bytesutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GuardedBlocks added in v1.2.0

func GuardedBlocks(data string, begin *regexp.Regexp, end *regexp.Regexp) (blocks []string)

GuardedBlocks extracts blocks of consecutive lines that are guarded by the given begin and end lines. The guarding lines are included in the results. If no end guard is given, the start guard is used as end guard as well.

func IsWhitespace

func IsWhitespace(data string) (isWhitespace bool)

IsWhitespace checks if the given string consists of only whitespace.

func LineLengths

func LineLengths(data []byte) []uint

LineLengths returns a slice of the line lengths of the given data. Line endings (Unix+Windows) are ignored.

func LineLengthsForFile

func LineLengthsForFile(filePath string) ([]uint, error)

LineLengthsForFile returns a slice of the line lengths of the given data. Line endings (Unix+Windows) are ignored.

func PrefixContinuationLinesWith

func PrefixContinuationLinesWith(paragraph string, prefix string) string

PrefixContinuationLinesWith indents every line except the first one with the given amount of whitespace.

func PrefixLines

func PrefixLines(data []byte, prefix []byte) (result []byte)

PrefixLines prefixes every non-empty line with the given prefix.

func RemoveLine

func RemoveLine(in string, search string) (out string)

RemoveLine looks up every line with the given search string in the input and returns an output removing all the selected lines.

func RenderMarkdownFileToHTMLFile

func RenderMarkdownFileToHTMLFile(markdownFilePath string, htmlFilePath string) (err error)

RenderMarkdownFileToHTMLFile reads in the Markdown file, renders it as HTML and writes that output in the HTML file.

func ReplaceBytesInBinary

func ReplaceBytesInBinary(binaryPathIn string, binaryPathOut string, search []byte, replace []byte, n int) (err error)

ReplaceBytesInBinary replaces a certain amount of occurrences of the given bytes in a binary. A negative number of occurrences replaces all matches. If no output file is given, the input file is overwritten.

func ReplaceBytesInFile

func ReplaceBytesInFile(filePathIn string, filePathOut string, search []byte, replace []byte, n int) (err error)

ReplaceBytesInFile replaces a certain amount of occurrences of the given bytes in a file. A negative number of occurrences replaces all matches. If no output file is given, the input file is overwritten.

func RewriteWebsiteContent

func RewriteWebsiteContent(data string, defaultURL string, url string, uriPrefix string, fileHashes map[string]string) (dataReplaced string)

RewriteWebsiteContent replaces all URLs and URIs to the given ones, and gives all URLs and URIs also a hash so they invalidate their cache when their content changes.

func RewriteWebsiteContentDirectory

func RewriteWebsiteContentDirectory(contentDirectoryPath string, defaultURL string, url string, uriPrefix string, staticFiles map[string]*osutil.StaticFile) (err error)

RewriteWebsiteContentDirectory replaces all URLs and URIs to the given ones, and gives all URLs and URIs also a hash so they invalidate their cache when their content changes.

func SearchAndReplaceFile

func SearchAndReplaceFile(file string, search *regexp.Regexp, replace string) (err error)

SearchAndReplaceFile searches for occurrences of a given pattern in a file and replaces them accordingly. Capturing groups can be referenced in the replace string by using $, i.e. $1 is the first capturing group.

func SortLines

func SortLines(s string) (sorted string)

SortLines splits the given string into lines, sorts them and then returns the sorted lines as a combined string.

func SortLinesAndTrimSpace

func SortLinesAndTrimSpace(s string) (sorted string)

SortLinesAndTrimSpace sorts the lines of the given string and removes all leading and trailing whitespaces.

func Split

func Split(s []byte, sep byte) <-chan []byte

Split iteratively splits argument s and returns the split items over the returned channel.

func StringTrimIndentations

func StringTrimIndentations(s string) string

StringTrimIndentations removes indentations that were added for a cleaner code style

func TrimIndentations

func TrimIndentations(s []byte) []byte

TrimIndentations removes indentations that were added for a cleaner code style

func WordAfterFirstMatch

func WordAfterFirstMatch(str string, substring string) string

WordAfterFirstMatch returns the next word in the string after the given substring, or the empty string if it does not exist.

Types

type SynchronizedBuffer

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

SynchronizedBuffer holds a concurrency-safe buffer.

func (*SynchronizedBuffer) Bytes

func (b *SynchronizedBuffer) Bytes() []byte

Bytes calls "Bytes" of "bytes.Buffer".

func (*SynchronizedBuffer) Cap

func (b *SynchronizedBuffer) Cap() int

Cap calls "Cap" of "bytes.Buffer".

func (*SynchronizedBuffer) Grow

func (b *SynchronizedBuffer) Grow(n int)

Grow calls "Grow" of "bytes.Buffer".

func (*SynchronizedBuffer) Len

func (b *SynchronizedBuffer) Len() int

Len calls "Len" of "bytes.Buffer".

func (*SynchronizedBuffer) Next

func (b *SynchronizedBuffer) Next(n int) []byte

Next calls "Next" of "bytes.Buffer".

func (*SynchronizedBuffer) Read

func (b *SynchronizedBuffer) Read(p []byte) (n int, err error)

Read calls "Read" of "bytes.Buffer".

func (*SynchronizedBuffer) ReadByte

func (b *SynchronizedBuffer) ReadByte() (byte, error)

ReadByte calls "ReadByte" of "bytes.Buffer".

func (*SynchronizedBuffer) ReadBytes

func (b *SynchronizedBuffer) ReadBytes(delim byte) (line []byte, err error)

ReadBytes calls "ReadBytes" of "bytes.Buffer".

func (*SynchronizedBuffer) ReadFrom

func (b *SynchronizedBuffer) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom calls "ReadFrom" of "bytes.Buffer".

func (*SynchronizedBuffer) ReadRune

func (b *SynchronizedBuffer) ReadRune() (r rune, size int, err error)

ReadRune calls "ReadRune" of "bytes.Buffer".

func (*SynchronizedBuffer) ReadString

func (b *SynchronizedBuffer) ReadString(delim byte) (line string, err error)

ReadString calls "ReadString" of "bytes.Buffer".

func (*SynchronizedBuffer) Reset

func (b *SynchronizedBuffer) Reset()

Reset calls "Reset" of "bytes.Buffer".

func (*SynchronizedBuffer) String

func (b *SynchronizedBuffer) String() string

String calls "String" of "bytes.Buffer".

func (*SynchronizedBuffer) Truncate

func (b *SynchronizedBuffer) Truncate(n int)

Truncate calls "Truncate" of "bytes.Buffer".

func (*SynchronizedBuffer) UnreadByte

func (b *SynchronizedBuffer) UnreadByte() error

UnreadByte calls "UnreadByte" of "bytes.Buffer".

func (*SynchronizedBuffer) UnreadRune

func (b *SynchronizedBuffer) UnreadRune() error

UnreadRune calls "UnreadRune" of "bytes.Buffer".

func (*SynchronizedBuffer) Write

func (b *SynchronizedBuffer) Write(p []byte) (n int, err error)

Write calls "Write" of "bytes.Buffer".

func (*SynchronizedBuffer) WriteByte

func (b *SynchronizedBuffer) WriteByte(c byte) error

WriteByte calls "WriteByte" of "bytes.Buffer".

func (*SynchronizedBuffer) WriteRune

func (b *SynchronizedBuffer) WriteRune(r rune) (n int, err error)

WriteRune calls "WriteRune" of "bytes.Buffer".

func (*SynchronizedBuffer) WriteString

func (b *SynchronizedBuffer) WriteString(s string) (n int, err error)

WriteString calls "WriteString" of "bytes.Buffer".

func (*SynchronizedBuffer) WriteTo

func (b *SynchronizedBuffer) WriteTo(w io.Writer) (n int64, err error)

WriteTo calls "WriteTo" of "bytes.Buffer".

Jump to

Keyboard shortcuts

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