mycocontext

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 3 Imported by: 1

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(hyphaName, input string) (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 NextByte

func NextByte(ctx Context) (b byte, done 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 done 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 added in v0.4.2

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

NextRune is like NextByte, but for runes.

func UnreadRune added in v0.5.4

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
}

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.

func WithWebSiteURL added in v0.5.0

func WithWebSiteURL(ctx Context, url string) Context

WithWebSiteURL returns a copy of the given context but with the website URL set to the given one instead of the default empty string. The url should not end on slash because that would break the links generated by the library.

Jump to

Keyboard shortcuts

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