Project

General

Profile

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

Functions

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

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

\param S : first string to test
\param S : second string to test

\return 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

\param [S r1] : list
\param S : string to search

\return 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

\param [S r1] : list
\param S : string to search

\return 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

\param [S r1] : list
\param S : string to search

\return 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

\param [S r1] : list
\param S : string to search

\return 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]

\param [S r1] : list
\param S : element to add

\return [S r1] : new list
std_szAddUniqueResult ( list  ,
tuple   
)

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

<b>Prototype:</b> 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
\return [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
\return 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
\return 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
\return 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]

\param S : a string
\param S : any separator (one or more chars)

\return 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.
<b>Prototype:</b> fun [S S S] S

\param S : the string to change
\param S : the string to find
\param S : the string to replace with

\return 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.
<b>Prototype:</b> fun [S S [S r1]] S

\param S : string
\param S : the key "$" for example
\param [S r1] : list of arguments

\return 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.

<b>Prototype:</b> 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.