Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
string_util.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_string_util_h 00003 #define INCLUDED_string_util_h 00004 00005 #include "attributes.h" 00006 #include <string> 00007 #include <vector> 00008 00009 //! some common string processing functions, for std::string 00010 namespace string_util { 00011 //! uses the standard library's "locale" to convert case of a single character 00012 char localeToUpper(char c); 00013 00014 //! uses the standard library's "locale" to convert case of a single character 00015 char localeToLower(char c); 00016 00017 //! returns lower case version of @a s 00018 std::string makeLower(const std::string& s) ATTR_must_check; 00019 00020 //! returns upper case version of @a s 00021 std::string makeUpper(const std::string& s) ATTR_must_check; 00022 00023 //! returns @a str with @a pre removed - if @a pre is not fully matched, @a str is returned unchanged 00024 std::string removePrefix(const std::string& str, const std::string& pre) ATTR_must_check; 00025 00026 //! removes whitespace (as defined by isspace()) from the beginning and end of @a str, and returns the result 00027 std::string trim(const std::string& str) ATTR_must_check; 00028 00029 //! returns true if @a str begins with @a prefix 00030 bool beginsWith(const std::string& str, const std::string& prefix); 00031 00032 //! returns true if @a str ends with @a suffix 00033 bool endsWith(const std::string& str, const std::string& suffix); 00034 00035 //! Returns @a tgt if it is an absolute path or @a rel is empty, otherwise drops trailing file (if any) from @a rel and appends @a tgt 00036 /*! This assumes final path component is a source file, referencing a self-relative path, 00037 * so make sure @a rel is a path to a file, or has a trailing '/' otherwise the final directory 00038 * component will be stripped. (Doesn't actually do any disk operations to test for the file.) */ 00039 std::string makePath(const std::string& rel, const std::string& path); 00040 00041 //! convert input string into vector of string tokens 00042 /*! @param input string to be parsed 00043 * @param delims list of delimiters. 00044 * 00045 * Consecutive delimiters will be treated as single delimiter, 00046 * delimiters are @e not included in return data. 00047 * Thanks http://www.rosettacode.org/wiki/Tokenizing_A_String#C.2B.2B */ 00048 std::vector<std::string> tokenize(const std::string & str, const std::string & delims=", \t"); 00049 00050 //! parses the input string into an arg list, with corresponding offsets of each arg in the original input 00051 bool parseArgs(const std::string& input, std::vector<std::string>& args, std::vector<unsigned int>& offsets); 00052 00053 //! replaces ~USER prefix with specified user's home directory, or ~ prefix with current HOME environment setting; returns str if no valid expansion is found 00054 std::string tildeExpansion(const std::string& str) ATTR_must_check; 00055 00056 //! returns true if @a str matches @a re (assumes 'extended' regular expression, not 'basic'), false otherwise and throws std::string message on error 00057 /*! @param str The string to match 00058 * @param regex The (extended) regular expression which should be parsed and executed 00059 * 00060 * This compiles the @a regex and then executes it... for repeated usage of the same 00061 * regular expression, you could be better off compiling it yourself and using the regex library directly. */ 00062 bool reMatch(const std::string& str, const std::string& regex); 00063 00064 //! returns true if @a str matches @a re (with optional @a flags to control interpretation), false otherwise and throws std::string message on error 00065 /*! @param str The string to match 00066 * @param regex The regular expression which should be parsed and executed 00067 * @param flags pass flags for regex (e.g. REG_EXTENDED) 00068 * 00069 * This compiles the @a regex and then executes it... for repeated usage of the same 00070 * regular expression, you could be better off compiling it yourself and using the regex library directly. */ 00071 bool reMatch(const std::string& str, const std::string& regex, int flags); 00072 00073 //! Converts a int representation of an IP to a string 00074 std::string intToStringIP(int ip); 00075 //! Converts a string representation of an IP to an int 00076 int stringToIntIP(std::string ip); 00077 00078 //! returns the number of utf8 code points found in the string 00079 /*! This does not do any verification of the validity of the codepoints. */ 00080 size_t utf8len(const std::string& str); 00081 00082 //! returns demangled version of a symbol name 00083 std::string demangle(const std::string& symbol); 00084 00085 //! convert int to string so robot can speak numbers 00086 std::string int2str(int const n); 00087 }; 00088 00089 /*! @file 00090 * @brief Describes some useful functions for string manipulation in the string_util namespace 00091 * @author ejt (Creator) 00092 */ 00093 00094 #endif |
Tekkotsu v5.1CVS |
Generated Mon May 9 04:58:51 2016 by Doxygen 1.6.3 |