Introduction, RegexFree, RegexGetErrorDescription, RegexGetMatch, RegexGetMatchCount, RegexMatches, RegexSearch, strcspn, StrMapCreate, StrMapFind, StrMapFree, StrMapGet, StrMapParseOptions, StrMapSet, StrMapUnset, strncmp, strncopy, strpbrk, strsplit, strtok
Description
Introduction();
Import("NkString.dll");
The commands in the NkString library operated on NIS strings. Run the file ~nis\macros\NkString.mac to load the library in NIS. The example macro ~nis\Examples\NkStringDemo.mac illustrates the usage of the commands. There are three categories: 1) standard c-lib string functions starting with 'str'; 2) map functions starting with 'StrMap' that implement a library of strings based on std::map<std:string,std:string> and 3) regex functions starting with 'Regex' that implement regular expressions based on std::regex. More documentation on these functions is found on public websites.
# a fragment from ~nis\Examples\NkStringDemo.mac int main() { if(!ExistProc("RegexCreate")) { RunMacro("c:/Program Files/NIS-Elements/macros/NkString.mac"); } NKS_split_example(); NKS_map_example(); NKS_regex_example(); NKS_regex_demo(); }
Description
strncmp( char *left
, char *right
, int64n
);
Compares the first “n” characters of the “left” and “right” strings. A value of -1 is returned when the “left” string sorts lexigraphical before “right”; +1 when after and 0 when the first n characters are the same.
Description
strncopy( char *dst
, char *str
, int64n
);
Copies the first “n” characters from “src” to “dst”. When the “src” string is longer than “n”, no terminating zero character is appended.
Description
strtok( char *str
, char *delims
, int64context
);
Returns the pointer to the next field in “str” terminated by the characters in “delims” array. To terminate the field, the delimiter character in the “str” buffer replaced by a “0”. Call strtok again with NULL as first argument to get the next field. The context variable is used to remember next position.
Description
strcspn( char *str
, char *tokens
);
Returns the position of the first character in “str” that is in “tokens”.
Description
strpbrk( char *str
, char *tokens
);
Returns the pointer to the first character in “str” that is in “tokens”.
Description
strsplit( int64 *offsets
, int64count
, char *str
, char *tokens
, longsplit_flags
);
The function strsplit splits the source string “str” into maximal “count” fields that are terminated by the “tokens” characters. It calls the function strtok() repeatedly and stores the position of the begin of each field in the “offsets” array. After calling strplit, field i can be accessed using str + offsets[i].
Parameters
Description
RegexFree(
int64 regex_id
);
Releases the resouces of the regex object with the specified ID.
Description
RegexGetErrorDescription(
int64 regex_id
);
Returns pointer to the description of the last failed call to RegexCompile.
Description
RegexMatches( int64regex_id
, char *string_to_match
, int64match_flags
);
Matches a string to the compiled expression and returns the number of matches. Use the function RegexSearch to match the beginning of the string only. Refer to the std::matches documentation for more information.
Parameters
regex_id
The ID of the regex object. Use different IDs when more than one regex object is needed.
match_flags
One or more of these options:
the default behavior | |
the first character will not be treated as the begin of a line | |
the last character will not be treated as the end of a line | |
the first character will not be treated as the begin of a word | |
the last character will not be treated as the end of a word | |
if more than one match is possible, then any match is an acceptable result | |
do not match empty sequences | |
Only match a sub-sequence at the begin of string_to_match | |
when set, causes match_not_bol and match_not_bow to be ignored |
Description
RegexSearch( int64regex_id
, char *string_to_search
, int64search_flags
);
Matches the begin of a string to the compiled expression and returns the number of matches. After a succesful search, call RegexSearch again with the NKSTRING_SEARCH_NEXT flag to resume the search at the end of the last match. The contents of the string buffer 'string_to_search' should not be modified between subsequent calls to RegexSearch. Use the function RegexMatches to match the full string. Refer to the std::search documentation for more information.
Parameters
regex_id
The ID of the regex object. Use different IDs when more than one regex object is needed.
search_flags
One or more of these options:
the default behavior | |
the first character will not be treated as the begin of a line | |
the last character will not be treated as the end of a line | |
the first character will not be treated as the begin of a word | |
the last character will not be treated as the end of a word | |
if more than one match is possible, then any match is an acceptable result | |
do not match empty sequences | |
Only match a sub-sequence at the begin of string_to_match | |
when set, causes match_not_bol and match_not_bow to be ignored | |
continue the search at the end of the last match (only for RegexSearch) |
Description
RegexGetMatchCount(
int64 regex_id
);
Returns the number of matches after a call to RegexMatches or RegexSearch.
Description
RegexGetMatch( int64regex_id
, int64match_index
);
Returns a pointer to the match.
Description
StrMapCreate( int64 *phMap
, char *init
);
Creates a map and optionally initializes it ({key1:value1,key2:value2}).
Description
StrMapSet( int64hMap
, char *key
, char *value
);
Adds a key value pair to the map.
Description
StrMapUnset( int64hMap
, char *key
);
Removes the specified key from the map.
Description
StrMapGet( int64hMap
, char *key
, char *value
);
Returns the value mapped to the key (empty string if the key is not in the map).