add documentation for text module
This commit is contained in:
parent
591d745ef7
commit
49b2b5f75f
3 changed files with 66 additions and 8 deletions
|
@ -71,7 +71,7 @@ _* See [here](https://github.com/d5/tengobench) for commands/codes used_
|
|||
- [Builtin Functions](https://github.com/d5/tengo/blob/master/docs/builtins.md)
|
||||
- [Interoperability](https://github.com/d5/tengo/blob/master/docs/interoperability.md)
|
||||
- [Tengo CLI](https://github.com/d5/tengo/blob/master/docs/tengo-cli.md)
|
||||
- [Standard Library](https://github.com/d5/tengo/blob/master/docs/stdlib.md) _(experimental)_
|
||||
- [Standard Library](https://github.com/d5/tengo/blob/master/docs/stdlib.md)
|
||||
|
||||
## Roadmap
|
||||
|
||||
|
|
|
@ -10,16 +10,16 @@ import (
|
|||
|
||||
var textModule = map[string]objects.Object{
|
||||
"re_match": &objects.UserFunction{Value: textREMatch}, // re_match(pattern, text) => bool/error
|
||||
"re_find": &objects.UserFunction{Value: textREFind}, // re_find(pattern, text, count) => array(array({text:,begin:,end:}))/undefined
|
||||
"re_find": &objects.UserFunction{Value: textREFind}, // re_find(pattern, text, count) => [[{text:,begin:,end:}]]/undefined
|
||||
"re_replace": &objects.UserFunction{Value: textREReplace}, // re_replace(pattern, text, repl) => string/error
|
||||
"re_split": &objects.UserFunction{Value: textRESplit}, // re_split(pattern, text, count) => array(string)/error
|
||||
"re_split": &objects.UserFunction{Value: textRESplit}, // re_split(pattern, text, count) => [string]/error
|
||||
"re_compile": &objects.UserFunction{Value: textRECompile}, // re_compile(pattern) => Regexp/error
|
||||
"compare": FuncASSRI(strings.Compare), // compare(a, b) => int
|
||||
"contains": FuncASSRB(strings.Contains), // contains(s, substr) => bool
|
||||
"contains_any": FuncASSRB(strings.ContainsAny), // contains_any(s, chars) => bool
|
||||
"count": FuncASSRI(strings.Count), // count(s, substr) => int
|
||||
"equal_fold": FuncASSRB(strings.EqualFold), // "equal_fold(s, t) => bool
|
||||
"fields": FuncASRSs(strings.Fields), // fields(s) => array(string)
|
||||
"fields": FuncASRSs(strings.Fields), // fields(s) => [string]
|
||||
"has_prefix": FuncASSRB(strings.HasPrefix), // has_prefix(s, prefix) => bool
|
||||
"has_suffix": FuncASSRB(strings.HasSuffix), // has_suffix(s, suffix) => bool
|
||||
"index": FuncASSRI(strings.Index), // index(s, substr) => int
|
||||
|
@ -29,10 +29,10 @@ var textModule = map[string]objects.Object{
|
|||
"last_index_any": FuncASSRI(strings.LastIndexAny), // last_index_any(s, chars) => int
|
||||
"repeat": FuncASIRS(strings.Repeat), // repeat(s, count) => string
|
||||
"replace": &objects.UserFunction{Value: textReplace}, // replace(s, old, new, n) => string
|
||||
"split": FuncASSRSs(strings.Split), // split(s, sep) => []string
|
||||
"split_after": FuncASSRSs(strings.SplitAfter), // split_after(s, sep) => []string
|
||||
"split_after_n": FuncASSIRSs(strings.SplitAfterN), // split_after_n(s, sep, n) => []string
|
||||
"split_n": FuncASSIRSs(strings.SplitN), // split_n(s, sep, n) => []string
|
||||
"split": FuncASSRSs(strings.Split), // split(s, sep) => [string]
|
||||
"split_after": FuncASSRSs(strings.SplitAfter), // split_after(s, sep) => [string]
|
||||
"split_after_n": FuncASSIRSs(strings.SplitAfterN), // split_after_n(s, sep, n) => [string]
|
||||
"split_n": FuncASSIRSs(strings.SplitN), // split_n(s, sep, n) => [string]
|
||||
"title": FuncASRS(strings.Title), // title(s) => string
|
||||
"to_lower": FuncASRS(strings.ToLower), // to_lower(s) => string
|
||||
"to_title": FuncASRS(strings.ToTitle), // to_title(s) => string
|
||||
|
|
58
docs/stdlib-text.md
Normal file
58
docs/stdlib-text.md
Normal file
|
@ -0,0 +1,58 @@
|
|||
# Module - "text"
|
||||
|
||||
```golang
|
||||
text := import("text")
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
- `re_match(pattern string, text string) => bool/error`: reports whether the string s contains any match of the regular expression pattern.
|
||||
- `re_find(pattern string, text string, count int) => [[{text: string, begin: int, end: int}]]/undefined`: returns an array holding all matches, each of which is an array of map object that contains matching text, begin and end (exclusive) index.
|
||||
- `re_replace(pattern string, text string, repl string) => string/error`: returns a copy of src, replacing matches of the pattern with the replacement string repl.
|
||||
- `re_split(pattern string, text string, count int) => [string]/error`: slices s into substrings separated by the expression and returns a slice of the substrings between those expression matches.
|
||||
- `re_compile(pattern string) => Regexp/error`: parses a regular expression and returns, if successful, a Regexp object that can be used to match against text.
|
||||
- `compare(a string, b string) => int`: returns an integer comparing two strings lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
|
||||
- `contains(s string, substr string) => bool`: reports whether substr is within s.
|
||||
- `contains_any(s string, chars string) => bool`: reports whether any Unicode code points in chars are within s.
|
||||
- `count(s string, substr string) => int`: counts the number of non-overlapping instances of substr in s.
|
||||
- `equal_fold(s string, t string) => bool`: reports whether s and t, interpreted as UTF-8 strings,
|
||||
- `fields(s string) => [string]`: splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space.
|
||||
- `has_prefix(s string, prefix string) => bool`: tests whether the string s begins with prefix.
|
||||
- `has_suffix(s string, suffix string) => bool`: tests whether the string s ends with suffix.
|
||||
- `index(s string, substr string) => int`: returns the index of the first instance of substr in s, or -1 if substr is not present in s.
|
||||
- `index_any(s string, chars string) => int`: returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.
|
||||
- `join(arr string, sep string) => string`: concatenates the elements of a to create a single string. The separator string sep is placed between elements in the resulting string.
|
||||
- `last_index(s string, substr string) => int`: returns the index of the last instance of substr in s, or -1 if substr is not present in s.
|
||||
- `last_index_any(s string, chars string) => int`: returns the index of the last instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.
|
||||
- `repeat(s string, count int) => string`: returns a new string consisting of count copies of the string s.
|
||||
- `replace(s string, old string, new string, n int) => string`: returns a copy of the string s with the first n non-overlapping instances of old replaced by new.
|
||||
- `split(s string, sep string) => [string]`: slices s into all substrings separated by sep and returns a slice of the substrings between those separators.
|
||||
- `split_after(s string, sep string) => [string]`: slices s into all substrings after each instance of sep and returns a slice of those substrings.
|
||||
- `split_after_n(s string, sep string, n int) => [string]`: slices s into substrings after each instance of sep and returns a slice of those substrings.
|
||||
- `split_n(s string, sep string, n int) => [string]`: slices s into substrings separated by sep and returns a slice of the substrings between those separators.
|
||||
- `title(s string) => string`: returns a copy of the string s with all Unicode letters that begin words mapped to their title case.
|
||||
- `to_lower(s string) => string`: returns a copy of the string s with all Unicode letters mapped to their lower case.
|
||||
- `to_title(s string) => string`: returns a copy of the string s with all Unicode letters mapped to their title case.
|
||||
- `to_upper(s string) => string`: returns a copy of the string s with all Unicode letters mapped to their upper case.
|
||||
- `trim_left(s string, cutset string) => string`: returns a slice of the string s with all leading Unicode code points contained in cutset removed.
|
||||
- `trim_prefix(s string, prefix string) => string`: returns s without the provided leading prefix string.
|
||||
- `trim_right(s string, cutset string) => string`: returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.
|
||||
- `trim_space(s string) => string`: returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.
|
||||
- `trim_suffix(s string, suffix string) => string`: returns s without the provided trailing suffix string.
|
||||
- `atoi(str string) => int/error`: returns the result of ParseInt(s, 10, 0) converted to type int.
|
||||
- `format_bool(b bool) => string`: returns "true" or "false" according to the value of b.
|
||||
- `format_float(f float, fmt string, prec int, bits int) => string`: converts the floating-point number f to a string, according to the format fmt and precision prec.
|
||||
- `format_int(i int, base int) => string`: returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.
|
||||
- `itoa(i int) => string`: is shorthand for format_int(i, 10).
|
||||
- `parse_bool(s string) => bool/error`: returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error.
|
||||
- `parse_float(s string, bits int) => float/error`: converts the string s to a floating-point number with the precision specified by bitSize: 32 for float32, or 64 for float64. When bitSize=32, the result still has type float64, but it will be convertible to float32 without changing its value.
|
||||
- `parse_int(s string, base int, bits int) => int/error`: interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.
|
||||
- `quote(s string) => string`: returns a double-quoted Go string literal representing s. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for control characters and non-printable characters as defined by IsPrint.
|
||||
- `unquote(s string) => string/error`: interprets s as a single-quoted, double-quoted, or backquoted Go string literal, returning the string value that s quotes. (If s is single-quoted, it would be a Go character literal; Unquote returns the corresponding one-character string.)
|
||||
|
||||
## Regexp
|
||||
|
||||
- `match(text string) => bool`: reports whether the string s contains any match of the regular expression pattern.
|
||||
- `find(text string, count int) => [[{text: string, begin: int, end: int}]]/undefined`: returns an array holding all matches, each of which is an array of map object that contains matching text, begin and end (exclusive) index.
|
||||
- `replace(src string, repl string) => string`: returns a copy of src, replacing matches of the pattern with the replacement string repl.
|
||||
- `split(text string, count int) => [string]`: slices s into substrings separated by the expression and returns a slice of the substrings between those expression matches.
|
Loading…
Reference in a new issue