ch7ex4

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

README

= Exercise 7.4
// Refs:
:url-base: https://github.com/fenegroni/TGPL-exercise-solutions
:workflow: workflows/Exercise 7.4
:action: actions/workflows/ch7ex4.yml
:url-workflow: {url-base}/{workflow}
:url-action: {url-base}/{action}
:badge-exercise: image:{url-workflow}/badge.svg?branch=main[link={url-action}]

{badge-exercise}

The `strings.NewReader` function returns a value that satisfies the `io.Reader` interface
(and others) by reading from its argument, a string.
Implement a simple version of `NewReader` yourself,
and use it to make the HTML parser take input from a string.

== Test

We use the same test we implemented for exercise 5.7
using the `outline` function to
build a string representation of an HTML document
given the parse tree got from `html.Parse`.
In this test we call `html.Parse` by calling our own implementation of `NewReader`
using the string from each test case.

As we can see from the implementation, out of the many interfaces our `Reader` has to satisfy
only the `io.Reader` interface needs to implemented for the test to pass.

Luckily for us, the other interfaces that `strings.Reader` implements are not called by `html.Parse`.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(s string) *Reader

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

func (*Reader) ReadAt

func (r *Reader) ReadAt([]byte, int64) (n int, err error)

func (*Reader) ReadByte

func (r *Reader) ReadByte() (byte, error)

func (*Reader) Seek

func (r *Reader) Seek(int64, int) (int64, error)

func (*Reader) UnreadByte

func (r *Reader) UnreadByte() error

func (*Reader) WriteTo

func (r *Reader) WriteTo(io.Writer) (n int64, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL