00001
00002
00003 #ifndef STRINGUTIL_H
00004 #define STRINGUTIL_H
00005
00006 #include <string>
00007 #include <algorithm>
00008 #include <functional>
00009 #include <cctype>
00010 #include <locale>
00011
00012 namespace Yosokumo
00013 {
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 static inline std::string <rim(std::string &s)
00034 {
00035 s.erase(s.begin(), std::find_if(s.begin(), s.end(),
00036 std::not1(std::ptr_fun<int, int>(std::isspace))));
00037 return s;
00038 }
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 static inline std::string &rtrim(std::string &s)
00049 {
00050 s.erase(std::find_if(s.rbegin(), s.rend(),
00051 std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
00052 return s;
00053 }
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 static inline std::string &trim(std::string &s)
00065 {
00066 return ltrim(rtrim(s));
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 static inline bool endsWith(
00079 const std::string &fullString,
00080 const std::string &ending)
00081 {
00082 if (fullString.length() < ending.length())
00083 return false;
00084
00085 return (fullString.compare(fullString.length() - ending.length(),
00086 ending.length(), ending) == 0);
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 static inline bool startsWith(
00099 const std::string &fullString,
00100 const std::string &start)
00101 {
00102 return start.length() <= fullString.length()
00103 && equal(start.begin(), start.end(), fullString.begin());
00104 }
00105
00106 }
00107
00108 #endif // STRINGUTIL_H
00109
00110