Documentation ¶
Overview ¶
Package runes provide a library for working with a single rune or slice of rune.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contain ¶
Contain find a rune `c` inside `s`. If `c` found in `s` it will return boolean true and index of `c` in `s`; otherwise it will return false and -1.
Example ¶
line := []rune(`a b c`) found, idx := Contain(line, 'a') fmt.Printf("%t %d\n", found, idx) found, idx = Contain(line, 'x') fmt.Printf("%t %d\n", found, idx)
Output: true 0 false -1
func Diff ¶
Diff return the difference between two slice of rune.
Example ¶
l := []rune{'a', 'b', 'c', 'd'} r := []rune{'b', 'c'} fmt.Printf("%c\n", Diff(l, r))
Output: [a d]
func EncloseRemove ¶
EncloseRemove given a line, remove all characters inside it, starting from `leftcap` until the `rightcap` and return cutted line and changed to true.
If no `leftcap` or `rightcap` is found, the line will unchanged, and returned status will be false.
Example ¶
line := []rune(`[[ ABC ]] DEF`) leftcap := []rune(`[[`) rightcap := []rune(`]]`) got, changed := EncloseRemove(line, leftcap, rightcap) fmt.Printf("'%s' %t\n", string(got), changed)
Output: ' DEF' true
func FindSpace ¶
FindSpace find any unicode spaces in line start from index `startAt` and return their index. If no spaces found it will return -1.
Example ¶
line := []rune(`Find a space`) fmt.Printf("%d\n", FindSpace(line, 0)) fmt.Printf("%d\n", FindSpace(line, 5))
Output: 4 6
func Inverse ¶
Inverse the input slice of rune with inplace reversion (without allocating another slice).
Example ¶
fmt.Printf("%s\n", string(Inverse([]rune(``)))) fmt.Printf("%s\n", string(Inverse([]rune(`a`)))) fmt.Printf("%s\n", string(Inverse([]rune(`ab`)))) fmt.Printf("%s\n", string(Inverse([]rune(`abc`)))) fmt.Printf("%s\n", string(Inverse([]rune(`abcd`)))) fmt.Printf("%s\n", string(Inverse([]rune(`abcde`))))
Output: a ba cba dcba edcba
func TokenFind ¶
TokenFind will search token in text starting from index `startAt` and return the position where the match start.
If no token is found it will return -1.
Example ¶
line := []rune("// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.") token := []rune("right") at := TokenFind(line, token, 0) fmt.Printf("%d\n", at)
Output: 7
Types ¶
This section is empty.