NkString.dll

Introduction, RegexFree, RegexGetErrorDescription, RegexGetMatch, RegexGetMatchCount, RegexMatches, RegexSearch, strcspn, StrMapCreate, StrMapFind, StrMapFree, StrMapGet, StrMapParseOptions, StrMapSet, StrMapUnset, strncmp, strncopy, strpbrk, strsplit, strtok

Introduction

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();
}
strncmp

Description 

 strncmp(
   char *left,
   char *right,
   int64  n
);

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.

Parameters

char *left

The first string to compare.

char *right

The second string to compare.

int64 n

The number of characters.

strncopy

Description 

 strncopy(
   char *dst,
   char *str,
   int64  n
);

Copies the first n characters from src to dst. When the src string is longer than n, no terminating zero character is appended.

Parameters

char *dst

The destination string.

char *str

Pointer to the string.

int64 n

The number of characters.

strtok

Description 

 strtok(
   char *str,
   char *delims,
   int64  context
);

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.

Parameters

char *str

Pointer to the string.

char *delims

The delimiter characters.

int64 context

Pointer to the variable where offset of the next field is stored.

strcspn

Description 

 strcspn(
   char *str,
   char *tokens
);

Returns the position of the first character in str that is in tokens.

Parameters

char *str

Pointer to the string.

char *tokens

The characters to search for.

strpbrk

Description 

 strpbrk(
   char *str,
   char *tokens
);

Returns the pointer to the first character in str that is in tokens.

Parameters

char *str

Pointer to the string.

char *tokens

The characters to search for.

strsplit

Description 

 strsplit(
   int64 *offsets,
   int64  count,
   char *str,
   char *tokens,
   long  split_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

int64 *offsets

The array that is filled with the offset of each field.

int64 count

The size of the array.

char *str

Pointer to the string.

char *tokens

The delimiter characters (or string if the flag STRSPLIT_TOKEN_SEQUENCE is specified).

long split_flags

One or more of these options:

STRSPLIT_DEFAULT 0

The tokens string is set of characters keep empty fields between two tokens are preserved.

STRSPLIT_SKIP_EMPTY_FIELDS 1

Empty fields between tokens are discarded.

STRSPLIT_TOKEN_SEQUENCE 2

The tokens string is a fixed sequence.

STRSPLIT_ESCAPE 4

Tokens preceded by \ are ignored.

RegexFree

Description 

 RegexFree(
   int64  regex_id
);

Releases the resouces of the regex object with the specified ID.

Parameters

int64 regex_id

The ID of the regex object. Use different IDs when more than one regex object is needed.

RegexGetErrorDescription

Description 

 RegexGetErrorDescription(
   int64  regex_id
);

Returns pointer to the description of the last failed call to RegexCompile.

Parameters

int64 regex_id

The ID of the regex object. Use different IDs when more than one regex object is needed.

RegexMatches

Description 

 RegexMatches(
   int64  regex_id,
   char *string_to_match,
   int64  match_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

int64 regex_id

The ID of the regex object. Use different IDs when more than one regex object is needed.

char *string_to_match

The string to match.

int64 match_flags

One or more of these options:

NKSTRING_MATCH_DEFAULT 0

the default behavior

NKSTRING_MATCH_NOT_BOL 1

the first character will not be treated as the begin of a line

NKSTRING_MATCH_NOT_EOL 2

the last character will not be treated as the end of a line

NKSTRING_MATCH_NOT_BOW 4

the first character will not be treated as the begin of a word

NKSTRING_MATCH_NOT_EOW 8

the last character will not be treated as the end of a word

NKSTRING_MATCH_ANY 16

if more than one match is possible, then any match is an acceptable result

NKSTRING_MATCH_NOT_NULL 32

do not match empty sequences

NKSTRING_MATCH_CONTINUOUS 64

Only match a sub-sequence at the begin of string_to_match

NKSTRING_MATCH_PREV_AVAIL 128

when set, causes match_not_bol and match_not_bow to be ignored

RegexSearch

Description 

 RegexSearch(
   int64  regex_id,
   char *string_to_search,
   int64  search_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

int64 regex_id

The ID of the regex object. Use different IDs when more than one regex object is needed.

char *string_to_search

The string to search.

int64 search_flags

One or more of these options:

NKSTRING_MATCH_DEFAULT 0

the default behavior

NKSTRING_MATCH_NOT_BOL 1

the first character will not be treated as the begin of a line

NKSTRING_MATCH_NOT_EOL 2

the last character will not be treated as the end of a line

NKSTRING_MATCH_NOT_BOW 4

the first character will not be treated as the begin of a word

NKSTRING_MATCH_NOT_EOW 8

the last character will not be treated as the end of a word

NKSTRING_MATCH_ANY 16

if more than one match is possible, then any match is an acceptable result

NKSTRING_MATCH_NOT_NULL 32

do not match empty sequences

NKSTRING_MATCH_CONTINUOUS 64

Only match a sub-sequence at the begin of string_to_match

NKSTRING_MATCH_PREV_AVAIL 128

when set, causes match_not_bol and match_not_bow to be ignored

NKSTRING_SEARCH_NEXT 16777216

continue the search at the end of the last match (only for RegexSearch)

RegexGetMatchCount

Description 

 RegexGetMatchCount(
   int64  regex_id
);

Returns the number of matches after a call to RegexMatches or RegexSearch.

Parameters

int64 regex_id

The ID of the regex object. Use different IDs when more than one regex object is needed.

RegexGetMatch

Description 

 RegexGetMatch(
   int64  regex_id,
   int64  match_index
);

Returns a pointer to the match.

Parameters

int64 regex_id

The ID of the regex object. Use different IDs when more than one regex object is needed.

int64 match_index

The match index, use the function RegexGetMatchCount to get the number of matches.

StrMapCreate

Description 

 StrMapCreate(
   int64 *phMap,
   char *init
);

Creates a map and optionally initializes it ({key1:value1,key2:value2}).

Parameters

int64 *phMap

The address of the variable to store the handle of the map.

char *init

The comma separated key:value pairs with which the map is initialized.

StrMapFree

Description 

 StrMapFree(
   int64 *phMap
);

Releases the resources used by the map.

Parameters

int64 *phMap

The address of the variable to store the handle of the map.

StrMapSet

Description 

 StrMapSet(
   int64  hMap,
   char *key,
   char *value
);

Adds a key value pair to the map.

Parameters

int64 hMap

The handle of the map.

char *key

The key.

char *value

The value.

StrMapUnset

Description 

 StrMapUnset(
   int64  hMap,
   char *key
);

Removes the specified key from the map.

Parameters

int64 hMap

The handle of the map.

char *key

The key.

StrMapFind

Description 

 StrMapFind(
   int64  hMap,
   char *key
);

Returns true if the key is in the map.

Parameters

int64 hMap

The handle of the map.

char *key

The key.

StrMapGet

Description 

 StrMapGet(
   int64  hMap,
   char *key,
   char *value
);

Returns the value mapped to the key (empty string if the key is not in the map).

Parameters

int64 hMap

The handle of the map.

char *key

The key.

char *value

The value.

StrMapParseOptions

Description 

 StrMapParseOptions(
   int64  hMap,
   char *options
);

Returns the integer sum of the options in the string. Initialize the list with numerical values only, e.g. {option1:1,option2:2,option3:4}. Parsing the option string option1|option3 will return 5 (1+4).

Parameters

int64 hMap

The handle of the map.

char *options

Option keys separated by the pipe symbol (|).