brace

package module
v0.0.0-...-4f22d2a Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 3 Imported by: 0

README

go-brace

Package brace implements tools for working with brace-string literals, for the Go programming language.

Brace-String literals are a type of string literal used in the Tcl programming language. For example:

{Hello world!}

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-brace

GoDoc

Example

Here is an example:


import "github.com/reiver/go-brace"
import "github.com/reiver/go-utf8"

// ...

const value string = `{This is a brace-string literal. It begins with a \{ symbol and end with a \} symbol. Now look at this: {wow} }`

var reader io.Reader = strings.NewReader(value)
var runereader io.RuneReader = utf8.NewRuneReader(reader)

bracestring, err := brace.ParseToString(runereader)
if nil != err {
		return err
}

fmt.Print(bracestring)

// This will print:
//
//	This is a brace-string literal. It begins with a { symbol and end with a } symbol. Now look at this: {wow} 
//
// I.e., the string:
//
//	"This is a brace-string literal. It begins with a { symbol and end with a } symbol. Now look at this: {wow} "
//
// Notice that the beginning '{' is not there, that the ending '}' is not there, and the 2 '\' are not there either.

Import

To import package brace use import code like the follownig:

import "github.com/reiver/go-brace"

Installation

To install package brace do the following:

GOPROXY=direct go get github.com/reiver/go-brace

Author

Package brace was written by Charles Iliya Krempeaux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(fn func(rune) error, runescanner io.RuneScanner) error

Parse parses a brace-string literal from a io.RuneScanner.

Parse will call ‘fn’ for each logical character it receives. So — if this is the brace-literal it parses:

`{a b \{ c \} d}`

Then ‘fn’ would be called 11 times, and given these runes:

'a'
' '
'b'
' '
'{'
' '
'c'
' '
'}'
' '
'd'

Note that the beginning '{' and ending '}' of the brace-string literal are not part of this. Also note that the '\' (black-slash) before the '{' and the '}' was not included either.

func ParseToBytes

func ParseToBytes(runescanner io.RuneScanner) ([]byte, error)

ParseToBytes is similar to Parse except it return the brace-string literal as a []byte.

func ParseToString

func ParseToString(runescanner io.RuneScanner) (string, error)

ParseToString is similar to Parse except it return the brace-string literal as a string.

func ParseToWriter

func ParseToWriter(writer io.Writer, runescanner io.RuneScanner) error

ParseToBytes is similar to Parse except it writes the brace-string literal as an io.Writer.

Types

This section is empty.

Jump to

Keyboard shortcuts

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