textutil

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: Apache-2.0 Imports: 6 Imported by: 2

README

Package cloudeng.io/text/textutil

CircleCI Go Report Card

import cloudeng.io/text/textutil

Package textutil provides utility routines for working with text, in particular utf8 encoded text.

Functions

Func BytesToString
func BytesToString(b []byte) string

BytesToString returns a string with the supplied byte slice as its contents. The original byte slice must never be modified. Taken from strings.Builder.String().

Func ReverseBytes
func ReverseBytes(input string) []byte

ReverseBytes returns a new slice containing the runes in the input string in reverse order.

Func ReverseString
func ReverseString(input string) string

ReverseString is like ReverseBytes but returns a string.

Func StringToBytes
func StringToBytes(s string) []byte

StringToBytes returns the byte slice containing the data for the supplied string without any allocations or copies. It should only be used when the resulting byte slice will never be modified. See https://groups.google.com/g/golang-nuts/c/Zsfk-VMd_fU/m/O1ru4fO-BgAJ

Types

Type RewriteRule
type RewriteRule struct {
	Match       *regexp.Regexp
	Replacement string
}

RewriteRule represents a rewrite rule of the form s/// or s%%%. Separators can be escpaed using a .

Functions
func NewRewriteRule(rule string) (RewriteRule, error)

NewReplacement accepts a string of the form s/// or s%%% and returns a RewriteRule that can be used to perform the rewquested rewrite. Separators can be escpaed using a .

Methods
func (rr RewriteRule) MatchString(input string) bool

Match applies regexp.MatchString.

func (rr RewriteRule) ReplaceAllString(input string) string

ReplaceAllString(input string) applies regexp.ReplaceAllString.

Documentation

Overview

Package textutil provides utility routines for working with text, in particular utf8 encoded text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString returns a string with the supplied byte slice as its contents. The original byte slice must never be modified. Taken from strings.Builder.String().

func ReverseBytes

func ReverseBytes(input string) []byte

ReverseBytes returns a new slice containing the runes in the input string in reverse order.

func ReverseString

func ReverseString(input string) string

ReverseString is like ReverseBytes but returns a string.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes returns the byte slice containing the data for the supplied string without any allocations or copies. It should only be used when the resulting byte slice will never be modified. See https://groups.google.com/g/golang-nuts/c/Zsfk-VMd_fU/m/O1ru4fO-BgAJ

Types

type RewriteRule

type RewriteRule struct {
	Match       *regexp.Regexp
	Replacement string
}

RewriteRule represents a rewrite rule of the form s/<match>/<replace>/ or s%<match>%<replace>%. Separators can be escpaed using a \.

func NewRewriteRule

func NewRewriteRule(rule string) (RewriteRule, error)

NewReplacement accepts a string of the form s/<match-re>/<replacement>/ or s%<match-re>%<replacement>% and returns a RewriteRule that can be used to perform the rewquested rewrite. Separators can be escpaed using a \.

func (RewriteRule) MatchString

func (rr RewriteRule) MatchString(input string) bool

Match applies regexp.MatchString.

func (RewriteRule) ReplaceAllString

func (rr RewriteRule) ReplaceAllString(input string) string

ReplaceAllString(input string) applies regexp.ReplaceAllString.

type RewriteRules added in v0.0.11

type RewriteRules []RewriteRule

func NewRewriteRules added in v0.0.11

func NewRewriteRules(rules ...string) (RewriteRules, error)

func (RewriteRules) ReplaceAllStringFirst added in v0.0.11

func (rw RewriteRules) ReplaceAllStringFirst(input string) string

Jump to

Keyboard shortcuts

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