Documentation ¶
Overview ¶
package rslice provides some common []rune patterns for moving runes around within a slice, justifying embedded text, etc
Charles <asciifaceman> Corbett 2023
MIT License
Index ¶
- func LeastWhitespaceIndex(slice []rune) int
- func Newline(r rune) bool
- func Normalize(slice []rune) []rune
- func NormalizeWhitespace(slice []rune) []rune
- func ShiftLeft(slice []rune) []rune
- func ShiftRight(slice []rune) []rune
- func ShiftWhitespaceLeft(slice []rune) []rune
- func ShiftWhitespaceRight(slice []rune) []rune
- func TrimExcessWhitespace(slice []rune) []rune
- func Valid(slice []rune) bool
- func Whitespace(slice []rune) bool
- func Words(slice []rune) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LeastWhitespaceIndex ¶
LeastWhitespaceIndex returns an index point of a []rune with the least whitespace between the left and right most characters
It will wait until it has passed at least one non-whitespace character before recording the potential index.
A return of -1 indicates there is no suitable index, an example string would be ` a ` which has no whitespace between two non-whitespace characters
Currently this function will trigger an ignore on whitespace after a control character is encountered until the next non-whitespace non-control character and effectively erase any whitespace between the previous non-ws/non-cc rune to prevent returning an index between or before a control character wh
func Newline ¶
Newline returns true if the given rune is a Linux, Darwin, or Windows newline character
func Normalize ¶
Normalize is a recursive function that will take all whitespace left of the left most non-whitespace and non-control-character space and move it somewhere in the interior starting on the left most interior and working in
Normalize maintains the []rune's width
Example ```go
s := []rune(" A string with whitespace to the left") s = rslice.Normalize(s) // s should now be "A string with whitespace to the left"
```
func NormalizeWhitespace ¶
NormalizeWhitespace takes the left and right whitespace of the given rune slice and spreads it across the interior whitespace of the rune slice between the inner and outer most non-whitespace character
Maintains the []rune's width
Returns the slice unchanged if the []rune contains only whitespace, has no length, or has fewer than 2 words since there would be no inner whitespace to utilize
Usage: ```go
s := []rune(" A string with whitespace to the left and right ") s = rslice.NormalizeWhitespace(s) // s should now be "A string with whitespace to the left and right"
```
func ShiftLeft ¶
ShiftLeft shifts the rune slice one to the left and returns a copy if the slice is not all whitespace
func ShiftRight ¶
ShiftRight shits the rune slice one to the right and returns a copy if the slice is not all whitespace
func ShiftWhitespaceLeft ¶
ShiftWhitespaceLeft shifts any whitespace right of the last non-whitespace character to the left of the first non-whitespace character in the rune slice and returns a copy if the slice is not all whitespace
func ShiftWhitespaceRight ¶
ShiftWhitespaceRight shifts any whitespace left of the first non-whitespace character to the right of the last non-whitespace character in the rune sluce and returns a copy if the slice is not all whitespace
func TrimExcessWhitespace ¶
TrimExcessWhitespace will remove any occurance of whitespace greater than one count
func Whitespace ¶
Whitespace returns true if the entire []rune is whitespace It will also return true if the slice is empty
func Words ¶
Words returns a count of non-whitespace groupings of characters that may or may not be a word
Can be useful to discover how many areas of whitespace you have for purposes such as full text justification across a width
Does not recognize control characters (such as \n or \t) as non-whitespace characters as per unicode stdlib
Types ¶
This section is empty.