00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <algorithm>
00026 #include <string>
00027 #include <vector>
00028
00029 #include <boost/algorithm/string.hpp>
00030
00031 #include "WStringUtils.h"
00032
00033 const std::string string_utils::WHITESPACE( "\r\n\t " );
00034
00035 std::string string_utils::rTrim( const std::string &source, const std::string& t )
00036 {
00037 std::string str = source;
00038 str.erase( str.find_last_not_of( t ) + 1 );
00039 return str;
00040 }
00041
00042 std::string string_utils::lTrim( const std::string& source, const std::string& t )
00043 {
00044 std::string str = source;
00045 str.erase( 0 , source.find_first_not_of( t ) );
00046 return str;
00047 }
00048
00049 std::string string_utils::trim( const std::string& source, const std::string& t )
00050 {
00051 std::string str = source;
00052 return lTrim( rTrim( str , t) , t );
00053 }
00054
00055 std::string string_utils::toUpper( const std::string& source )
00056 {
00057 std::string str = source;
00058 std::transform( source.begin(), source.end(), str.begin(), ::toupper );
00059 return str;
00060 }
00061
00062 std::string string_utils::toLower( const std::string& source )
00063 {
00064 std::string str = source;
00065 std::transform( source.begin(), source.end(), str.begin(), ::tolower );
00066 return str;
00067 }
00068
00069 std::vector< std::string > string_utils::tokenize( const std::string& source,
00070 const std::string& delim,
00071 bool compress )
00072 {
00073 std::vector< std::string > result;
00074 namespace ba = boost::algorithm;
00075 ba::token_compress_mode_type compression = ba::token_compress_on;
00076 if( !compress )
00077 {
00078 compression = ba::token_compress_off;
00079 }
00080 ba::split( result, source, ba::is_any_of( delim ), compression );
00081 if( !result.empty() )
00082 {
00083
00084
00085
00086 if( result.back() == "" )
00087 {
00088 result.pop_back();
00089 }
00090 }
00091 return result;
00092 }