Scol standard library package  0.3.1
Common and usefull functions for all Scol applications
Functions
The string API for string manipulations.

Functions

 std_szAddEscape (str, lAsc)
 Protect special character with a '\'. More...
 
 std_szAddUnique (list, str)
 Add a string element as unique. This function is case-sensitive. More...
 
 std_szAddUniqueResult (list, tuple)
 
 std_szCatSep (list, sep)
 Concat a string list with a defined separator. More...
 
 std_szCheckLastChar (str, c)
 Check the last char of a string. More...
 
 std_szCheckSubPos (str, sub, pos)
 Compare if a sub string is in a string at a given position. This function is sensitive-case. More...
 
 std_szCmp (s1, s2)
 Check if the first string is found to be equal, less or greater than the second string. This function is case-sensitive. More...
 
 std_szCutFromSep (str, sep)
 Cut a string when the first seperator is found. More...
 
 std_szCutFromSepAll (str, sep)
 Cut a string with all seperator found. More...
 
 std_szGetBoolean (str)
 Get the boolean value of a string. This function is insensitive-case. More...
 
 std_szGetPosInList (list, string)
 Get the position of a string in a list. This function is case-sensitive. More...
 
 std_szGreater (s1, s2)
 Check if the first string is found to be greater than the second string. This function is case-sensitive. More...
 
 std_sziAddUnique (list, str)
 Add a string element as unique. This function is case-insensitive. More...
 
 std_sziAddUniqueResult (list, tuple)
 Add a string element as unique. This function is case-insensitive. More...
 
 std_sziCheckSubPos (str, sub, pos)
 Compare if a sub string is in a string at a given position. This function is insensitive-case. More...
 
 std_sziCmp (s1, s2)
 Check if the first string is found to be equal, less or greater than the second string. This function is case-insensitive. More...
 
 std_sziGetPosInList (list, string)
 Get the position of a string in a list. This function is case-insensitive. More...
 
 std_sziGreater (s1, s2)
 Check if the first string is found to be greater than the second string. This function is case-insensitive. More...
 
 std_sziInList (list, string)
 Test if a string exist in a list. This function is case-insensitive. More...
 
 std_sziInListFromPos (list, string, pos, length)
 Test if a string exist in a list from a given position. This function is case-insensitive. More...
 
 std_sziIsEqual (s1, s2)
 Check if two strings are equals. This function is case-insensitive. More...
 
 std_sziLesser (s1, s2)
 Check if the first string is found to be less than the second string. This function is case-insensitive. More...
 
 std_szInList (list, string)
 Test if a string exist in a list. This function is case-sensitive. More...
 
 std_szInListFromPos (list, string, pos, length)
 Test if a string exist in a list from a given position. This function is case-sensitive. More...
 
 std_sziReplace (s, from, to)
 Replace a string in an another string. Case insensitive. More...
 
 std_szIsDigit (str)
 Return if a string contains digits only (0123456789) More...
 
 std_szIsEmpty (str)
 Check if a string is empty (nil or "") More...
 
 std_szIsEqual (s1, s2)
 Check if two strings are equals. This function is case-sensitive. More...
 
 std_szIsPattern (str, pattern)
 Return if a string contains the characters pattern only. More...
 
 std_sziStrfindR (str, substr)
 Find the last position of a given substring. Function case-insensitive. More...
 
 std_szIsUrl (url)
 Check if a string is an url. More...
 
 std_szLesser (s1, s2)
 Check if the first string is found to be less than the second string. This function is case-sensitive. More...
 
 std_szRemoveLastChar (str)
 Remove the last char of any string. More...
 
 std_szReplace (s, from, to)
 Replace a string in an another string. Case sensitive. More...
 
 std_szReplaceKeys (s, key, args)
 replace key by value position in arg list ("my string is $1 with $2" "val1"::"val2"::nil) More...
 
 std_szStrfindR (str, substr)
 Find the last position of a given substring. Function case-sensitive. More...
 
 std_szXor (szToDo, szKey)
 Perform a xor operation between a string and a key. More...
 

Detailed Description

Package to load : lib/std/string.pkg

Function Documentation

std_szIsEmpty ( str  )

Check if a string is empty (nil or "")

Prototype: fun [S] I

Parameters
S: the string to test
Returns
I : 1 if empty else 0
std_szLesser ( s1  ,
s2   
)

Check if the first string is found to be less than the second string. This function is case-sensitive.

Prototype: fun [S S] I

Parameters
S: first string to test
S: second string to test
Returns
I : 1 if less otherwise 0
std_szGreater ( s1  ,
s2   
)

Check if the first string is found to be greater than the second string. This function is case-sensitive.

Prototype: fun [S S] I

Parameters
S: first string to test
S: second string to test
Returns
I : 1 if greater 0 otherwise
std_sziLesser ( s1  ,
s2   
)

Check if the first string is found to be less than the second string. This function is case-insensitive.

Prototype: fun [S S] I

Parameters
S: first string to test
S: second string to test
Returns
I : 1 if less otherwise 0
std_sziGreater ( s1  ,
s2   
)

Check if the first string is found to be greater than the second string. This function is case-insensitive.

Prototype: fun [S S] I

Parameters
S: first string to test
S: second string to test
Returns
I : 1 if greater 0 otherwise
std_szCmp ( s1  ,
s2   
)

Check if the first string is found to be equal, less or greater than the second string. This function is case-sensitive.

Prototype: fun [S S] I

Parameters
S: first string to test
S: second string to test
Returns
I : a negative value if lesser, a positive value if greater 0 if equal
std_szIsEqual ( s1  ,
s2   
)

Check if two strings are equals. This function is case-sensitive.

Prototype: fun [S S] I

Parameters
S: first string to test
S: second string to test
Returns
I : 1 if equal, otherwise 0
std_sziCmp ( s1  ,
s2   
)

Check if the first string is found to be equal, less or greater than the second string. This function is case-insensitive.

Prototype: fun [S S] I

Parameters
S: first string to test
S: second string to test
Returns
I : a negative value if lesser, a positive value if greater 0 if equal
std_sziIsEqual ( s1  ,
s2   
)

Check if two strings are equals. This function is case-insensitive.

Prototype: fun [S S] I

Parameters
S: first string to test
S: second string to test
Returns
I : 1 if equal, otherwise 0
std_szInList ( list  ,
string   
)

Test if a string exist in a list. This function is case-sensitive.

Prototype: fun [[S r1] S] I

Parameters
[Sr1] : list
S: string to search
Returns
I : 1 if the string exist in the list 0 otherwise
std_sziInList ( list  ,
string   
)

Test if a string exist in a list. This function is case-insensitive.

Prototype: fun [[S r1] S] I

Parameters
[Sr1] : list
S: string to search
Returns
I : 1 if the string exist in the list 0 otherwise
std_szInListFromPos ( list  ,
string  ,
pos  ,
length   
)

Test if a string exist in a list from a given position. This function is case-sensitive.

Prototype: fun [[S r1] S I I] I

Parameters
[Sr1] : list
S: string to search
Returns
I : 1 if the string exist in the list 0 otherwise
std_sziInListFromPos ( list  ,
string  ,
pos  ,
length   
)

Test if a string exist in a list from a given position. This function is case-insensitive.

Prototype: fun [[S r1] S I I] I

Parameters
[Sr1] : list
S: string to search
Returns
I : 1 if the string exist in the list 0 otherwise
std_szAddUnique ( list  ,
str   
)

Add a string element as unique. This function is case-sensitive.

Prototype: fun [[S r1] S] [S r1]

Parameters
[Sr1] : list
S: element to add
Returns
[S r1] : new list
std_szAddUniqueResult ( list  ,
tuple   
)

Add a string element as unique. This function is case-sensitive.

Prototype: fun [[S r1] [S I]] [S r1]

Parameters
[Sr1] : list
[SI] : string to add and the result : 1 is set if the string is added, else 0
Returns
[S r1] : new list
(...)
_showconsole;
let "aa" :: "az" :: "12" :: "sdf" :: "aa" :: "ws" :: nil -> ls in
let ["as" nil] -> tuple1 in
let ["aa" nil] -> tuple2 in
(
_fooSList std_szAddUniqueResult ls tuple1;  // "as:"aa":"az":"12":"sdf":"aa":"ws";nil
_fooS sprintf "s i" tuple1; // string added and result (1)
_fooSList std_szAddUniqueResult ls tuple2;  // "aa":"az":"12":"sdf":"aa":"ws";nil
_fooS sprintf "s i" tuple2; // string added and result (0, "aa" is already in the list)
(...)
std_sziAddUnique ( list  ,
str   
)

Add a string element as unique. This function is case-insensitive.

Prototype: fun [[S r1] S] [S r1]

Parameters
[Sr1] : list
S: element to add
Returns
[S r1] : new list
std_sziAddUniqueResult ( list  ,
tuple   
)

Add a string element as unique. This function is case-insensitive.

Prototype: fun [[S r1] [S I]] [S r1]

Parameters
[Sr1] : list
[SI] : string to add and the result : 1 is set if the string is added, else 0
Returns
[S r1] : new list
std_szGetPosInList ( list  ,
string   
)

Get the position of a string in a list. This function is case-sensitive.

Prototype: fun [[S r1] S] I

Parameters
[Sr1] : list
S: a string to found
Returns
I : the position or nil if not found
std_sziGetPosInList ( list  ,
string   
)

Get the position of a string in a list. This function is case-insensitive.

Prototype: fun [[S r1] S] I

Parameters
[Sr1] : list
S: a string to found
Returns
I : the position or nil if not found
std_szRemoveLastChar ( str  )

Remove the last char of any string.

Prototype: fun [S] S

Parameters
S: a string
Returns
S : the same string less the last char
std_szCheckLastChar ( str  ,
 
)

Check the last char of a string.

Prototype: fun [S S] I

Parameters
S: a string
S: a string (if more one char, the only first char is taken)
Returns
I : 1 if equal, otherwise 0
std_szStrfindR ( str  ,
substr   
)

Find the last position of a given substring. Function case-sensitive.

Prototype: fun [S S] I

Parameters
S: a string
S: a sub-string
Returns
I : the last position or -1 if not found
std_sziStrfindR ( str  ,
substr   
)

Find the last position of a given substring. Function case-insensitive.

Prototype: fun [S S] I

Parameters
S: a string
S: a sub-string
Returns
I : the last position or -1 if not found
std_szIsDigit ( str  )

Return if a string contains digits only (0123456789)

Prototype: fun [S] I

Parameters
S: a string
Returns
I : 1 if ok else 0
std_szIsPattern ( str  ,
pattern   
)

Return if a string contains the characters pattern only.

_fooId std_szIsPattern "mississipi" "mpsie"; // 1
_fooId std_szIsPattern "michigan" "mpsie";  // 0

Prototype: fun [S] I

Parameters
S: a string
S: a pattern
Returns
I : 1 if ok else 0.
Remarks
"[az]" is equal at "abcdefghijklmnopqrstuvwxyz", "[AZ]" is equal at "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "[aZ]" is equalt at "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" and "[09]" is equal at "0123456789". So a pattern such as "+-.=[az][09]" is valid and it is equal at "+-.=abcdefghijklmnopqrstuvwxyz0123456789". There are no 'joker' supported.
to include a double quote ("), escape it.
std_szCutFromSep ( str  ,
sep   
)

Cut a string when the first seperator is found.

_fooS sprintf "%s %s" std_szCutFromSep "lib/std/string.pkg" "/"; // lib std/string.pkg

Prototype: fun [S S] [S S]

Parameters
S: a string
S: any separator (one or more chars)
Returns
I : a tuple with the two sub-strings or nil if separator is not found
std_szCutFromSepAll ( str  ,
sep   
)

Cut a string with all seperator found.

_fooSList std_szCutFromSepAll "lib/std/string.pkg" "/"; // lib :: std :: string.pkg :: nil

Prototype: fun [S S] [S r1]

Parameters
S: a string
S: any separator (one or more chars)
Returns
I : a list of sub-strings. If no seperator found, the list has only one no-nil element with the entire string.
std_szGetBoolean ( str  )

Get the boolean value of a string. This function is insensitive-case.

Prototype: fun [S] I

Parameters
S: the boolean value "enable" "1" "on" "true" "yes"
Returns
I : 1 if the boolean value is correct, 0 otherwise
std_szCheckSubPos ( str  ,
sub  ,
pos   
)

Compare if a sub string is in a string at a given position. This function is sensitive-case.

Prototype: fun [S S I] I

Parameters
S: the full string
S: the substring to compare
I: a position (if nil, the position will be 0)
Returns
I : 1 if ok, 0 otherwise
std_sziCheckSubPos ( str  ,
sub  ,
pos   
)

Compare if a sub string is in a string at a given position. This function is insensitive-case.

Prototype: fun [S S I] I

Parameters
S: the full string
S: the substring to compare
I: a position (if nil, the position will be 0)
Returns
I : 1 if ok, 0 otherwise
std_szReplace ( ,
from  ,
to   
)

Replace a string in an another string. Case sensitive.

Remarks
you can use the SYSPACK API : strreplace (fun [S S S I] S) faster but the syspack library is required on the client.

Prototype: fun [S S S] S

Parameters
S: the string to change
S: the string to find
S: the string to replace with
Returns
S : the new string
std_sziReplace ( ,
from  ,
to   
)

Replace a string in an another string. Case insensitive.

Prototype: fun [S S S] S

Parameters
S: the string to change
S: the string to find
S: the string to replace with
Returns
S : the new string
std_szReplaceKeys ( ,
key  ,
args   
)

replace key by value position in arg list ("my string is $1 with $2" "val1"::"val2"::nil)

Remarks
you can use the SYSPACK API : sprintf (fun [S u0] S) faster but the syspack library is required on the client.

Prototype: fun [S S [S r1]] S

Parameters
S: string
S: the key "$" for example
[Sr1] : list of arguments
Returns
S : the converted string
std_szCatSep ( list  ,
sep   
)

Concat a string list with a defined separator.

Prototype: fun [[S r1] S] S

Parameters
[Sr1] : the string list
S: the separator to use
Returns
S : the new string
std_szAddEscape ( str  ,
lAsc   
)

Protect special character with a '\'.

Prototype: fun [S [I r1]] S

Parameters
S: the string to protect
S: a list of ascii char to escape (% -> 37, & -> 38, ...)
Returns
S : the new string
std_szIsUrl ( url  )

Check if a string is an url.

Prototype: fun [S] I

Parameters
S: the string to test
Returns
I : 1 if ok else 0
Remarks
Known protocols : http, https, file, ftp, ftps, sftp, scol.
std_szXor ( szToDo  ,
szKey   
)

Perform a xor operation between a string and a key.

The string is splitted in word of key lenght. For each word, the xor operation is performed : the string becomes "ciphered". To "uncipher", call this same function with the same key to retrieve the initial string.

This is very easy to use : any string and the same key to cipher / uncipher. However, it is easy to uncipher the ciphered string. This function should not be used in a critical secure environment.

Prototype: fun [S S] S

Parameters
S: the string to cipher/uncipher
S: the key
Returns
S : the ciphered/unciphered string.
See also
std_sfXor in std/systemfiles.pkg to cipher/uncipher a file.