Documentation ¶
Overview ¶
Package stringsh is helper for system package strings.
Index ¶
- func ExtractLine(s string) (line, rem string)
- func FieldsQuoted(s string) (f []string)
- func GetFirstLine(s string) string
- func GetLine(s string) (line string, pos int)
- func IndexMulti(s string, seps ...string) (i int, sep int)
- func Len(s string) (l int)
- func PadLeft(s, glyph string, l int) string
- func PadLeftWithByte(s string, b byte, l int) string
- func PadRight(s, glyph string, l int) string
- func PadRightWithByte(s string, b byte, l int) string
- func ReplaceMulti(s string, old, new []string) (r string)
- func Surround(s []string, prefix, suffix string) []string
- func TrimBytes(s string, cut byte) string
- func TrimLeftBytes(s string, cut byte) string
- func TrimRightBytes(s string, cut byte) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractLine ¶
ExtractLine returns first line from s and remaining part of s. Line delimiter is the same as in GetLine. Also as in GetLine delimiter does not include nor in line nor in rem.
func FieldsQuoted ¶
FieldsQuoted splits the string s around each instance of one or more consecutive white space characters, as defined by unicodeh.IsWhiteSpaceYes. It also treat single and double quoted substrings as single field (so it is possible to have white spaces in field itself). In quoted substrings '\' used to escape: "...\X..." translated to "...X..." ("\\" => "\", "\"" => '"'). Returns an array of substrings of s or an empty list if s contains only white space.
func GetFirstLine ¶
GetFirstLine is a shortcut for GetLine but returning only first line. As line delimiter does not include in result it may be hard to manipulate with remaining string.
func GetLine ¶
GetLine returns first line from s and position in s of remaining part. Line delimiter may be "\n" or "\r\n". In both cases delimiter does not include nor in line nor in pos (pos points to first byte of second line). If s does not contain delimiter than GetLine returns s as first line. If there is no second line in s (s does not contain delimiter or there is no other bytes after delimiter) than pos will be point to non existing position in s.
func IndexMulti ¶
IndexMulti returns the index of the first instance of any seps in s and index of founded sep, or (-1,-1) if seps are not present in s. Checking for seps in each position of s proceeds in order of they are passed, so if seps[5] and seps[7] both present in s at the same position (let it be 29) then result will be (29; 5), not (29; 7). Empty string (as seps) presents at position 0 in any string.
func PadLeft ¶
PadLeft returns original string padded on the left side with glyph to length l. Length for this function is in glyphs, not bytes or runes. Original string s will be returned if required length l > len(s). Passed glyph should be single glyph (printable char) else result will be of wrong length. But where is no check for that.
func PadLeftWithByte ¶
PadLeftWithByte return original string padded on the left side with char b to length l. Length for this function is in bytes. So this function is good only for ascii strings. Original string s will be returned if required length l > len(s).
func PadRight ¶
PadRight returns original string padded on the right side with glyph to length l. Length for this function is in glyphs, not bytes or runes. Original string s will be returned if required length l > len(s). Passed glyph should be single glyph (printable char) else result will be of wrong length. But where is no check for that.
func PadRightWithByte ¶
PadRightWithByte return original string padded on the left side with char b to length l. Length for this function is in bytes. So this function is good only for ascii strings. Original string s will be returned if required length l > len(s).
func ReplaceMulti ¶
ReplaceMulti returns a copy of the string s with non-overlapping instances of old elements replaced by corresponding new elements. If len(old) != len(new) => panic if len(old[i])==0 => panic ReplaceMulti returns s as-is if old is empty.
func Surround ¶
Surround surrounds each passing string with prefix and suffix. Surround does not modify passed slice, instead of this it returns result as separate slice.
func TrimLeftBytes ¶
TrimLeftBytes remove leading bytes cut from s.
func TrimRightBytes ¶
TrimRightBytes remove trailing bytes cut from s.
Types ¶
This section is empty.