add s:tokenize to stdlib

FossilOrigin-Name: 1c4918bebdacb9e724b29f51f5a80751116c1afbd28606e8a8dfac2a9a71c489
This commit is contained in:
crc 2017-11-13 12:52:10 +00:00
parent 0004ce7232
commit 990066ac08
5 changed files with 33 additions and 2 deletions

View file

@ -3421,6 +3421,18 @@ Class Handler: class:word | Namespace: s | Interface Layer: all
----------------------------------------------------------------
s:tokenize
Data: sc-a
Addr: -
Float: -
Takes a string and a character to use as a separator. It splits the string into a set of substrings and returns a set containing pointers to each of them.
Class Handler: class:word | Namespace: {n/a} | Interface Layer: {n/a}
----------------------------------------------------------------
s:trim
Data: s-s

File diff suppressed because one or more lines are too long

View file

@ -907,6 +907,24 @@ located.
}}
~~~
`s:tokenize` takes a string and a character to use as a separator. It
splits the string into a set of substrings and returns a set containing
pointers to each of them.
~~~
{{
'Split-On var
:match? (c-f) @Split-On eq? ;
:terminate (s-s) #0 over n:dec store ;
:step (ss-s) [ n:inc ] dip match? [ dup , terminate ] if ;
---reveal---
:s:tokenize (sc-a)
!Split-On s:keep
here #0 , [ dup , dup [ step ] s:for-each drop ] dip
here over - n:dec over store ;
}}
~~~
Ok, This is a bit of a hack, but very useful at times.
Assume you have a bunch of values:

BIN
ngaImage

Binary file not shown.

View file

@ -276,6 +276,7 @@ s:to-float s- - -F Convert a string representation into a floating point value.
s:to-lower s-s - - Convert uppercase ASCII characters in a string to lowercase. class:word {n/a} {n/a} s all
s:to-number s-n - - Convert a string to a number. class:word {n/a} {n/a} s all
s:to-upper s-s - - Convert lowercase ASCII characters in a string to uppercase. class:word {n/a} {n/a} s all
s:tokenize sc-a - - Takes a string and a character to use as a separator. It splits the string into a set of substrings and returns a set containing pointers to each of them. class:word {n/a} {n/a} {n/a} {n/a}
s:trim s-s - - Trim leading and trailing whitespace from a string. class:word {n/a} {n/a} s all
s:trim-left s-s - - Trim leading whitespace from a string. class:word {n/a} {n/a} s all
s:trim-right s-s - - Trim trailing whitespace from a string. class:word {n/a} {n/a} s all

1 * nn-n - - Multiply `n1` by `n2` and return the result. class:primitive {n/a} {n/a} global all
276 s:to-lower s-s - - Convert uppercase ASCII characters in a string to lowercase. class:word {n/a} {n/a} s all
277 s:to-number s-n - - Convert a string to a number. class:word {n/a} {n/a} s all
278 s:to-upper s-s - - Convert lowercase ASCII characters in a string to uppercase. class:word {n/a} {n/a} s all
279 s:tokenize sc-a - - Takes a string and a character to use as a separator. It splits the string into a set of substrings and returns a set containing pointers to each of them. class:word {n/a} {n/a} {n/a} {n/a}
280 s:trim s-s - - Trim leading and trailing whitespace from a string. class:word {n/a} {n/a} s all
281 s:trim-left s-s - - Trim leading whitespace from a string. class:word {n/a} {n/a} s all
282 s:trim-right s-s - - Trim trailing whitespace from a string. class:word {n/a} {n/a} s all