47 std::string &
trim(std::string &str)
49 size_t pos = str.find_last_not_of(
' ');
50 if (pos != std::string::npos)
53 pos = str.find_first_not_of(
' ');
55 if (pos != std::string::npos)
68 std::transform(str.begin(), str.end(), str.begin(), &tolower);
74 std::transform(str.begin(), str.end(), str.begin(), &toupper);
78 unsigned int atox(
const std::string &str)
80 unsigned int value = 0;
81 if (sscanf(str.c_str(),
"0x%06x", &value) != 0)
88 static char asciiIP[18];
90 snprintf(asciiIP,
sizeof(asciiIP),
"%i.%i.%i.%i",
104 va_start(args, format);
105 size_t nb = vsnprintf(buf, 256, format, args);
113 char *buf2 =
new char[nb];
114 va_start(args, format);
115 vsnprintf(buf2, nb, format, args);
117 std::string res(buf2);
124 for (
unsigned int f = 0; f <
msg.length() - 2 &&
msg.length() > 2; f++)
126 while (
msg.length() > f + 2 &&
msg.at(f) ==
'#'
127 &&
msg.at(f + 1) ==
'#')
137 std::string::const_iterator itA = a.begin();
138 const std::string::const_iterator endA = a.end();
139 std::string::const_iterator itB = b.begin();
140 const std::string::const_iterator endB = b.end();
142 for (; itA < endA && itB < endB; ++itA, ++itB)
144 const int comp = tolower(*itA) - tolower(*itB);
150 if (itA == endA && itB == endB)
152 else if (itA == endA)
161 const int minLength = str1.length() > str2.length()
163 for (
int f = 0; f < minLength; f ++)
165 if (str1.at(f) != str2.at(f))
166 return str1.substr(0, f);
168 return str1.substr(0, minLength);
174 std::string str1 = s1;
175 std::string str2 = s2;
179 const size_t minLength = str1.length() > str2.length()
180 ? str2.length() : str1.length();
181 for (
size_t f = 0; f < minLength; f ++)
183 if (str1.at(f) != str2.at(f))
184 return s1.substr(0, f);
186 return s1.substr(0, minLength);
189 size_t findI(std::string str, std::string subStr)
193 return str.find(subStr);
201 std::string subStr = *i;
203 const size_t idx = text.find(subStr);
204 if (idx != std::string::npos)
207 return std::string::npos;
214 size_t idx = std::string::npos;
215 const size_t sz = chars.size();
216 for (
size_t f = 0; f < sz; f ++)
218 const size_t idx2 = text.find(chars[f], pos);
219 if (idx2 != std::string::npos && idx2 < idx)
242 while (buf.length() <
size)
253 int res = str[0] -
start;
255 for (
size_t f = 1; f < str.length(); f ++)
258 res = res + (str[f] -
start) * mult;
265 const size_t pos1 = str.rfind(
'.');
266 if (pos1 != std::string::npos)
268 size_t pos2 = str.rfind(
'/');
269 const size_t pos3 = str.rfind(
'\\');
270 if (pos3 != std::string::npos)
272 if (pos2 == std::string::npos || pos3 > pos2)
275 if (pos2 == std::string::npos)
280 str = str.substr(pos2 + 1,
size);
287 const size_t pos1 = str.rfind(
'[');
289 if (pos1 != std::string::npos)
291 size_t pos2 = str.rfind(
'/');
292 const size_t pos3 = str.rfind(
'\\');
293 if (pos3 != std::string::npos)
295 if (pos2 == std::string::npos || pos3 > pos2)
298 if (pos2 == std::string::npos)
303 str = str.substr(pos2 + 1,
size);
310 const size_t sz = text.size();
312 char *
const buf =
new char[
size];
313 memcpy(buf, text.c_str(), sz);
322 const size_t sz = text.size();
326 text = text.substr(0, 65500);
327 const size_t sz1 = text.size();
328 memcpy(buf, text.c_str(), sz1);
333 memcpy(buf, text.c_str(), sz);
340 size_t pos1 = path.rfind(
'/');
341 const size_t pos2 = path.rfind(
'\\');
342 if (pos1 == std::string::npos ||
343 (pos2 != std::string::npos && pos2 > pos1))
348 if (pos1 == std::string::npos)
350 return path.substr(pos1 + 1);
355 size_t pos1 = path.rfind(
'/');
356 const size_t pos2 = path.rfind(
'\\');
357 if (pos1 == std::string::npos ||
358 (pos2 != std::string::npos && pos2 > pos1))
363 if (pos1 == std::string::npos)
365 return path.substr(0, pos1);
376 const size_t fromSize = from.size();
377 const size_t toSize = to.size();
378 while ((foundHere = context.find(from, lookHere)) != std::string::npos)
380 context.replace(foundHere, fromSize, to);
381 lookHere = foundHere + toSize;
392 const size_t fromSize = from.size();
393 while ((foundHere = context.find(from, lookHere)) != std::string::npos)
395 context.replace(foundHere, fromSize, 1, to);
396 lookHere = foundHere;
402 std::string txt = text;
404 if (txt ==
"true" || txt ==
"yes" || txt ==
"on" || txt ==
"1")
406 else if (txt ==
"false" || txt ==
"no" || txt ==
"off" || txt ==
"0")
409 return static_cast<bool>(atoi(txt.c_str()));
414 size_t pos1 = text.find(
'&');
415 while (pos1 != std::string::npos)
417 const size_t idx = pos1 + 1;
418 const size_t sz = text.size();
423 for (f = idx; f < sz; f ++)
425 if (text[f] <
'0' || text[f] >
'9')
428 if (idx + 1 < f && text[f] ==
';')
430 std::string str(
" ");
431 str[0] =
CAST_S8(atoi(text.substr(
432 idx, f - idx).c_str()));
433 text = text.substr(0, pos1).append(str).append(text.substr(f + 1));
441 pos1 = text.find(
'&', pos1);
447 std::string normalized = name;
452 const std::string &text,
453 const char separator)
455 std::stringstream ss(text);
457 while (std::getline(ss, item, separator))
458 tokens.insert(atoi(item.c_str()));
462 const char separator)
464 std::list<int> tokens;
465 std::stringstream ss(text);
467 while (std::getline(ss, item, separator))
468 tokens.push_back(atoi(item.c_str()));
474 const char separator)
476 std::list<std::string> tokens;
477 std::stringstream ss(text);
479 while (std::getline(ss, item, separator))
480 tokens.push_back(item);
486 const std::string &text,
487 const char separator)
489 std::stringstream ss(text);
491 while (std::getline(ss, item, separator))
495 tokens.push_back(item);
500 const std::string &text,
501 const char separator)
503 std::stringstream ss(text);
505 while (std::getline(ss, item, separator))
514 const std::string &text,
515 const char separator)
517 std::stringstream ss(text);
519 while (std::getline(ss, item, separator))
523 tokens.push_back(atoi(item.c_str()));
528 const std::string &dye)
532 const size_t pos = file.find_last_of(
'|');
533 if (pos != std::string::npos)
534 return file.substr(0, pos).append(
"|").append(dye);
535 return file.append(
"|").append(dye);
539 const std::string &dye)
544 const size_t pos = file.find_last_of(
'|');
545 if (pos != std::string::npos)
547 const std::string dye1 = file.substr(pos + 1);
549 file = file.substr(0, pos);
552 for (std::list<std::string>::const_iterator it1 = list1.begin(),
553 it2 = list2.begin(), it1_end = list1.end(), it2_end = list2.end();
554 it1 != it1_end && it2 != it2_end; ++it1, ++it2)
556 str.append(*it1).append(
":").append(*it2).append(
";");
558 return file.append(
"|").append(str);
564 const std::string &dye)
569 const size_t pos = file.find_last_of(
'|');
570 if (pos != std::string::npos)
572 const std::string dye1 = file.substr(pos + 1);
574 file = file.substr(0, pos);
577 for (std::list<std::string>::const_iterator it1 = list1.begin(),
578 it2 = list2.begin(), it1_end = list1.end(), it2_end = list2.end();
579 it1 != it1_end && it2 != it2_end; ++it1, ++it2)
581 str.append(*it1).append(
":").append(*it2).append(
";");
583 return file.append(
"|").append(str);
587 return file.append(
"|").append(dye);
590 std::string
packList(
const std::list<std::string> &list)
592 std::list<std::string>::const_iterator i = list.begin();
594 while (i != list.end())
596 str.append(*i).append(
"|");
599 const size_t sz = str.size();
601 str = str.substr(0, sz - 1);
616 for (
unsigned f = 1, fsz =
CAST_U32(str.size());
633 const int v = str[*pos];
635 if ((v & 192) != 128)
643 const size_t s1 = str1.size();
644 const size_t s2 = str2.size();
647 if (str1.substr(s1 - s2) == str2)
655 const size_t s1 = str1.size();
656 const size_t s2 = str2.size();
659 if (str1.substr(0, s2) == str2)
667 const size_t s1 = str1.size();
668 const size_t s2 = str2.size();
671 if (str1.substr(s1 - s2) == str2)
673 str1 = str1.substr(0, s1 - s2);
682 const size_t s1 = str1.size();
683 const size_t s2 = str2.size();
686 if (str1.substr(s1 - s2) == str2)
687 str1 = str1.substr(0, s1 - s2);
693 const size_t s1 = str1.size();
694 const size_t s2 = str2.size();
697 if (str1.substr(0, s2) == str2)
699 str1 = str1.substr(s2);
708 const size_t s1 = str1.size();
709 const size_t s2 = str2.size();
712 if (str1.substr(0, s2) == str2)
713 str1 = str1.substr(s2);
718 const size_t i =
url.find(
"://");
719 if (i != std::string::npos)
727 const size_t sz2 = str2.size();
728 if (str1.size() < sz2)
730 return str1.substr(0, sz2) == str2;
738 const tm *
const timeinfo = localtime(&rawtime);
740 strftime(buffer, 79,
"%Y-%m-%d", timeinfo);
741 return std::string(buffer);
749 const tm *
const timeinfo = localtime(&rawtime);
751 strftime(buffer, 79,
"%Y-%m-%d %H:%M:%S", timeinfo);
752 return std::string(buffer);
757 std::string txt = value;
759 if (txt ==
"true" || txt ==
"yes" || txt ==
"on" || txt ==
"1")
761 else if (txt ==
"false" || txt ==
"no" || txt ==
"off" || txt ==
"0")
779 static char str[100];
780 snprintf(str,
sizeof(str),
"%u 0x%x", val, val);
791 buf[idx--] =
CAST_8((num % 10) +
'0');
792 while ((num /= 10) != 0);
793 return buf + idx + 1;
802 buf[idx--] =
CAST_8((num % 10) +
'0');
803 while ((num /= 10) != 0);
804 return buf + idx + 1;
813 buf[idx--] =
CAST_8((num % 10) +
'0');
814 while ((num /= 10) != 0);
815 return buf + idx + 1;
824 buf[idx--] =
CAST_8((num % 10) +
'0');
825 while ((num /= 10) != 0);
826 return buf + idx + 1;
842 buf[idx--] =
CAST_8((num % 10) +
'0');
843 while ((num /= 10) != 0);
846 return buf + idx + 1;
856 return strprintf(
"%f",
static_cast<float>(num));
863 const size_t sz = str.size();
864 for (
size_t f = 0; f < sz; f ++)
866 const char &chr = str[f];
867 if (chr < '0' || chr >
'9')
875 if (str[0] ==
'/' || str[0] ==
'@' || str[0] ==
'#')
883 bool isValid =
false;
884 size_t pos = args.find(
' ');
885 if (pos == std::string::npos)
886 pos = args.find(
',');
887 if (pos != std::string::npos)
889 if (pos + 1 < args.length())
891 x = atoi(args.substr(0, pos).c_str());
892 y = atoi(args.substr(pos + 1, args.length()).c_str());
903 bool isValid =
false;
904 size_t pos = args.find(
' ');
905 if (pos == std::string::npos)
906 pos = args.find(
',');
907 if (pos != std::string::npos)
909 if (pos + 1 < args.length())
911 str1 = args.substr(0, pos);
912 str2 = args.substr(pos + 1, args.length());
925 else if (str[0] ==
'h' || str[0] ==
'x')
928 sscanf(str.substr(idx).c_str(),
"%10x", &i);
930 i = atoi(str.c_str());
935 const std::string &token)
937 const size_t idx = str.find(token);
938 if (idx > 0 && idx != std::string::npos)
939 str = str.substr(idx + 1);
948 const time_t tempTime = time;
949 tm *
const timeInfo = localtime(&tempTime);
950 if (strftime(&buf[0], 100,
"%Y-%m-%d_%H-%M-%S", timeInfo) != 0U)
951 return std::string(buf);
959 const int weeks = timeDiff / 60 / 60 / 24 / 7;
965 timeDiff -= weeks * 60 * 60 * 24 * 7;
968 const int days = timeDiff / 60 / 60 / 24;
976 timeDiff -= days * 60 * 60 * 24;
978 const int hours = timeDiff / 60 / 60;
986 timeDiff -= hours * 60 * 60;
988 const int min = timeDiff / 60;
994 str.append(
strprintf(ngettext(
N_(
"%d minute"),
N_(
"%d minutes"),
996 timeDiff -= min * 60;
1004 str.append(
strprintf(ngettext(
N_(
"%d second"),
N_(
"%d seconds"),
1005 timeDiff), timeDiff));
1010 str.append(
strprintf(ngettext(
N_(
"%d second"),
N_(
"%d seconds"),
1019 return "\"" + str +
"\"";
1025 const char sepStr =
'\\';
1026 const std::string sep2Str =
"\\\\";
1027 const std::string sepWrongStr =
"/";
1029 const char sepStr =
'/';
1030 const std::string sep2Str =
"//";
1031 const std::string sepWrongStr =
"\\";
1038 const std::string &str2)
1041 const char sep =
'\\';
1042 std::string sepStr =
"\\";
1044 const char sep =
'/';
1045 std::string sepStr =
"/";
1052 return sepStr.append(str2);
1054 const size_t sz1 = str1.size();
1057 if (str1[sz1 - 1] == sep)
1059 return str1.append(sepStr);
1061 if (str1[sz1 - 1] == sep)
1064 return str1.append(str2.substr(1));
1065 return str1.append(str2);
1070 return str1.append(str2);
1071 return str1.append(sepStr).append(str2);
1076 const std::string &str2,
1077 const std::string &str3)
1080 const char sep =
'\\';
1081 std::string sepStr =
"\\";
1083 const char sep =
'/';
1084 std::string sepStr =
"/";
1091 size_t sz1 = str1.size();
1100 if (str1[sz1 - 1] == sep)
1103 str1.append(str2.substr(1));
1112 str1.append(sepStr).append(str2);
1116 if (str1[sz1 - 1] == sep)
1119 return str1.append(str3.substr(1));
1120 return str1.append(str3);
1125 return str1.append(str3);
1126 return str1.append(sepStr).append(str3);
1131 const std::string &str2)
1133 const char sep =
'/';
1134 std::string sepStr =
"/";
1140 return sepStr.append(str2);
1142 const size_t sz1 = str1.size();
1145 if (str1[sz1 - 1] == sep)
1147 return str1.append(sepStr);
1149 if (str1[sz1 - 1] == sep)
1152 return str1.append(str2.substr(1));
1153 return str1.append(str2);
1158 return str1.append(str2);
1159 return str1.append(sepStr).append(str2);
1165 const size_t idx1 = str1.rfind(
'/');
1166 const size_t idx2 = str1.rfind(
'\\');
1167 if (idx1 != std::string::npos)
1169 if (idx2 != std::string::npos)
1183 if (idx2 != std::string::npos)
1189 return std::string::npos;
1198 size_t start2 =
msg.find(
'[');
1199 size_t sz =
msg.size();
1200 while (start2 + 1 < sz &&
1201 start2 != std::string::npos &&
1202 msg[start2 + 1] !=
'@')
1204 const size_t end =
msg.find(
']', start2);
1205 if (start2 + 1 != end &&
1206 end != std::string::npos)
1210 while ((
msg.find(
'[', start2 + 1) != std::string::npos) &&
1211 (
msg.find(
'[', start2 + 1) < end))
1213 start2 =
msg.find(
'[', start2 + 1);
1216 if (start2 + 1 < sz &&
1220 std::string itemStr =
msg.substr(start2 + 1, end - start2 - 1);
1228 const int itemId =
itemInfo.getId();
1231 std::string temp =
strprintf(
"@@%d", itemId);
1232 std::string name = parts[0];
1233 msg.erase(start2 + 1, end - start2 - 1);
1234 parts.erase(parts.begin());
1240 std:: string str = *it;
1243 const int cardId = itemInfo2.
getId();
1250 msg.insert(start2 + 1, temp);
1255 start2 =
msg.find(
'[', start2 + 1);
#define FOR_EACH(type, iter, array)
bool msg(InputEvent &event)
bool itemInfo(InputEvent &event)
bool url(InputEvent &event)
const ItemInfo & get(const int id)
std::string toString(uint32_t num)
std::string removeColors(std::string msg)
void sanitizePath(std::string &path)
std::string packList(const std::list< std::string > &list)
void cutFirst(std::string &str1, const std::string &str2)
std::string combineDye3(std::string file, const std::string &dye)
std::string & toUpper(std::string &str)
std::string removeSpriteIndex(std::string str)
std::string getFileName(const std::string &path)
unsigned int atox(const std::string &str)
std::list< std::string > splitToStringList(const std::string &text, const char separator)
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)
void deleteCharLeft(std::string &str, unsigned *const pos)
void cutLast(std::string &str1, const std::string &str2)
std::string combineDye(std::string file, const std::string &dye)
void splitToIntVector(std::vector< int > &tokens, const std::string &text, const char separator)
bool parse2Int(const std::string &args, int &x, int &y)
std::string stringToHexPath(const std::string &str)
std::string & removeProtocol(std::string &url)
std::string toStringPrint(const unsigned int val)
std::string strprintf(const char *const format,...)
std::string getDateTimeString()
bool parse2Str(const std::string &args, std::string &str1, std::string &str2)
std::string & toLower(std::string &str)
std::string removeToken(std::string &str, const std::string &token)
void splitToStringVector(StringVect &tokens, const std::string &text, const char separator)
int compareStrI(const std::string &a, const std::string &b)
std::string timeDiffToString(int timeDiff)
std::string getFileDir(const std::string &path)
std::string escapeString(std::string str)
void replaceRecursiveAll(std::string &context, const std::string &from, const char to)
unsigned int decodeStr(const std::string &str)
bool findCutFirst(std::string &str1, const std::string &str2)
void splitToIntSet(std::set< int > &tokens, const std::string &text, const char separator)
size_t findI(std::string str, std::string subStr)
bool getBoolFromString(const std::string &text)
void replaceItemLinks(std::string &msg)
void splitToStringSet(std::set< std::string > &tokens, const std::string &text, const char separator)
bool findLast(const std::string &str1, const std::string &str2)
std::string decodeLinkText(std::string data)
signed char parseBoolean(const std::string &value)
size_t rfindSepatator(const std::string &str1)
std::string timeToStr(const uint32_t time)
bool findCutLast(std::string &str1, const std::string &str2)
std::string combineDye2(std::string file, const std::string &dye)
const char * getSafeUtf8String(const std::string &text)
std::string pathJoin(std::string str1, const std::string &str2)
size_t findAny(const std::string &text, const std::string &chars, const size_t pos)
std::string urlJoin(std::string str1, const std::string &str2)
const std::string encodeStr(unsigned int value, const unsigned int size)
bool isDigit(const std::string &str)
std::string normalize(const std::string &name)
std::list< int > splitToIntList(const std::string &text, const char separator)
void secureChatCommand(std::string &str)
std::string extractNameFromSprite(std::string str)
void replaceSpecialChars(std::string &text)
bool strStartWith(const std::string &str1, const std::string &str2)
const char * ipToString(const uint32_t address)
const std::string findSameSubstring(const std::string &str1, const std::string &str2)
uint32_t parseNumber(const std::string &str)
std::string encodeLinkText(std::string data)
std::string getDateString()
const std::string findSameSubstringI(const std::string &s1, const std::string &s2)
bool findFirst(const std::string &str1, const std::string &str2)
std::string & trim(std::string &str)
std::list< std::string > unpackList(const std::string &str)
StringVect::const_iterator StringVectCIter
std::vector< std::string > StringVect
static const size_t UTF8_MAX_SIZE