strings

package
v0.0.0-...-6187f5f Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteNumber

type ByteNumber int

Numeric type that represents the amount of bytes in a string, array or slice.

func IndexNotAny

func IndexNotAny(s, chars string) ByteNumber

IndexNotAny is similar with strings.IndexAny but showing the opposite behavior.

Example
package main

import (
	"fmt"

	"github.com/joeycumines/go-prompt/strings"
)

func main() {
	fmt.Println(strings.IndexNotAny("golang", "glo"))
	fmt.Println(strings.IndexNotAny("golang", "gl"))
	fmt.Println(strings.IndexNotAny("golang", "golang"))
}
Output:

3
1
-1

func IndexNotByte

func IndexNotByte(s string, c byte) ByteNumber

IndexNotByte is similar with strings.IndexByte but showing the opposite behavior.

Example
package main

import (
	"fmt"

	"github.com/joeycumines/go-prompt/strings"
)

func main() {
	fmt.Println(strings.IndexNotByte("golang", 'g'))
	fmt.Println(strings.IndexNotByte("golang", 'x'))
	fmt.Println(strings.IndexNotByte("gggggg", 'g'))
}
Output:

1
0
-1

func LastIndexNotAny

func LastIndexNotAny(s, chars string) ByteNumber

LastIndexNotAny is similar with strings.LastIndexAny but showing the opposite behavior.

Example
package main

import (
	"fmt"

	"github.com/joeycumines/go-prompt/strings"
)

func main() {
	fmt.Println(strings.LastIndexNotAny("golang", "agn"))
	fmt.Println(strings.LastIndexNotAny("golang", "an"))
	fmt.Println(strings.LastIndexNotAny("golang", "golang"))
}
Output:

2
5
-1

func LastIndexNotByte

func LastIndexNotByte(s string, c byte) ByteNumber

LastIndexNotByte is similar with strings.LastIndexByte but showing the opposite behavior.

Example
package main

import (
	"fmt"

	"github.com/joeycumines/go-prompt/strings"
)

func main() {
	fmt.Println(strings.LastIndexNotByte("golang", 'g'))
	fmt.Println(strings.LastIndexNotByte("golang", 'x'))
	fmt.Println(strings.LastIndexNotByte("gggggg", 'g'))
}
Output:

4
5
-1

func Len

func Len(s string) ByteNumber

Get the length of the string in bytes.

type GraphemeNumber

type GraphemeNumber int

Numeric type that represents the amount of grapheme clusters in a string, array or slice.

func GraphemeCountInString

func GraphemeCountInString(text string) GraphemeNumber

Returns the number of horizontal cells needed to print the given text. It splits the text into its grapheme clusters, calculates each cluster's width, and adds them up to a total.

type RuneNumber

type RuneNumber int

Numeric type that represents the amount of runes in a string, array or slice.

func RuneCount

func RuneCount(b []byte) RuneNumber

Get the length of the byte slice in runes.

func RuneCountInString

func RuneCountInString(s string) RuneNumber

Get the length of the string in runes.

func RuneIndexNthColumn

func RuneIndexNthColumn(text string, n Width) RuneNumber

Returns the rune index of the nth column (in terms of char width) in the given text.

func RuneIndexNthGrapheme

func RuneIndexNthGrapheme(text string, n GraphemeNumber) RuneNumber

Returns the rune index of the nth grapheme in the given text.

type Width

type Width int

Numeric type that represents the visible width of characters in a string as seen in a terminal emulator.

func GetRuneWidth

func GetRuneWidth(char rune) Width

Get the width of the rune (how many columns it takes upt in the terminal).

func GetWidth

func GetWidth(text string) Width

Returns the number of horizontal cells needed to print the given text. It splits the text into its grapheme clusters, calculates each cluster's width, and adds them up to a total.

Jump to

Keyboard shortcuts

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