00001 #ifndef STRING_UTIL_H 00002 #define STRING_UTIL_H 00003 00004 #include <string> 00005 00006 00007 //!@defgroup string String Utils 00008 //!Helper functions for std::string's 00009 //!@li StringUtil::IsPrefix 00010 //!@li StringUtil::IsSuffix 00011 //!@li StringUtil::ToLower 00012 //!@li StringUtil::Trim 00013 //!@li StringUtil::EncodeToXml 00014 00015 00016 //!@ingroup std::string 00017 namespace StringUtil 00018 { 00019 //!@return true if prefix is a prefix of str, and false if it is not. 00020 bool IsPrefix(const std::string & str, const std::string & prefix); 00021 00022 //!@return true if suffix is a suffix of str, and false if it is not. 00023 bool IsSuffix(const std::string & str, const std::string & suffix); 00024 00025 //!Inplace converts each character in str to lower-case. 00026 void ToLower(std::string & str); 00027 00028 //!Inplace converts each character in substring [start, end) to lower-case. 00029 void ToLower(std::string::iterator start, std::string::iterator end); 00030 00031 00032 //!@return A copy of str in which each character in str is converted to lower-case. 00033 std::string ToLowerCopy (const std::string & str); 00034 00035 //!Inplace converts each character in str which are considered 00036 //!an XML special character (&,<,>,',") will be converted to an XML entity( & -> &amp;). 00037 void EncodeToXml (std::string & str); 00038 00039 //!@return A copy of str in which each character in str which are considered 00040 //!an XML special character (&,<,>,',") will be converted to an XML entity( & -> &amp;). 00041 std::string EncodeToXmlCopy (const std::string & str); 00042 00043 //!Inplace removes all leading and trailing whitespace from str. 00044 void Trim(std::string & str); 00045 00046 //!@return A copy of str which has removed all leading and trailing whitespace. 00047 std::string TrimCopy(const std::string & str); 00048 } 00049 00050 00051 #endif
1.5.8