This class just defines a bunch of string utility functions. They are part of a class just so that they don't clog up the global namespace. I suppose a namespace would have worked just as well. More...
#include <strtool.h>
Classes | |
struct | CharCompare |
Functor object used to compare characters either case sensitively or or insentively. More... | |
struct | Is_Colon |
struct | Is_Comma |
struct | Is_Delim |
struct | Is_Newline |
If you want to use the parse_words method to split a string into lines, this is the Is_Separator parameter type for you. More... | |
struct | Is_Space |
This struct is a 'functor' whose job it is to tell you whether a given character counts as 'space' in the normal way. You can write your own that have more or less complex tests... To use this struct, you construct an object of this type then execute the object like a funct -- passing it a character. The return value from the function call is a boolean value that tells you whether or not the character you pass in is whitespace. More... | |
struct | Is_Tab |
Public Types | |
enum | constants { all = 2000000000 } |
typedef std::string | string |
typedef std::list< string > | stringlist_t |
Static Public Member Functions | |
static int | compareInsensitive (std::string const &a, std::string const &b) |
static string | expand_tabs (string const &r, bool *non_printable_chars=0, char replacement=0) |
Same as the above, except it takes a std::string instead of a character buffer. | |
static string | expand_tabs (char const *sourceBytes, bool *non_printable_chars=0, char replacement=0) |
Copy the input string and expand tab characters in the put into spaces in the output. Tab expansion is done based on tab 'stop' positions -- it is not a simple string substitution. Basically, a tab character means 'insert spaces until the the text tab stop'. Tab stops are 8 characters apart in the unix standard -- which the function implements. | |
static size_t | find (char const *fragment, std::string const &within, bool insensitive) |
static size_t | find (std::string const &fragment, std::string const &within, bool insensitive) |
static size_t | find (char const *&fragment, size_t fragLen, char const *&within, size_t totalLen, bool insensitive) |
search for a string fragment within a larger string and return an offset to the start of the fragment. If not found, then return an offset outside the larger string. | |
template<class It1 , class It2 > | |
static It1 | find_next_word (It1 start, It1 end, It2 word_start, It2 word_end) |
Search the sequence from start to end looking for the beginning of the next "word", from the given start position. The sequence word_start to word_end defines a list of valid word characters. | |
template<class It1 , class It2 > | |
static It1 | find_prev_word (It1 start, It1 begin, It1 end, It2 word_start, It2 word_end) |
Move backwards from start to the beginning of the current or previous word. Words are defined by the characters in the range word_start to word_end. See find_next_word above for a description of how word start positions appear. | |
template<class Char , class Iterator > | |
static bool | is_word_char (Char c, Iterator word_start, Iterator word_end) |
Return true if a character is found in a sequence specified by a pair of iterators. The iterators are presumed to define a list of valid word characters. | |
static string | pack_tabs (string const &r, bool stop_after_first_non_blank=true) |
Convert spaces into tabs wherever possible according to the standard unix 8 character rule. This is the reverse of 'expand_tabs' above. | |
static string | pack_tabs (char const *s, bool stop_after_first_non_blank=true) |
static int | parse_lines (string const &s, stringlist_t *l, unsigned at_most) |
Parses a string into a list of lines -- up to a count of at most 'at_most'. The last parm will have all remaining text. | |
static int | parse_lines (string const &s, stringlist_t *l) |
Parses a string into a list of lines using. | |
static int | parse_words (string const &s, stringlist_t *l, unsigned at_most) |
An overload of the parse_words function that eliminates seldom used parameters in favor of common defaults. See the commentary above for the use of this function. | |
static int | parse_words (string const &s, stringlist_t *l) |
An overload of the parse_words function that eliminates seldom used parameters in favor of common defaults. See the commentary above for the use of this function. | |
template<class IsSeparator > | |
static int | parse_words (string const &s, stringlist_t *l, unsigned at_most, IsSeparator const &is_space) |
Parses a string, which is assumed to be collection of words separated by spaces. The parsed words are stored in a list and the count of words is returned. You can specify a maximum limit of words to store in the list -- the default is to store them all -- well 2 billion anyway. If the maximum limit is reached, all unparsed text is left in the last item in the list -- leading spaces will be removed from it, however. That is, this function works much like the bourne shell 'read' command that reads words from a a file and stores them in environment variables. In this case, the parsed words are stored in a list of strings. | |
static void | remove_leading (std::string &s, char space=' ') |
Remove all leading copies of space from the specified string. | |
static bool | snatch_file_info (std::string const &s, std::string &file, int &line) |
Snatch file information out of a string and return it in file and line. | |
static size_t | splitOnString (std::string const &s, std::vector< std::string > &output, std::string const &sep) |
This class just defines a bunch of string utility functions. They are part of a class just so that they don't clog up the global namespace. I suppose a namespace would have worked just as well.
Definition at line 56 of file strtool.h.
typedef std::list<string> stringlist_t |
static int compareInsensitive | ( | std::string const & | a, | |
std::string const & | b | |||
) | [static] |
string expand_tabs | ( | char const * | sourceBytes, | |
bool * | non_printable_chars = 0 , |
|||
char | replacement = 0 | |||
) | [static] |
Copy the input string and expand tab characters in the put into spaces in the output. Tab expansion is done based on tab 'stop' positions -- it is not a simple string substitution. Basically, a tab character means 'insert spaces until the the text tab stop'. Tab stops are 8 characters apart in the unix standard -- which the function implements.
Parameters:
sourceBytes | defines the text to be tab expanded. | |
non_printable_chars | if specified must point to a boolean variable which will be modified to a value which indicates that non-printable characters exist in the sourceBytes. | |
replacement | if specified, indicates that non-printable characters should be converted to the value of replacement. |
Definition at line 43 of file strtool.cxx.
static size_t find | ( | char const * | fragment, | |
std::string const & | within, | |||
bool | insensitive | |||
) | [static] |
static size_t find | ( | std::string const & | fragment, | |
std::string const & | within, | |||
bool | insensitive | |||
) | [static] |
static size_t find | ( | char const *& | fragment, | |
size_t | fragLen, | |||
char const *& | within, | |||
size_t | totalLen, | |||
bool | insensitive | |||
) | [static] |
search for a string fragment within a larger string and return an offset to the start of the fragment. If not found, then return an offset outside the larger string.
[in] | fragment | The begining of the substring to be searched for. |
[in] | fragLen | The length of the substring to be searched for |
[in] | within | The larger string from which to perform the search |
[in] | totalLen | The length of the larger string from the search is being performed |
[in] | insensitive | True implies a case insensitive search. |
Definition at line 649 of file strtool.h.
static It1 find_next_word | ( | It1 | start, | |
It1 | end, | |||
It2 | word_start, | |||
It2 | word_end | |||
) | [static] |
Search the sequence from start to end looking for the beginning of the next "word", from the given start position. The sequence word_start to word_end defines a list of valid word characters.
This function returns the beginning of the next word or it returns 'end'. Assuming that these iterators are referring to characters, here is an example of word start positions:
word1 word2 word3 word4 ^ ^ ^ ^
Only positions noted by carets will be returne.d
Definition at line 410 of file strtool.h.
static It1 find_prev_word | ( | It1 | start, | |
It1 | begin, | |||
It1 | end, | |||
It2 | word_start, | |||
It2 | word_end | |||
) | [static] |
Move backwards from start to the beginning of the current or previous word. Words are defined by the characters in the range word_start to word_end. See find_next_word above for a description of how word start positions appear.
Definition at line 450 of file strtool.h.
static bool is_word_char | ( | Char | c, | |
Iterator | word_start, | |||
Iterator | word_end | |||
) | [static] |
Convert spaces into tabs wherever possible according to the standard unix 8 character rule. This is the reverse of 'expand_tabs' above.
If stop_after_first_non_blank is true, then tab compression will stop as soon as the first non-blank character is encountered. This prevents the accidental insertion of tab characters into quoted strings in program source code as can occur if you set don't set the flag. Same as the above, except it takes a std::string instead of a character buffer.
If stop_after_first_non_blank is true, then tab compression will stop as soon as the first non-blank character is encountered. This prevents the accidental insertion of tab characters into quoted strings in program source code as can occur if you set don't set the flag.
Definition at line 381 of file strtool.h.
string pack_tabs | ( | char const * | s, | |
bool | stop_after_first_non_blank = true | |||
) | [static] |
Definition at line 92 of file strtool.cxx.
static int parse_lines | ( | string const & | s, | |
stringlist_t * | l, | |||
unsigned | at_most | |||
) | [static] |
static int parse_lines | ( | string const & | s, | |
stringlist_t * | l | |||
) | [static] |
static int parse_words | ( | string const & | s, | |
stringlist_t * | l, | |||
unsigned | at_most | |||
) | [static] |
static int parse_words | ( | string const & | s, | |
stringlist_t * | l | |||
) | [static] |
static int parse_words | ( | string const & | s, | |
stringlist_t * | l, | |||
unsigned | at_most, | |||
IsSeparator const & | is_space | |||
) | [static] |
Parses a string, which is assumed to be collection of words separated by spaces. The parsed words are stored in a list and the count of words is returned. You can specify a maximum limit of words to store in the list -- the default is to store them all -- well 2 billion anyway. If the maximum limit is reached, all unparsed text is left in the last item in the list -- leading spaces will be removed from it, however. That is, this function works much like the bourne shell 'read' command that reads words from a a file and stores them in environment variables. In this case, the parsed words are stored in a list of strings.
The parameters are as follows:
s | the string to be parsed | |
l | a pointer to the list in which the parsed words will go |
at_most | the maximum number of elements to be parsed into the list, see note above about how unparsed text is handled. | |
is_space | a functor describing how to tell if a character is a 'space' or not. To make your own definitions, use StrTool::Is_Space as an example. |
Definition at line 210 of file strtool.h.
void remove_leading | ( | std::string & | s, | |
char | space = ' ' | |||
) | [static] |
Remove all leading copies of space from the specified string.
Definition at line 189 of file strtool.cxx.
bool snatch_file_info | ( | std::string const & | s, | |
std::string & | file, | |||
int & | line | |||
) | [static] |
Snatch file information out of a string and return it in file and line.
The input string is assumed to be one of the following formats:
[in] | s | The string containing the source information |
[out] | file | The output file name, if any. |
[out] | line | The output line number if any |
Definition at line 208 of file strtool.cxx.
static size_t splitOnString | ( | std::string const & | s, | |
std::vector< std::string > & | output, | |||
std::string const & | sep | |||
) | [static] |