stringsh

package
v0.0.0-...-61d31b1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package stringsh is helper for system package strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractLine

func ExtractLine(s string) (line, rem string)

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

func FieldsQuoted(s string) (f []string)

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

func GetFirstLine(s string) string

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

func GetLine(s string) (line string, pos int)

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

func IndexMulti(s string, seps ...string) (i int, sep int)

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 Len

func Len(s string) (l int)

Len returns number of glyph in UTF-8 encoded string.

func PadLeft

func PadLeft(s, glyph string, l int) string

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

func PadLeftWithByte(s string, b byte, l int) string

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

func PadRight(s, glyph string, l int) string

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

func PadRightWithByte(s string, b byte, l int) string

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

func ReplaceMulti(s string, old, new []string) (r string)

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

func Surround(s []string, prefix, suffix string) []string

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 TrimBytes

func TrimBytes(s string, cut byte) string

TrimBytes remove leading and trailing bytes cut from s.

func TrimLeftBytes

func TrimLeftBytes(s string, cut byte) string

TrimLeftBytes remove leading bytes cut from s.

func TrimRightBytes

func TrimRightBytes(s string, cut byte) string

TrimRightBytes remove trailing bytes cut from s.

Types

This section is empty.

Jump to

Keyboard shortcuts

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