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