00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "utils/stringutils.h"
00023
00024 #include <algorithm>
00025
00026 std::string &trim(std::string &str)
00027 {
00028 std::string::size_type pos = str.find_last_not_of(' ');
00029 if (pos != std::string::npos)
00030 {
00031 str.erase(pos + 1);
00032 pos = str.find_first_not_of(' ');
00033 if (pos != std::string::npos)
00034 {
00035 str.erase(0, pos);
00036 }
00037 }
00038 else
00039 {
00040
00041 str.clear();
00042 }
00043 return str;
00044 }
00045
00046 std::string &toLower(std::string &str)
00047 {
00048 std::transform(str.begin(), str.end(), str.begin(), tolower);
00049 return str;
00050 }
00051
00052 const char *ipToString(int address)
00053 {
00054 static char asciiIP[16];
00055
00056 sprintf(asciiIP, "%i.%i.%i.%i",
00057 (unsigned char)(address),
00058 (unsigned char)(address >> 8),
00059 (unsigned char)(address >> 16),
00060 (unsigned char)(address >> 24));
00061
00062 return asciiIP;
00063 }
00064
00065 std::string &removeBadChars(std::string &str)
00066 {
00067 std::string::size_type pos;
00068 do
00069 {
00070 pos = str.find_first_of("@#[]");
00071 if (pos != std::string::npos)
00072 str.erase(pos, 1);
00073 } while (pos != std::string::npos);
00074
00075 return str;
00076 }