#include <dk.h>
#include <dktypes.h>
Go to the source code of this file.
Functions | |
int | dkstr_casecmp (char *a, char *b) |
Case insensitive comparison. | |
char * | dkstr_dup (char *a) |
Duplicate a string. | |
char * | dkstr_chr (char *str, int c) |
Find first occurance of character. | |
char * | dkstr_rchr (char *str, int c) |
Find last occurance of character. | |
void | dkstr_delcomm (char *s, char c) |
Delete comments from text line. | |
char * | dkstr_start (char *str, char *whsp) |
Find start of text. | |
void | dkstr_chomp (char *str, char *whsp) |
Remove trailing whitespaces. | |
char * | dkstr_next (char *str, char *whsp) |
Find next text. | |
int | dkstr_is_abbr (char *s, char *p, char c, int cs) |
Check abbreviation. | |
int | dkstr_is_bool (char *str) |
Check whether text is a boolean value. | |
int | dkstr_is_on (char *str) |
Check whether text is the boolean value for true. | |
int | dkstr_array_index (char **a, char *s, int cs) |
Find index of a text word in an array. | |
int | dkstr_array_abbr (char **a, char *s, char c, int cs) |
Find index of abbreviated text in an array. | |
size_t | dkstr_explode (char **a, size_t sz, char *s, char *wh) |
Explode multi-part string into array of strings. | |
int | dkstr_find_multi_part_cmd (char **c, char ***s, int cs) |
Find index of multi-word text in array of multi-word patterns. | |
int | dkstr_find_multi_part_abbr (char **c, char ***s, char sc, int cs) |
Find index of abbreviated multi-word text in array of multi-word patterns. | |
int | dkstr_is_identifier (char *str) |
Check whether a string is an identifier. | |
char * | dkstr_unquote (char *str, char *quotes) |
Unquote a string. |
This module contains functions to handle strings.
Unless otherwise stated, int functions in this module return a positive number to indicate success or a true condition, 0 to indicate an error or an unfullfilled condition. Pointer functions return valid pointers on success, NULL on error.
int dkstr_array_abbr | ( | char ** | a, | |
char * | s, | |||
char | c, | |||
int | cs | |||
) |
Find index of abbreviated text in an array.
The function checks the string array a whether or not s is an abbreviation of one of the array elements. The character c introduces the optional text in each array element. The cs parameter can be used to do a case-sensitive search.
a | Array containing patterns. | |
s | String to search for. | |
c | Control character (introduces the optional part of the pattern). | |
cs | Flag to indicate case-sensitive search. |
int dkstr_array_index | ( | char ** | a, | |
char * | s, | |||
int | cs | |||
) |
Find index of a text word in an array.
The function checks the string array a whether or not it contains the string s and returns the index of s in a. The cs parameter can be set to do a case-sensitive search.
a | Array containing patterns. | |
s | String to search for. | |
cs | Flag to indicate case-sensitive search. |
int dkstr_casecmp | ( | char * | a, | |
char * | b | |||
) |
Case insensitive comparison.
The function compares two strings a and b. The function returns 0 if both strings are equal in a case-insensitive comparison, a positive value if a > b or a negative value if a < b.
a | One string. | |
b | The other string. |
void dkstr_chomp | ( | char * | str, | |
char * | whsp | |||
) |
Remove trailing whitespaces.
The function removes trailing whitespaces from a string.
str | String to remove tailing whitespaces from. | |
whsp | A string listing all whitespaces. This parameter can be set to NULL to use a default set of whitespaces. |
char* dkstr_chr | ( | char * | str, | |
int | c | |||
) |
Find first occurance of character.
The function searches for the first orrucance of c in string str and returns a pointer to the address of c.
c | The character to search for. | |
str | The string to search for c. |
void dkstr_delcomm | ( | char * | s, | |
char | c | |||
) |
Delete comments from text line.
This function removes a comment started by the comment starter character c from text line s by replacing the c character by a 0-byte. The replacement is only done if c is not a part of a string in single or double quotes.
s | The string to modify. | |
c | Special character marking the start of a comment. |
char* dkstr_dup | ( | char * | a | ) |
Duplicate a string.
The function allocates memory to create a copy of string a.
a | The string to copy. |
size_t dkstr_explode | ( | char ** | a, | |
size_t | sz, | |||
char * | s, | |||
char * | wh | |||
) |
Explode multi-part string into array of strings.
The function splits the string s consisting of multiple text words into a sequence of multiple strings containing one text word each. The pointers to the beginnings of the text words are stored in array a.
a | Array to store the pointers to the beginnings of the text words. | |
sz | Number of array elements in a. | |
s | The string to split. | |
wh | A string listing all the whitespace characters. |
int dkstr_find_multi_part_abbr | ( | char ** | c, | |
char *** | s, | |||
char | sc, | |||
int | cs | |||
) |
Find index of abbreviated multi-word text in array of multi-word patterns.
The functions searches for the index of a multi-word command c in an array s of multi-word patterns.
c | The command to search for. | |
s | The array of multi-word commands, allowing abbreviations. | |
sc | Special character to mark the beginning of the optional text word parts in the patterns. | |
cs | Flag to indicate case-sensitive search. |
int dkstr_find_multi_part_cmd | ( | char ** | c, | |
char *** | s, | |||
int | cs | |||
) |
Find index of multi-word text in array of multi-word patterns.
The function searches for the index of a multi-word command c in an array s of multi-word patterns and returns the index of the first matching pattern.
c | Multi-word command to search for (finished by a NULL pointer). | |
s | Array of multi-word patterns (finished by a NULL pointer, each pattern finished by a NULL pointer). | |
cs | Flag to indicate case-sensitive search. |
int dkstr_is_abbr | ( | char * | s, | |
char * | p, | |||
char | c, | |||
int | cs | |||
) |
Check abbreviation.
The function checks whether or not the string s is an abbreviation of pattern p. The special character c marks the beginning of the optional part in pattern p. The cs parameter can be used to indicate case-sensitive search.
s | String to check. | |
p | The pattern to compare against. | |
c | Special character to mark the start of the optional part of the pattern. | |
cs | Flag for case-sensitive comparison. |
int dkstr_is_bool | ( | char * | str | ) |
Check whether text is a boolean value.
This function checks whether or not the text in str represents a boolean value.
int dkstr_is_identifier | ( | char * | str | ) |
Check whether a string is an identifier.
The function checks whether str is an languaidentifier in a programming language (str must match [a-zA-Z_][a-zA-Z_01-9]+).
str | String to check. |
int dkstr_is_on | ( | char * | str | ) |
Check whether text is the boolean value for true.
This function checks whether or not the text in str represents the boolean value "true".
char* dkstr_next | ( | char * | str, | |
char * | whsp | |||
) |
Find next text.
After finding the beginning of text in a string str this function can be used to find the next text word in the string. The first text word is finished using a 0-byte.
str | The string to search for the next text word. | |
whsp | A string listing all whitespaces. This paramter can be set to NULL to use a default set of whitespaces. |
char* dkstr_rchr | ( | char * | str, | |
int | c | |||
) |
Find last occurance of character.
The function searches for the last orrucance of c in string str and returns a pointer to the address of c.
c | The character to search for. | |
str | The string to search for c. |
char* dkstr_start | ( | char * | str, | |
char * | whsp | |||
) |
Find start of text.
The function searches for the first non-whitespace in str and returns a pointer to it.
str | String to search for test. | |
whsp | String containing all characters to treat as whitespaces. This paramter can be NULL to use a default set of whitespaces. |
char* dkstr_unquote | ( | char * | str, | |
char * | quotes | |||
) |
Unquote a string.
This function removes single or double quotes from a string and returns a pointer to the result string.
str | The source string. | |
quotes | A string containing the characters representing quotes. |