dkstr.h File Reference

String functions. More...

#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.


Detailed Description

String functions.

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.


Function Documentation

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.

Parameters:
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.
Returns:
The index of the pattern matching s in a (or -1 if s was not found).
If a contains a pattern 'h$elp' and c = '$' the strings 'h', 'he', 'hel' and 'help' will match the pattern.

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.

Parameters:
a Array containing patterns.
s String to search for.
cs Flag to indicate case-sensitive search.
Returns:
The index of s in a (or -1 if the array does not contain the string).

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.

Parameters:
a One string.
b The other string.
Returns:
The comparison result.

void dkstr_chomp ( char *  str,
char *  whsp 
)

Remove trailing whitespaces.

The function removes trailing whitespaces from a string.

Parameters:
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.
Examples:
stotest.c.

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.

Parameters:
c The character to search for.
str The string to search for c.
Returns:
  • Pointer to the first occurance of c found or
  • NULL if str does not contain 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.

Parameters:
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.

Parameters:
a The string to copy.
Returns:
A pointer to the new copy of the string. Use dk_delete() to release the memory used by the copy if the copy is not longer needed.
Examples:
stotest.c.

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.

Parameters:
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.
Returns:
The number of array elements used in a.

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.

Parameters:
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.
Returns:
The index of the matching pattern or -1 if no such pattern was found.

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.

Parameters:
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.
Returns:
The index of the matching pattern or -1 if no such pattern was found.

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.

Parameters:
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.
Returns:
Positive value if the string matches the pattern, 0 if there is no match.
If the special character c is '$' and the pattern p is 'h$elp' the texts 'h', 'he', 'hel' and 'help' will match.

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]+).

Parameters:
str String to check.
Returns:
1 if str is an identifier, 0 if not.

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.

Parameters:
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.
Returns:
Pointer to the beginning of the second text word in str.

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.

Parameters:
c The character to search for.
str The string to search for c.
Returns:
  • Pointer to the last occurance of c found or
  • NULL if str does not contain 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.

Parameters:
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.
Returns:
Pointer to the first text character (or NULL if there is no text).
Examples:
stotest.c.

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.

Parameters:
str The source string.
quotes A string containing the characters representing quotes.
Returns:
A pointer to the string without surrounding quotes.


Generated on Thu Feb 25 13:48:25 2010 for dklibs by  doxygen 1.5.8