mycocontext

package
v4.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2022 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Overview

Package mycocontext provides a wrapper over context.Context and some operations on the wrapper.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextFromStringInput

func ContextFromStringInput(input string, opts options.Options) (Context, CancelFunc)

ContextFromStringInput returns the context for the given input.

func EatUntilSpace

func EatUntilSpace(ctx Context) (line string)

EatUntilSpace reads characters until it encounters a non-space character. The read characters are returned. No errors are reported even if there are any, be bold.

func HyphaExists

func HyphaExists(ctx Context, hyphaName string) bool

func HyphaHTMLData

func HyphaHTMLData(ctx Context, name string) (rawText, binaryHtml string, err error)

func IsEof

func IsEof(ctx Context) bool

IsEof is true if there is nothing left to read in the input. It does not handle the case when all next characters are \r, which are never returned by NextRune, thus making this function lie.

Be not afraid because everyone lies. Not a good idea to trust a //function// anyway.

func IterateHyphaNamesWith

func IterateHyphaNamesWith(ctx Context, f func(string))

func NextByte

func NextByte(ctx Context) (b byte, eof bool)

NextByte returns the next byte in the inputFrom. The CR byte (\r) is never returned, if there is a CR in the inputFrom, the byte after it is returned. If there is no next byte, the NL byte (\n) is returned and eof is true.

func NextLine

func NextLine(ctx Context) (line string, done bool)

NextLine returns the text in the inputFrom up to the next newline. The characters are gotten using nextByte.

func NextRune

func NextRune(ctx Context) (r rune, eof bool)

NextRune is like NextByte, but for runes.

func Options added in v4.3.1

func Options(ctx Context) options.Options

func UnreadRune

func UnreadRune(ctx Context)

UnreadRune unreads the previous rune. Pray so it doesn't throw any errors, because they are ignored.

Types

type CancelFunc

type CancelFunc context.CancelFunc

CancelFunc is a function you call to cancel the context. Why would you, though?

type Context

type Context interface {
	context.Context

	// HyphaName returns the name of the processed hypha.
	HyphaName() string

	// Input returns the buffer which contains all characters of the hypha text.
	Input() *bytes.Buffer

	// RecursionLevel returns current recursive transclusion level.
	RecursionLevel() uint

	// WithIncrementedRecursionLevel returns a copy of the context but with the recursion level incremented.
	//
	//     lvl1 := ctx.RecursionLevel()
	//     lvl2 := ctx.WithIncrementedRecursionLevel().RecursionLevel()
	//     lvl2 - lvl1 == 1
	WithIncrementedRecursionLevel() Context

	// WebSiteURL returns the URL of the wiki, including the protocol (http or https). It is used for generating OpenGraph meta tags.
	WebSiteURL() string

	// TransclusionSupported is true if Mycomarkup is invoked as a stand-alone program, false if used as a library.
	TransclusionSupported() bool
}

Context is the wrapper around context.Context providing type-level safety on presence of several values.

func WithBuffer

func WithBuffer(ctx Context, buf *bytes.Buffer) Context

WithBuffer returns a copy of the given context but with a different input buffer.

Jump to

Keyboard shortcuts

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