strutil

package
v0.0.0-...-8aadb99 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewlineMatcher = regexp.MustCompile(`\r\n`)

NewlineMatcher is a regular expression matching all newlines or returned newlines.

Functions

func AdjustNumberOperatorPos

func AdjustNumberOperatorPos(cpos int, line []rune) int

AdjustNumberOperatorPos returns an adjusted cursor position when the word around the cursor is an expression with an operator.

func AdjustSurroundQuotes

func AdjustSurroundQuotes(dBpos, dEpos, sBpos, sEpos int) (mark, cpos int)

AdjustSurroundQuotes returns the correct mark and cursor positions when we want to know where a shell word enclosed with quotes (and potentially having inner ones) starts and ends.

func ConvertMeta

func ConvertMeta(keys []rune) string

ConvertMeta recursively searches for metafied keys in a sequence, and replaces them with an esc prefix and their unmeta equivalent.

func FormatTabs

func FormatTabs(s string) string

FormatTabs replaces all '\t' occurrences in a string with 6 spaces each.

func GetQuotedWordStart

func GetQuotedWordStart(line []rune) (unclosed bool, pos int)

GetQuotedWordStart returns the position of the outmost containing quote of the word (going backward from the end of the provided line), if the current word is a shell word that is not closed yet. Ex: `this 'quote contains "surrounded" words`. the outermost quote is the single one.

func IsBracket

func IsBracket(char rune) bool

IsBracket returns true if the character is an opening/closing bracket/brace/parenthesis.

func IsSurround

func IsSurround(bchar, echar rune) bool

IsSurround returns true if the character is a quote or a bracket/brace, etc.

func LineSpan

func LineSpan(line []rune, idx, indent int) (x, y int)

LineSpan computes the number of columns and lines that are needed for a given line, accounting for any ANSI escapes/color codes, and tabulations replaced with 4 spaces.

func MatchSurround

func MatchSurround(r rune) (bchar, echar rune)

MatchSurround returns the matching character of a rune that is either a bracket/brace/parenthesis, or a single/double quote.

func Quote

func Quote(char rune) (res []rune, length int)

Quote translates one rune in its printable version, which might be different for Control/Meta characters. Returns the "translated" string and new length. (eg 0x04 => ^C = len:2).

func RealLength

func RealLength(s string) int

RealLength returns the real length of a string (the number of terminal columns used to render the line, which may contain special graphemes). Before computing the width, it replaces tabs with (4) spaces, and strips colors.

func Split

func Split(input string) (words []string, err error)

Split splits a string according to /bin/sh's word-splitting rules. It supports backslash-escapes, single-quotes, and double-quotes. Notably it does not support the $” style of quoting. It also doesn't attempt to perform any other sort of expansion, including brace expansion, shell expansion, or pathname expansion.

If the given input has an unterminated quoted string or ends in a backslash-escape, one of UnterminatedSingleQuoteError, UnterminatedDoubleQuoteError, or UnterminatedEscapeError is returned.

func SurroundType

func SurroundType(char rune) (surround, closer bool)

SurroundType says if the character is a pairing one (first boolean), and if the character is the closing part of the pair (second boolean).

Types

type KeywordSwitcher

type KeywordSwitcher func(word string, increase bool, times int) (done bool, switched string, bpos, epos int)

KeywordSwitcher is a function modifying a given word, returning: @done => If true, the handler performed a change. @switched => The updated word. @bpos => Offset to begin position. @epos => Offset to end position.

func KeywordSwitchers

func KeywordSwitchers() []KeywordSwitcher

KeywordSwitchers returns all keywordSwitchers of the shell.

Jump to

Keyboard shortcuts

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