core/vul/vul_string.h
Go to the documentation of this file.
00001 // This is core/vul/vul_string.h
00002 #ifndef vul_string_h
00003 #define vul_string_h
00004 //:
00005 // \file
00006 // \brief Utility functions for C strings and vcl_strings
00007 
00008 #include <vcl_string.h>
00009 #include <vcl_vector.h>
00010 
00011 // C string functions:
00012 
00013 //: Converts all alphabetical characters to uppercase.
00014 extern char* vul_string_c_upcase(char*);
00015 //: Converts all alphabetical characters to lowercase.
00016 extern char* vul_string_c_downcase(char*);
00017 //: Capitalizes all words in a string.
00018 // A word is defined as a sequence of characters separated by
00019 // non-alphanumerics.
00020 extern char* vul_string_c_capitalize(char*);
00021 //: Removes any occurrences of rem from str, and returns the modified string.
00022 extern char* vul_string_c_trim(char* str, const char* rem);
00023 //: Removes any prefix occurrence of rem from str and returns modified string.
00024 extern char* vul_string_c_left_trim(char* str, const char* rem);
00025 //: Removes any suffix occurrence of rem from str and returns modified string.
00026 extern char* vul_string_c_right_trim(char* str, const char* rem);
00027 //: Reverses the order of the characters in string.
00028 extern char* vul_string_c_reverse(char*);
00029 
00030 // vcl_string functions:
00031 
00032 //: Converts all alphabetical characters to uppercase.
00033 extern vcl_string& vul_string_upcase(vcl_string&);
00034 //: Converts all alphabetical characters to lowercase.
00035 extern vcl_string& vul_string_downcase(vcl_string&);
00036 //: Capitalizes all words in string.
00037 extern vcl_string& vul_string_capitalize(vcl_string&);
00038 //: Removes any occurrences of rem from str and returns modified string
00039 extern vcl_string& vul_string_trim(vcl_string&, const char*);
00040 //: Removes any prefix occurrence of rem from str and returns modified string
00041 extern vcl_string& vul_string_left_trim(vcl_string&, const char*);
00042 //: Removes any suffix occurrence of rem from str and returns modified string
00043 extern vcl_string& vul_string_right_trim(vcl_string&, const char*);
00044 //: Reverses the order of the characters in string
00045 extern vcl_string& vul_string_reverse(vcl_string&);
00046 
00047 //: Reads an integer from a string
00048 extern int vul_string_atoi(vcl_string const&);
00049 
00050 //: Reads a double from a string
00051 extern double vul_string_atof(vcl_string const& s);
00052 
00053 //: Reads a double from a string, with k, kb, M, etc suffix.
00054 // No space is allowed between the number and the suffix.
00055 // k=10^3, ki=2^10, M=10^6, Mi=2^20, G=10^9, Gi=2^30, T=10^12, Ti=2^40
00056 // The i suffix is from the IEC 60027 standard.
00057 extern double vul_string_atof_withsuffix(vcl_string const& s);
00058 
00059 //: Convert a string to a boolean.
00060 // Looks for On, true, yes, 1 to mean true. everything else is false.
00061 // It ignores leading and trailing whitespace and capitalisation.
00062 extern bool vul_string_to_bool(const vcl_string &str);
00063 
00064 //: Convert a string to a list of ints.
00065 extern vcl_vector<int> vul_string_to_int_list(vcl_string str);
00066 
00067 //: Expand any environment variables in the string.
00068 // \verbatim
00069 // Expands "foo$VARfoo" to "foobarfoo" when $VAR=bar. If
00070 // both $VAR and $VARfoo exists, an arbitrary choice will
00071 // be made of which variable to use. This problem can
00072 // be avoided by using the syntax "foo${VAR}foo." "$(VAR)" and
00073 // "$[VAR]" can also be used. There are no inbuilt variables
00074 // like in shell scripting. "$$" can be used to insert a
00075 // literal "$" in to the output.
00076 // \endverbatim
00077 // \returns false if a matching variable could not be found.
00078 extern bool vul_string_expand_var(vcl_string &str);
00079 
00080 //: replaces instances "find_str" in "full_str" with "replace_str" a given "num_times" (default 1000).
00081 //  \returns true iff at least one replacement took place.
00082 extern bool vul_string_replace( vcl_string& full_str,
00083                                 const vcl_string& find_str,
00084                                 const vcl_string& replace_str,
00085                                 int num_times=1000);
00086 
00087 //: Replace control chars with escaped representations.
00088 // Space and \n are preserved, but tabs, CR, etc are escaped.
00089 // This is not aimed and is not suitable for any particular input-validation
00090 // security problem, such as sql-injection.
00091 vcl_string vul_string_escape_ctrl_chars(const vcl_string &in);
00092 
00093 
00094 #endif // vul_string_h