ManaPlus
Namespaces | Functions | Variables
stringutils.cpp File Reference

(642df39)

#include "utils/stringutils.h"
#include "const/utils/utf8.h"
#include "resources/iteminfo.h"
#include "resources/db/itemdb.h"
#include "utils/gettext.h"
#include "utils/foreach.h"
#include <algorithm>
#include <sstream>
#include "debug.h"

Go to the source code of this file.

Namespaces

 anonymous_namespace{stringutils.cpp}
 

Functions

std::string & trim (std::string &str)
 
std::string & toLower (std::string &str)
 
std::string & toUpper (std::string &str)
 
unsigned int atox (const std::string &str)
 
const char * ipToString (const uint32_t address)
 
std::string strprintf (const char *const format,...)
 
std::string removeColors (std::string msg)
 
int compareStrI (const std::string &a, const std::string &b)
 
const std::string findSameSubstring (const std::string &str1, const std::string &str2)
 
const std::string findSameSubstringI (const std::string &s1, const std::string &s2)
 
size_t findI (std::string str, std::string subStr)
 
size_t findI (std::string text, const StringVect &list)
 
size_t findAny (const std::string &text, const std::string &chars, const size_t pos)
 
const std::string encodeStr (unsigned int value, const unsigned int size)
 
unsigned int decodeStr (const std::string &str)
 
std::string extractNameFromSprite (std::string str)
 
std::string removeSpriteIndex (std::string str)
 
const char * getSafeUtf8String (const std::string &text)
 
void getSafeUtf8String (std::string text, char *const buf)
 
std::string getFileName (const std::string &path)
 
std::string getFileDir (const std::string &path)
 
std::string & replaceAll (std::string &context, const std::string &from, const std::string &to)
 
void replaceRecursiveAll (std::string &context, const std::string &from, const char to)
 
bool getBoolFromString (const std::string &text)
 
void replaceSpecialChars (std::string &text)
 
std::string normalize (const std::string &name)
 
void splitToIntSet (std::set< int > &tokens, const std::string &text, const char separator)
 
std::list< int > splitToIntList (const std::string &text, const char separator)
 
std::list< std::string > splitToStringList (const std::string &text, const char separator)
 
void splitToStringVector (StringVect &tokens, const std::string &text, const char separator)
 
void splitToStringSet (std::set< std::string > &tokens, const std::string &text, const char separator)
 
void splitToIntVector (std::vector< int > &tokens, const std::string &text, const char separator)
 
std::string combineDye (std::string file, const std::string &dye)
 
std::string combineDye2 (std::string file, const std::string &dye)
 
std::string combineDye3 (std::string file, const std::string &dye)
 
std::string packList (const std::list< std::string > &list)
 
std::list< std::string > unpackList (const std::string &str)
 
std::string stringToHexPath (const std::string &str)
 
void deleteCharLeft (std::string &str, unsigned *const pos)
 
bool findLast (const std::string &str1, const std::string &str2)
 
bool findFirst (const std::string &str1, const std::string &str2)
 
bool findCutLast (std::string &str1, const std::string &str2)
 
void cutLast (std::string &str1, const std::string &str2)
 
bool findCutFirst (std::string &str1, const std::string &str2)
 
void cutFirst (std::string &str1, const std::string &str2)
 
std::string & removeProtocol (std::string &url)
 
bool strStartWith (const std::string &str1, const std::string &str2)
 
std::string getDateString ()
 
std::string getDateTimeString ()
 
signed char parseBoolean (const std::string &value)
 
std::string encodeLinkText (std::string data)
 
std::string decodeLinkText (std::string data)
 
std::string toStringPrint (const unsigned int val)
 
std::string toString (uint32_t num)
 
std::string toString (uint64_t num)
 
std::string toString (uint16_t num)
 
std::string toString (unsigned char num)
 
std::string toString (int32_t num)
 
std::string toString (const float num)
 
std::string toString (const double num)
 
bool isDigit (const std::string &str)
 
void secureChatCommand (std::string &str)
 
bool parse2Int (const std::string &args, int &x, int &y)
 
bool parse2Str (const std::string &args, std::string &str1, std::string &str2)
 
uint32_t parseNumber (const std::string &str)
 
std::string removeToken (std::string &str, const std::string &token)
 
std::string timeToStr (const uint32_t time)
 
std::string timeDiffToString (int timeDiff)
 
std::string escapeString (std::string str)
 
void sanitizePath (std::string &path)
 
std::string pathJoin (std::string str1, const std::string &str2)
 
std::string pathJoin (std::string str1, const std::string &str2, const std::string &str3)
 
std::string urlJoin (std::string str1, const std::string &str2)
 
size_t rfindSepatator (const std::string &str1)
 
void replaceItemLinks (std::string &msg)
 

Variables

unsigned int anonymous_namespace{stringutils.cpp}::base = 94
 
unsigned int anonymous_namespace{stringutils.cpp}::start = 33
 

Function Documentation

◆ atox()

unsigned int atox ( const std::string &  str)

Converts an ascii hexidecimal string to an integer

Parameters
strthe hex string to convert to an int
Returns
the integer representation of the hex string

Definition at line 77 of file stringutils.cpp.

78 {
79  unsigned int value = 0;
80  if (sscanf(str.c_str(), "0x%06x", &value) != 0)
81  return value;
82  return 0;
83 }

Referenced by UserPalette::addColor().

◆ combineDye()

std::string combineDye ( std::string  file,
const std::string &  dye 
)

Definition at line 526 of file stringutils.cpp.

528 {
529  if (dye.empty())
530  return file;
531  const size_t pos = file.find_last_of('|');
532  if (pos != std::string::npos)
533  return file.substr(0, pos).append("|").append(dye);
534  return file.append("|").append(dye);
535 }

Referenced by Being::setGender(), Being::setHairTempSprite(), Being::setSpriteCards(), Being::setSpriteColor(), Being::setSpriteColorId(), and Being::setTempSprite().

◆ combineDye2()

std::string combineDye2 ( std::string  file,
const std::string &  dye 
)

Definition at line 537 of file stringutils.cpp.

539 {
540  if (dye.empty())
541  return file;
542 
543  const size_t pos = file.find_last_of('|');
544  if (pos != std::string::npos)
545  {
546  const std::string dye1 = file.substr(pos + 1);
547  std::string str;
548  file = file.substr(0, pos);
549  const std::list<std::string> list1 = splitToStringList(dye1, ';');
550  const std::list<std::string> list2 = splitToStringList(dye, ';');
551  for (std::list<std::string>::const_iterator it1 = list1.begin(),
552  it2 = list2.begin(), it1_end = list1.end(), it2_end = list2.end();
553  it1 != it1_end && it2 != it2_end; ++it1, ++it2)
554  {
555  str.append(*it1).append(":").append(*it2).append(";");
556  }
557  return file.append("|").append(str);
558  }
559  return file;
560 }

References splitToStringList().

Referenced by Item::getImage(), Item::setId(), ItemPopup::setItem(), and ActorSprite::setupSpriteDisplay().

◆ combineDye3()

std::string combineDye3 ( std::string  file,
const std::string &  dye 
)

Definition at line 562 of file stringutils.cpp.

564 {
565  if (dye.empty())
566  return file;
567 
568  const size_t pos = file.find_last_of('|');
569  if (pos != std::string::npos)
570  {
571  const std::string dye1 = file.substr(pos + 1);
572  std::string str;
573  file = file.substr(0, pos);
574  const std::list<std::string> list1 = splitToStringList(dye1, ';');
575  const std::list<std::string> list2 = splitToStringList(dye, ';');
576  for (std::list<std::string>::const_iterator it1 = list1.begin(),
577  it2 = list2.begin(), it1_end = list1.end(), it2_end = list2.end();
578  it1 != it1_end && it2 != it2_end; ++it1, ++it2)
579  {
580  str.append(*it1).append(":").append(*it2).append(";");
581  }
582  return file.append("|").append(str);
583  }
584  if (file.empty())
585  return file;
586  return file.append("|").append(dye);
587 }

References splitToStringList().

Referenced by ActorSprite::setupSpriteDisplay().

◆ compareStrI()

int compareStrI ( const std::string &  a,
const std::string &  b 
)

Compares the two strings case-insensitively.

Parameters
athe first string in the comparison
bthe second string in the comparison
Returns
0 if the strings are equal, positive if the first is greater, negative if the second is greater

Definition at line 134 of file stringutils.cpp.

135 {
136  std::string::const_iterator itA = a.begin();
137  const std::string::const_iterator endA = a.end();
138  std::string::const_iterator itB = b.begin();
139  const std::string::const_iterator endB = b.end();
140 
141  for (; itA < endA && itB < endB; ++itA, ++itB)
142  {
143  const int comp = tolower(*itA) - tolower(*itB);
144  if (comp != 0)
145  return comp;
146  }
147 
148  // Check string lengths
149  if (itA == endA && itB == endB)
150  return 0;
151  else if (itA == endA)
152  return -1;
153  else
154  return 1;
155 }

Referenced by ServerDialog::loadServers(), anonymous_namespace{whoisonline.cpp}::NameFunctuator::operator()(), ServerInfo::parseFreeType(), ServerInfo::parseType(), readColorGradient(), readColorType(), and readProgressType().

◆ cutFirst()

void cutFirst ( std::string &  str1,
const std::string &  str2 
)

Definition at line 704 of file stringutils.cpp.

706 {
707  const size_t s1 = str1.size();
708  const size_t s2 = str2.size();
709  if (s1 < s2)
710  return;
711  if (str1.substr(0, s2) == str2)
712  str1 = str1.substr(s2);
713 }

Referenced by Game::saveScreenshot(), and GraphicsManager::setGLVersion().

◆ cutLast()

void cutLast ( std::string &  str1,
const std::string &  str2 
)

Definition at line 678 of file stringutils.cpp.

680 {
681  const size_t s1 = str1.size();
682  const size_t s2 = str2.size();
683  if (s1 < s2)
684  return;
685  if (str1.substr(s1 - s2) == str2)
686  str1 = str1.substr(0, s1 - s2);
687 }

◆ decodeLinkText()

std::string decodeLinkText ( std::string  data)

Definition at line 771 of file stringutils.cpp.

772 {
773  return replaceAll(data, "\342\235\230", "|");
774 }

References data, and replaceAll().

Referenced by WhoIsOnline::handleLink().

◆ decodeStr()

unsigned int decodeStr ( const std::string &  str)

Definition at line 247 of file stringutils.cpp.

248 {
249  if (str.empty())
250  return 0;
251 
252  int res = str[0] - start;
253  int mult = 1;
254  for (size_t f = 1; f < str.length(); f ++)
255  {
256  mult *= base;
257  res = res + (str[f] - start) * mult;
258  }
259  return res;
260 }

References anonymous_namespace{stringutils.cpp}::base, and anonymous_namespace{stringutils.cpp}::start.

Referenced by ShopWindow::showList().

◆ deleteCharLeft()

void deleteCharLeft ( std::string &  str,
unsigned *const  pos 
)

Definition at line 623 of file stringutils.cpp.

625 {
626  if (pos == nullptr)
627  return;
628 
629  while (*pos > 0)
630  {
631  (*pos)--;
632  const int v = str[*pos];
633  str.erase(*pos, 1);
634  if ((v & 192) != 128)
635  break;
636  }
637 }

Referenced by TextField::caretDeleteWord(), TextField::handleCtrlKeys(), and TextField::handleNormalKeys().

◆ encodeLinkText()

std::string encodeLinkText ( std::string  data)

Definition at line 766 of file stringutils.cpp.

767 {
768  return replaceAll(data, "|", "\342\235\230");
769 }

References data, and replaceAll().

Referenced by StaticBrowserBox::addRow(), BrowserBox::addRow(), WhoIsOnline::prepareNick(), and OnlinePlayer::setText().

◆ encodeStr()

const std::string encodeStr ( unsigned int  value,
const unsigned int  size 
)

Definition at line 230 of file stringutils.cpp.

231 {
232  std::string buf;
233 
234  do
235  {
236  buf += CAST_S8(value % base + start);
237  value /= base;
238  }
239  while (value != 0U);
240 
241  while (buf.length() < size)
242  buf += CAST_S8(start);
243  return buf;
244 }

References anonymous_namespace{stringutils.cpp}::base, CAST_S8, EmoteDB::size(), and anonymous_namespace{stringutils.cpp}::start.

Referenced by ShopWindow::giveList(), and ShopWindow::sendMessage().

◆ escapeString()

std::string escapeString ( std::string  str)

Definition at line 1015 of file stringutils.cpp.

1016 {
1017  replaceAll(str, "\"", "\\\"");
1018  return "\"" + str + "\"";
1019 }

References replaceAll().

Referenced by PopupMenu::handleLink().

◆ extractNameFromSprite()

std::string extractNameFromSprite ( std::string  str)

Definition at line 262 of file stringutils.cpp.

263 {
264  const size_t pos1 = str.rfind('.');
265  if (pos1 != std::string::npos)
266  {
267  size_t pos2 = str.rfind('/');
268  const size_t pos3 = str.rfind('\\');
269  if (pos3 != std::string::npos)
270  {
271  if (pos2 == std::string::npos || pos3 > pos2)
272  pos2 = pos3;
273  }
274  if (pos2 == std::string::npos)
275  pos2 = CAST_SIZE(-1);
276 
277  const int size = CAST_S32(pos1) - CAST_S32(pos2) - 1;
278  if (size > 0)
279  str = str.substr(pos2 + 1, size);
280  }
281  return str;
282 }

References CAST_S32, CAST_SIZE, and EmoteDB::size().

Referenced by Inventory::findItemBySprite().

◆ findAny()

size_t findAny ( const std::string &  text,
const std::string &  chars,
const size_t  pos 
)

Definition at line 209 of file stringutils.cpp.

212 {
213  size_t idx = std::string::npos;
214  const size_t sz = chars.size();
215  for (size_t f = 0; f < sz; f ++)
216  {
217  const size_t idx2 = text.find(chars[f], pos);
218  if (idx2 != std::string::npos && idx2 < idx)
219  idx = idx2;
220  }
221  return idx;
222 }

Referenced by findNextSplit().

◆ findCutFirst()

bool findCutFirst ( std::string &  str1,
const std::string &  str2 
)

Definition at line 689 of file stringutils.cpp.

691 {
692  const size_t s1 = str1.size();
693  const size_t s2 = str2.size();
694  if (s1 < s2)
695  return false;
696  if (str1.substr(0, s2) == str2)
697  {
698  str1 = str1.substr(s2);
699  return true;
700  }
701  return false;
702 }

Referenced by VirtFs::FsZip::enumerate(), EAthena::ChatRecv::extractChannelFromMessage(), VirtFs::FsZip::getDirs(), VirtFs::FsZip::getFiles(), VirtFs::FsZip::getFilesWithDir(), getPicturesDir(), GuildManager::process(), EAthena::ChatRecv::processColorChat(), EAthena::ChatRecv::processGmChat(), and GraphicsManager::setGLVersion().

◆ findCutLast()

bool findCutLast ( std::string &  str1,
const std::string &  str2 
)

Definition at line 663 of file stringutils.cpp.

665 {
666  const size_t s1 = str1.size();
667  const size_t s2 = str2.size();
668  if (s1 < s2)
669  return false;
670  if (str1.substr(s1 - s2) == str2)
671  {
672  str1 = str1.substr(0, s1 - s2);
673  return true;
674  }
675  return false;
676 }

Referenced by Theme::fillSoundsList(), Theme::load(), GuildManager::process(), and EAthena::ChatRecv::processColorChat().

◆ findFirst()

bool findFirst ( const std::string &  str1,
const std::string &  str2 
)

Definition at line 651 of file stringutils.cpp.

653 {
654  const size_t s1 = str1.size();
655  const size_t s2 = str2.size();
656  if (s1 < s2)
657  return false;
658  if (str1.substr(0, s2) == str2)
659  return true;
660  return false;
661 }

Referenced by Cpu::detect().

◆ findI() [1/2]

size_t findI ( std::string  str,
std::string  subStr 
)

Definition at line 188 of file stringutils.cpp.

189 {
190  str = toLower(str);
191  subStr = toLower(subStr);
192  return str.find(subStr);
193 }

References toLower().

Referenced by ChatWindow::addGlobalMessage(), ChatWindow::addToAwayLog(), GraphicsManager::detectGraphics(), ChatWindow::findHighlight(), and ChatWindow::resortChatLog().

◆ findI() [2/2]

size_t findI ( std::string  text,
const StringVect list 
)

Definition at line 195 of file stringutils.cpp.

196 {
197  toLower(text);
198  FOR_EACH (StringVectCIter, i, list)
199  {
200  std::string subStr = *i;
201  subStr = toLower(subStr);
202  const size_t idx = text.find(subStr);
203  if (idx != std::string::npos)
204  return idx;
205  }
206  return std::string::npos;
207 }

References FOR_EACH, and toLower().

◆ findLast()

bool findLast ( const std::string &  str1,
const std::string &  str2 
)

◆ findSameSubstring()

const std::string findSameSubstring ( const std::string &  str1,
const std::string &  str2 
)

Definition at line 157 of file stringutils.cpp.

159 {
160  const int minLength = str1.length() > str2.length()
161  ? CAST_S32(str2.length()) : CAST_S32(str1.length());
162  for (int f = 0; f < minLength; f ++)
163  {
164  if (str1.at(f) != str2.at(f))
165  return str1.substr(0, f);
166  }
167  return str1.substr(0, minLength);
168 }

References CAST_S32.

Referenced by SpellManager::autoComplete().

◆ findSameSubstringI()

const std::string findSameSubstringI ( const std::string &  s1,
const std::string &  s2 
)

Definition at line 170 of file stringutils.cpp.

172 {
173  std::string str1 = s1;
174  std::string str2 = s2;
175  toLower(str1);
176  toLower(str2);
177 
178  const size_t minLength = str1.length() > str2.length()
179  ? str2.length() : str1.length();
180  for (size_t f = 0; f < minLength; f ++)
181  {
182  if (str1.at(f) != str2.at(f))
183  return s1.substr(0, f);
184  }
185  return s1.substr(0, minLength);
186 }

References toLower().

Referenced by ChatWindow::autoComplete().

◆ getBoolFromString()

bool getBoolFromString ( const std::string &  text)

Returns a bool value depending on the given string value.

Parameters
textthe string used to get the bool value
Returns
a boolean value..

Definition at line 399 of file stringutils.cpp.

400 {
401  std::string txt = text;
402  toLower(trim(txt));
403  if (txt == "true" || txt == "yes" || txt == "on" || txt == "1")
404  return true;
405  else if (txt == "false" || txt == "no" || txt == "off" || txt == "0")
406  return false;
407  else
408  return static_cast<bool>(atoi(txt.c_str()));
409 }

References toLower(), and trim().

Referenced by Configuration::getBoolValue().

◆ getDateString()

std::string getDateString ( )

Definition at line 732 of file stringutils.cpp.

733 {
734  char buffer[80];
735  time_t rawtime;
736  time(&rawtime);
737  const tm *const timeinfo = localtime(&rawtime);
738 
739  strftime(buffer, 79, "%Y-%m-%d", timeinfo);
740  return std::string(buffer);
741 }

Referenced by ServerDialog::downloadServerList(), and ServerDialog::needUpdateServers().

◆ getDateTimeString()

std::string getDateTimeString ( )

Definition at line 743 of file stringutils.cpp.

744 {
745  char buffer[80];
746  time_t rawtime;
747  time(&rawtime);
748  const tm *const timeinfo = localtime(&rawtime);
749 
750  strftime(buffer, 79, "%Y-%m-%d %H:%M:%S", timeinfo);
751  return std::string(buffer);
752 }

Referenced by ActorManager::updateNameId().

◆ getFileDir()

std::string getFileDir ( const std::string &  path)

Definition at line 352 of file stringutils.cpp.

353 {
354  size_t pos1 = path.rfind('/');
355  const size_t pos2 = path.rfind('\\');
356  if (pos1 == std::string::npos ||
357  (pos2 != std::string::npos && pos2 > pos1))
358  {
359  pos1 = pos2;
360  }
361 
362  if (pos1 == std::string::npos)
363  return path;
364  return path.substr(0, pos1);
365 }

Referenced by VirtFs::FsDir::init(), and Configuration::init().

◆ getFileName()

std::string getFileName ( const std::string &  path)

Definition at line 337 of file stringutils.cpp.

338 {
339  size_t pos1 = path.rfind('/');
340  const size_t pos2 = path.rfind('\\');
341  if (pos1 == std::string::npos ||
342  (pos2 != std::string::npos && pos2 > pos1))
343  {
344  pos1 = pos2;
345  }
346 
347  if (pos1 == std::string::npos)
348  return path;
349  return path.substr(pos1 + 1);
350 }

Referenced by Setup_Theme::apply(), Setup_Theme::cancel(), and Setup_Theme::Setup_Theme().

◆ getSafeUtf8String() [1/2]

const char* getSafeUtf8String ( const std::string &  text)

Definition at line 307 of file stringutils.cpp.

308 {
309  const size_t sz = text.size();
310  const size_t size = sz + UTF8_MAX_SIZE;
311  char *const buf = new char[size];
312  memcpy(buf, text.c_str(), sz);
313  memset(buf + sz, 0, UTF8_MAX_SIZE);
314  return buf;
315 }

References EmoteDB::size(), and UTF8_MAX_SIZE.

Referenced by TextChunk::generate(), and Font::getWidth().

◆ getSafeUtf8String() [2/2]

void getSafeUtf8String ( std::string  text,
char *const  buf 
)

Definition at line 317 of file stringutils.cpp.

318 {
319  if (buf == nullptr)
320  return;
321  const size_t sz = text.size();
322  const size_t size = sz + UTF8_MAX_SIZE;
323  if (size > 65500)
324  {
325  text = text.substr(0, 65500);
326  const size_t sz1 = text.size();
327  memcpy(buf, text.c_str(), sz1);
328  memset(buf + sz1, 0, UTF8_MAX_SIZE);
329  }
330  else
331  {
332  memcpy(buf, text.c_str(), sz);
333  memset(buf + sz, 0, UTF8_MAX_SIZE);
334  }
335 }

References EmoteDB::size(), and UTF8_MAX_SIZE.

◆ ipToString()

const char* ipToString ( const uint32_t  address)

Converts the given IP address to a string.

The returned string is statically allocated, and shouldn't be freed. It is changed upon the next use of this method.

Parameters
addressthe address to convert to a string
Returns
the string representation of the address

Definition at line 85 of file stringutils.cpp.

86 {
87  static char asciiIP[18];
88 
89  snprintf(asciiIP, sizeof(asciiIP), "%i.%i.%i.%i",
90  CAST_U8(address),
91  CAST_U8(address >> 8),
92  CAST_U8(address >> 16),
93  CAST_U8(address >> 24));
94  asciiIP[17] = 0;
95 
96  return asciiIP;
97 }

References CAST_U8.

Referenced by Ea::LoginHandler::chooseServer(), TmwAthena::CharServerRecv::processChangeMapServer(), EAthena::CharServerRecv::processChangeMapServer(), TmwAthena::CharServerRecv::processCharMapInfo(), EAthena::CharServerRecv::processCharMapInfo(), TmwAthena::BeingRecv::processIpResponse(), TmwAthena::LoginRecv::processLoginData(), EAthena::LoginRecv::processLoginData(), and Ea::Network::realConnect().

◆ isDigit()

bool isDigit ( const std::string &  str)

Definition at line 858 of file stringutils.cpp.

859 {
860  if (str.empty())
861  return false;
862  const size_t sz = str.size();
863  for (size_t f = 0; f < sz; f ++)
864  {
865  const char &chr = str[f];
866  if (chr < '0' || chr > '9')
867  return false;
868  }
869  return true;
870 }

◆ normalize()

std::string normalize ( const std::string &  name)

Normalize a string, which means lowercase and trim it.

Definition at line 444 of file stringutils.cpp.

445 {
446  std::string normalized = name;
447  return toLower(trim(normalized));
448 }

References toLower(), and trim().

Referenced by ItemDB::exists(), ItemDB::get(), and ItemDB::loadXmlFile().

◆ packList()

std::string packList ( const std::list< std::string > &  list)

Definition at line 589 of file stringutils.cpp.

590 {
591  std::list<std::string>::const_iterator i = list.begin();
592  std::string str;
593  while (i != list.end())
594  {
595  str.append(*i).append("|");
596  ++ i;
597  }
598  const size_t sz = str.size();
599  if (sz > 1)
600  str = str.substr(0, sz - 1);
601  return str;
602 }

Referenced by ActorManager::storeAttackList().

◆ parse2Int()

bool parse2Int ( const std::string &  args,
int &  x,
int &  y 
)

Definition at line 878 of file stringutils.cpp.

881 {
882  bool isValid = false;
883  size_t pos = args.find(' ');
884  if (pos == std::string::npos)
885  pos = args.find(',');
886  if (pos != std::string::npos)
887  {
888  if (pos + 1 < args.length())
889  {
890  x = atoi(args.substr(0, pos).c_str());
891  y = atoi(args.substr(pos + 1, args.length()).c_str());
892  isValid = true;
893  }
894  }
895  return isValid;
896 }

References x, and y.

◆ parse2Str()

bool parse2Str ( const std::string &  args,
std::string &  str1,
std::string &  str2 
)

Definition at line 898 of file stringutils.cpp.

901 {
902  bool isValid = false;
903  size_t pos = args.find(' ');
904  if (pos == std::string::npos)
905  pos = args.find(',');
906  if (pos != std::string::npos)
907  {
908  if (pos + 1 < args.length())
909  {
910  str1 = args.substr(0, pos);
911  str2 = args.substr(pos + 1, args.length());
912  isValid = true;
913  }
914  }
915  return isValid;
916 }

Referenced by ItemLinkHandler::handleCommandLink(), and Ea::PlayerRecv::processPlayerClientCommand().

◆ parseBoolean()

signed char parseBoolean ( const std::string &  value)

Definition at line 754 of file stringutils.cpp.

755 {
756  std::string txt = value;
757  toLower(trim(txt));
758  if (txt == "true" || txt == "yes" || txt == "on" || txt == "1")
759  return 1;
760  else if (txt == "false" || txt == "no" || txt == "off" || txt == "0")
761  return 0;
762  else
763  return -1;
764 }

References toLower(), and trim().

◆ parseNumber()

uint32_t parseNumber ( const std::string &  str)

Definition at line 918 of file stringutils.cpp.

919 {
920  uint32_t i = 0;
921  int idx = 0;
922  if (strStartWith(str, "0x"))
923  idx = 2;
924  else if (str[0] == 'h' || str[0] == 'x')
925  idx = 1;
926  if (idx > 0)
927  sscanf(str.substr(idx).c_str(), "%10x", &i);
928  else
929  i = atoi(str.c_str());
930  return i;
931 }

References strStartWith().

Referenced by EAthena::ChatHandler::processRaw(), TmwAthena::ChatHandler::processRaw(), TmwAthena::ChatHandler::sendRaw(), and EAthena::ChatHandler::sendRaw().

◆ pathJoin() [1/2]

std::string pathJoin ( std::string  str1,
const std::string &  str2 
)

Definition at line 1036 of file stringutils.cpp.

1038 {
1039 #ifdef WIN32
1040  const char sep = '\\';
1041  std::string sepStr = "\\";
1042 #else
1043  const char sep = '/';
1044  std::string sepStr = "/";
1045 #endif
1046 
1047  if (str1.empty())
1048  {
1049  if (str2[0] == sep)
1050  return str2;
1051  return sepStr.append(str2);
1052  }
1053  const size_t sz1 = str1.size();
1054  if (str2.empty())
1055  {
1056  if (str1[sz1 - 1] == sep)
1057  return str1;
1058  return str1.append(sepStr);
1059  }
1060  if (str1[sz1 - 1] == sep)
1061  {
1062  if (str2[0] == sep)
1063  return str1.append(str2.substr(1));
1064  return str1.append(str2);
1065  }
1066  else
1067  {
1068  if (str2[0] == sep)
1069  return str1.append(str2);
1070  return str1.append(sepStr).append(str2);
1071  }
1072 }

Referenced by SetupItemSound::action(), Map::addExtraLayer(), UpdaterWindow::addUpdateFile(), ConfigManager::backupConfig(), Game::changeMap(), Files::deleteFilesInDirectory(), UpdaterWindow::download(), ServerDialog::downloadServerList(), VirtFs::FsZip::enumerate(), VirtFs::FsZip::exists(), Dirs::extractDataDir(), Client::gameExec(), Client::gameInit(), VirtFs::FsZip::getDirs(), VirtFs::FsDir::getDirs(), VirtFs::FsZip::getFiles(), VirtFs::FsDir::getFiles(), VirtFs::FsZip::getFilesWithDir(), VirtFs::FsDir::getFilesWithDir(), StatusEffect::getIcon(), Item::getImage(), VirtFs::getPath(), getPicturesDir(), VirtFs::FsZip::getRealDir(), Map::getUserMapDirectory(), Wallpaper::getWallpaper(), SpriteDef::includeSprite(), Dirs::initConfigDir(), Dirs::initLocalDataDir(), Dirs::initScreenshotDir(), ConfigManager::initServerConfig(), Dirs::initTempDir(), Dirs::initUpdatesDir(), VirtFs::FsZip::isDirectory(), HorseDB::load(), EmoteDB::load(), SpriteDef::load(), Theme::loadColors(), Being::loadComment(), Client::loadData(), UpdaterWindow::loadDirMods(), DidYouKnowWindow::loadFile(), HelpWindow::loadFile(), VirtFs::FsZip::loadFile(), TextCommand::loadImage(), Theme::loadInfo(), UpdaterWindow::loadLocalUpdates(), UpdaterWindow::loadManaPlusUpdates(), UpdaterWindow::loadMods(), loadMusic(), ServerDialog::loadServers(), EmoteDB::loadSpecialXmlFile(), UpdaterWindow::loadUpdates(), EmoteDB::loadXmlFile(), UpdaterWindow::logic(), Dirs::mountDataDir(), VirtFs::FsZip::openRead(), NpcDialog::parseListItems(), pathJoin(), SoundManager::playGuiSfx(), SoundManager::playGuiSound(), SoundManager::playSfx(), TestMain::readValue(), UpdaterWindow::removeUpdateFile(), Theme::resolveThemePath(), Being::saveComment(), Map::saveExtraLayer(), Files::saveTextFile(), VirtFs::searchAndAddArchives(), VirtFs::searchAndRemoveArchives(), Being::setGender(), Being::setHairTempSprite(), Item::setId(), ItemPopup::setItem(), Being::setLanguageId(), Minimap::setMap(), ChatLogger::setServerName(), Being::setSpriteCards(), Being::setSpriteColor(), Being::setSpriteColorId(), Being::setSpriteId(), Being::setTempSprite(), ActorSprite::setupSpriteDisplay(), CutInWindow::show(), TestLauncher::TestLauncher(), TestMain::TestMain(), Client::unloadData(), UpdaterWindow::unloadManaPlusUpdates(), UpdaterWindow::unloadMods(), UpdaterWindow::unloadUpdates(), Dirs::updateDataPath(), MapReader::updateMusic(), and ActorManager::updateNameId().

◆ pathJoin() [2/2]

std::string pathJoin ( std::string  str1,
const std::string &  str2,
const std::string &  str3 
)

Definition at line 1074 of file stringutils.cpp.

1077 {
1078 #ifdef WIN32
1079  const char sep = '\\';
1080  std::string sepStr = "\\";
1081 #else
1082  const char sep = '/';
1083  std::string sepStr = "/";
1084 #endif
1085 
1086  if (str1.empty())
1087  {
1088  return pathJoin(str2, str3);
1089  }
1090  size_t sz1 = str1.size();
1091  if (str2.empty())
1092  {
1093  return pathJoin(str1, str3);
1094  }
1095  if (str3.empty())
1096  {
1097  return pathJoin(str1, str2);
1098  }
1099  if (str1[sz1 - 1] == sep)
1100  {
1101  if (str2[0] == sep)
1102  str1.append(str2.substr(1));
1103  else
1104  str1.append(str2);
1105  }
1106  else
1107  {
1108  if (str2[0] == sep)
1109  str1.append(str2);
1110  else
1111  str1.append(sepStr).append(str2);
1112  }
1113 
1114  sz1 = str1.size();
1115  if (str1[sz1 - 1] == sep)
1116  {
1117  if (str3[0] == sep)
1118  return str1.append(str3.substr(1));
1119  return str1.append(str3);
1120  }
1121  else
1122  {
1123  if (str3[0] == sep)
1124  return str1.append(str3);
1125  return str1.append(sepStr).append(str3);
1126  }
1127 }

References pathJoin().

◆ removeColors()

std::string removeColors ( std::string  msg)

Removes colors from a string

Parameters
msgthe string to remove the colors from
Returns
string without colors

Definition at line 121 of file stringutils.cpp.

122 {
123  for (unsigned int f = 0; f < msg.length() - 2 && msg.length() > 2; f++)
124  {
125  while (msg.length() > f + 2 && msg.at(f) == '#'
126  && msg.at(f + 1) == '#')
127  {
128  msg = msg.erase(f, 3);
129  }
130  }
131  return msg;
132 }

References Actions::msg().

Referenced by ChatWindow::addWhisper(), ChatTab::chatLog(), ChatLogger::log(), TmwAthena::ChatRecv::processBeingChat(), EAthena::ChatRecv::processBeingChat(), and Being::setSpeech().

◆ removeProtocol()

std::string& removeProtocol ( std::string &  url)

Definition at line 715 of file stringutils.cpp.

716 {
717  const size_t i = url.find("://");
718  if (i != std::string::npos)
719  url = url.substr(i + 3);
720  return url;
721 }

References Actions::url().

Referenced by UpdaterWindow::postInit().

◆ removeSpriteIndex()

std::string removeSpriteIndex ( std::string  str)

Definition at line 284 of file stringutils.cpp.

285 {
286  const size_t pos1 = str.rfind('[');
287 
288  if (pos1 != std::string::npos)
289  {
290  size_t pos2 = str.rfind('/');
291  const size_t pos3 = str.rfind('\\');
292  if (pos3 != std::string::npos)
293  {
294  if (pos2 == std::string::npos || pos3 > pos2)
295  pos2 = pos3;
296  }
297  if (pos2 == std::string::npos)
298  pos2 = CAST_SIZE(-1);
299 
300  const int size = CAST_S32(pos1) - CAST_S32(pos2) - 1;
301  if (size > 0)
302  str = str.substr(pos2 + 1, size);
303  }
304  return str;
305 }

References CAST_S32, CAST_SIZE, and EmoteDB::size().

Referenced by Inventory::findItemBySprite().

◆ removeToken()

std::string removeToken ( std::string &  str,
const std::string &  token 
)

Definition at line 933 of file stringutils.cpp.

935 {
936  const size_t idx = str.find(token);
937  if (idx > 0 && idx != std::string::npos)
938  str = str.substr(idx + 1);
939  else
940  str.clear();
941  return str;
942 }

Referenced by Actions::getAmountFromEvent().

◆ replaceAll()

std::string& replaceAll ( std::string &  context,
const std::string &  from,
const std::string &  to 
)

Definition at line 367 of file stringutils.cpp.

370 {
371  if (from.empty())
372  return context;
373  size_t lookHere = 0;
374  size_t foundHere;
375  const size_t fromSize = from.size();
376  const size_t toSize = to.size();
377  while ((foundHere = context.find(from, lookHere)) != std::string::npos)
378  {
379  context.replace(foundHere, fromSize, to);
380  lookHere = foundHere + toSize;
381  }
382  return context;
383 }

Referenced by addToken(), LocalPlayer::afkRespond(), PoParser::convertStr(), decodeLinkText(), encodeLinkText(), escapeString(), fixDirSeparators(), getPicturesDir(), ItemLinkHandler::handleHttpLink(), PopupMenu::handleLink(), Dirs::initUpdatesDir(), Setup_Mods::loadMods(), loadQuest(), SpellManager::parseCommand(), ItemInfo::replaceColors(), BrowserBoxTools::replaceVars(), replaceVars(), ChatWindow::resortChatLog(), QuestsWindow::showQuest(), TranslationManager::translateFile(), and Setup_Theme::updateInfo().

◆ replaceItemLinks()

void replaceItemLinks ( std::string &  msg)

Definition at line 1194 of file stringutils.cpp.

1195 {
1196  // Check for item link
1197  size_t start2 = msg.find('[');
1198  size_t sz = msg.size();
1199  while (start2 + 1 < sz &&
1200  start2 != std::string::npos &&
1201  msg[start2 + 1] != '@')
1202  {
1203  const size_t end = msg.find(']', start2);
1204  if (start2 + 1 != end &&
1205  end != std::string::npos)
1206  {
1207  // Catch multiple embeds and ignore them
1208  // so it doesn't crash the client.
1209  while ((msg.find('[', start2 + 1) != std::string::npos) &&
1210  (msg.find('[', start2 + 1) < end))
1211  {
1212  start2 = msg.find('[', start2 + 1);
1213  }
1214 
1215  if (start2 + 1 < sz &&
1216  end < sz &&
1217  end > start2 + 1)
1218  {
1219  std::string itemStr = msg.substr(start2 + 1, end - start2 - 1);
1220 
1221  StringVect parts;
1222  splitToStringVector(parts, itemStr, ',');
1223  if (parts.empty())
1224  return;
1225 
1226  const ItemInfo &itemInfo = ItemDB::get(parts[0]);
1227  const int itemId = itemInfo.getId();
1228  if (itemId != 0)
1229  {
1230  std::string temp = strprintf("@@%d", itemId);
1231  std::string name = parts[0];
1232  msg.erase(start2 + 1, end - start2 - 1);
1233  parts.erase(parts.begin());
1234  if (!parts.empty())
1235  name.clear();
1236 
1237  FOR_EACH (StringVectCIter, it, parts)
1238  {
1239  std:: string str = *it;
1240  trim(str);
1241  const ItemInfo &itemInfo2 = ItemDB::get(str);
1242  const int cardId = itemInfo2.getId();
1243  if (cardId != 0)
1244  temp.append(strprintf(",%d", cardId));
1245  }
1246  temp.append("|");
1247  temp.append(name);
1248  temp.append("@@");
1249  msg.insert(start2 + 1, temp);
1250  sz = msg.size();
1251  }
1252  }
1253  }
1254  start2 = msg.find('[', start2 + 1);
1255  }
1256 }

References FOR_EACH, ItemDB::get(), ItemInfo::getId(), Actions::itemInfo(), Actions::msg(), splitToStringVector(), strprintf(), and trim().

Referenced by ChatTab::chatInput(), and loadQuest().

◆ replaceRecursiveAll()

void replaceRecursiveAll ( std::string &  context,
const std::string &  from,
const char  to 
)

Definition at line 385 of file stringutils.cpp.

388 {
389  size_t lookHere = 0;
390  size_t foundHere;
391  const size_t fromSize = from.size();
392  while ((foundHere = context.find(from, lookHere)) != std::string::npos)
393  {
394  context.replace(foundHere, fromSize, 1, to);
395  lookHere = foundHere;
396  }
397 }

Referenced by sanitizePath().

◆ replaceSpecialChars()

void replaceSpecialChars ( std::string &  text)

Definition at line 411 of file stringutils.cpp.

412 {
413  size_t pos1 = text.find('&');
414  while (pos1 != std::string::npos)
415  {
416  const size_t idx = pos1 + 1;
417  const size_t sz = text.size();
418  if (idx >= sz)
419  break;
420 
421  size_t f;
422  for (f = idx; f < sz; f ++)
423  {
424  if (text[f] < '0' || text[f] > '9')
425  break;
426  }
427  if (idx + 1 < f && text[f] == ';')
428  {
429  std::string str(" ");
430  str[0] = CAST_S8(atoi(text.substr(
431  idx, f - idx).c_str()));
432  text = text.substr(0, pos1).append(str).append(text.substr(f + 1));
433  pos1 += 1;
434  }
435  else
436  {
437  pos1 = f + 1;
438  }
439 
440  pos1 = text.find('&', pos1);
441  }
442 }

References CAST_S8.

Referenced by ChatWindow::doReplace().

◆ rfindSepatator()

size_t rfindSepatator ( const std::string &  str1)

Definition at line 1162 of file stringutils.cpp.

1163 {
1164  const size_t idx1 = str1.rfind('/');
1165  const size_t idx2 = str1.rfind('\\');
1166  if (idx1 != std::string::npos)
1167  { // idx1
1168  if (idx2 != std::string::npos)
1169  { // idx1, idx2
1170  if (idx1 >= idx2)
1171  return idx1;
1172  else
1173  return idx2;
1174  }
1175  else
1176  { // idx1, not idx2
1177  return idx1;
1178  }
1179  }
1180  else
1181  { // not idx1
1182  if (idx2 != std::string::npos)
1183  { // not idx1, idx2
1184  return idx2;
1185  }
1186  else
1187  { // not idx1, not idx2
1188  return std::string::npos;
1189  }
1190  }
1191 }

Referenced by Map::getGatName().

◆ sanitizePath()

void sanitizePath ( std::string &  path)

Definition at line 1021 of file stringutils.cpp.

1022 {
1023 #ifdef WIN32
1024  const char sepStr = '\\';
1025  const std::string sep2Str = "\\\\";
1026  const std::string sepWrongStr = "/";
1027 #else
1028  const char sepStr = '/';
1029  const std::string sep2Str = "//";
1030  const std::string sepWrongStr = "\\";
1031 #endif
1032  replaceRecursiveAll(path, sepWrongStr, sepStr);
1033  replaceRecursiveAll(path, sep2Str, sepStr);
1034 }

References replaceRecursiveAll().

Referenced by prepareFsPath().

◆ secureChatCommand()

void secureChatCommand ( std::string &  str)

Definition at line 872 of file stringutils.cpp.

873 {
874  if (str[0] == '/' || str[0] == '@' || str[0] == '#')
875  str = "_" + str;
876 }

Referenced by ChatWindow::autoComplete().

◆ splitToIntList()

std::list<int> splitToIntList ( const std::string &  text,
const char  separator 
)

Definition at line 460 of file stringutils.cpp.

462 {
463  std::list<int> tokens;
464  std::stringstream ss(text);
465  std::string item;
466  while (std::getline(ss, item, separator))
467  tokens.push_back(atoi(item.c_str()));
468 
469  return tokens;
470 }

◆ splitToIntSet()

void splitToIntSet ( std::set< int > &  tokens,
const std::string &  text,
const char  separator 
)

Definition at line 450 of file stringutils.cpp.

453 {
454  std::stringstream ss(text);
455  std::string item;
456  while (std::getline(ss, item, separator))
457  tokens.insert(atoi(item.c_str()));
458 }

Referenced by PlayerInfo::loadData(), loadEffect(), Net::loadIgnorePackets(), and loadQuest().

◆ splitToIntVector()

void splitToIntVector ( std::vector< int > &  tokens,
const std::string &  text,
const char  separator 
)

Definition at line 512 of file stringutils.cpp.

515 {
516  std::stringstream ss(text);
517  std::string item;
518  while (std::getline(ss, item, separator))
519  {
520  item = trim(item);
521  if (!item.empty())
522  tokens.push_back(atoi(item.c_str()));
523  }
524 }

References trim().

Referenced by ItemLinkHandler::handleItemLink(), GraphicsManager::initGraphics(), ItemShortcutContainer::mouseMoved(), parseInherit(), BrowserBoxTools::replaceLinkCommands(), GraphicsManager::setVideoMode(), and SkillDialog::useItem().

◆ splitToStringList()

std::list<std::string> splitToStringList ( const std::string &  text,
const char  separator 
)

Definition at line 472 of file stringutils.cpp.

474 {
475  std::list<std::string> tokens;
476  std::stringstream ss(text);
477  std::string item;
478  while (std::getline(ss, item, separator))
479  tokens.push_back(item);
480 
481  return tokens;
482 }

Referenced by combineDye2(), combineDye3(), and unpackList().

◆ splitToStringSet()

void splitToStringSet ( std::set< std::string > &  tokens,
const std::string &  text,
const char  separator 
)

Definition at line 498 of file stringutils.cpp.

501 {
502  std::stringstream ss(text);
503  std::string item;
504  while (std::getline(ss, item, separator))
505  {
506  item = trim(item);
507  if (!item.empty())
508  tokens.insert(item);
509  }
510 }

References trim().

Referenced by Setup_Mods::loadMods(), UpdaterWindow::loadMods(), GraphicsManager::updateExtensions(), and GraphicsManager::updatePlanformExtensions().

◆ splitToStringVector()

void splitToStringVector ( StringVect tokens,
const std::string &  text,
const char  separator 
)

Definition at line 484 of file stringutils.cpp.

487 {
488  std::stringstream ss(text);
489  std::string item;
490  while (std::getline(ss, item, separator))
491  {
492  item = trim(item);
493  if (!item.empty())
494  tokens.push_back(item);
495  }
496 }

References trim().

Referenced by InputManager::addChatCommands(), NpcDialog::createSkinControls(), Cpu::detect(), DyePalette::DyePalette(), SpriteDef::loadAnimation(), UpdaterWindow::loadDirMods(), ChatWindow::parseGlobalsFilter(), ChatWindow::parseHighlights(), GuildManager::process(), EAthena::LoginRecv::processUpdateHost2(), readField(), BeingCommon::readWalkingAttributes(), replaceItemLinks(), InputManager::retrieve(), and UpdaterWindow::unloadMods().

◆ stringToHexPath()

std::string stringToHexPath ( const std::string &  str)

Definition at line 609 of file stringutils.cpp.

610 {
611  if (str.empty())
612  return "";
613 
614  std::string hex = strprintf("%%%2x/", CAST_U32(str[0]));
615  for (unsigned f = 1, fsz = CAST_U32(str.size());
616  f < fsz; f ++)
617  {
618  hex.append(strprintf("%%%2x", CAST_U32(str[f])));
619  }
620  return hex;
621 }

References CAST_U32, and strprintf().

Referenced by Being::loadComment(), Being::saveComment(), and ActorManager::updateNameId().

◆ strprintf()

std::string strprintf ( const char *const  format,
  ... 
)

A safe version of sprintf that returns a std::string of the result.

Definition at line 99 of file stringutils.cpp.

100 {
101  char buf[257];
102  va_list args;
103  va_start(args, format);
104  size_t nb = vsnprintf(buf, 256, format, args);
105  buf[256] = 0;
106  va_end(args);
107  if (nb < 256)
108  return buf;
109 
110  // The static size was not big enough, try again with a dynamic allocation.
111  ++nb;
112  char *buf2 = new char[nb];
113  va_start(args, format);
114  vsnprintf(buf2, nb, format, args);
115  va_end(args);
116  std::string res(buf2);
117  delete [] buf2;
118  return res;
119 }

Referenced by IPC::acceptLoop(), StatDebugTab::action(), KillStats::action(), ChangePasswordDialog::action(), ChangeEmailDialog::action(), SocialWindow::action(), RegisterDialog::action(), CharSelectDialog::action(), SocialGuildTab::action(), SocialPartyTab::action(), NpcDialog::action(), TradeWindow::action(), PopupMenu::addChat(), LocalPlayer::addHomunXpMessage(), LocalPlayer::addHpMessage(), LocalPlayer::addJobMessage(), SocialNavigationTab::addPortal(), StaticBrowserBox::addRow(), BrowserBox::addRow(), ServerInfoWindow::addServerComment(), SkillDialog::addSkill(), LocalPlayer::addSpMessage(), ChatWindow::addWhisper(), LocalPlayer::addXpMessage(), ShopWindow::announce(), Setup_Input::apply(), applyEffectByOption(), applyEffectByOption1(), StatsPageBasic::attributeChanged(), KillStats::attributeChanged(), StatusWindow::attributeChanged(), BankWindow::bankMoneyChanged(), SocialGuildTab2::buildCounter(), SocialGuildTab::buildCounter(), SocialPartyTab::buildCounter(), ChangeEmailDialog::ChangeEmailDialog(), ChangePasswordDialog::ChangePasswordDialog(), Actions::changeRelation(), CharacterViewSmall::CharacterViewSmall(), CharSelectDialog::CharSelectDialog(), ChatTab::chatLog(), LocalPlayer::checkNewName(), InventoryWindow::combineItems(), compareSDLVersions(), NpcDialog::complexItemToStr(), Ea::AdminHandler::createItems(), Desktop::Desktop(), TmwAthena::Network::dispatchMessages(), EAthena::Network::dispatchMessages(), ChatWindow::doPresent(), WindowManager::doResizeVideo(), AvatarListBox::draw(), TestMain::exec(), LocalPlayer::fixPos(), Setup_Input::fixTranslation(), formatUnit(), KillStats::gainXp(), Client::gameInit(), ItemPopup::getCardsString(), GameModifiers::getCrazyMoveTypeString(), ChatLogger::getDir(), PoParser::getFileName(), KeyboardConfig::getKeyName(), InputManager::getKeyStringLong(), ItemInfo::getLink(), MailWindow::getMailHeader(), ItemPopup::getOptionsString(), LocalPlayer::getPingTime(), SocialFriendsTab::getPlayersAvatars(), SocialPlayersTab::getPlayersAvatars(), GameModifiers::getQuickDropCounterString(), Loader::getRescaled(), StatsPageBasic::getStatsStr(), ShopWindow::giveList(), ItemLinkHandler::handleCommandLink(), BuyDialog::init(), Dirs::initConfigDir(), Dirs::initLocalDataDir(), Dirs::initScreenshotDir(), ConfigManager::initServerConfig(), ActorSprite::initTargetCursor(), Dirs::initTempDir(), WindowManager::initTitle(), TradeWindow::initTrade(), Dirs::initUpdatesDir(), Dirs::initUsersDir(), InsertCardDialog::InsertCardDialog(), SocialGuildTab::invite(), SocialPartyTab::invite(), KillStats::KillStats(), SocialGuildTab::leave(), SocialPartyTab::leave(), CharDB::load(), Theme::load(), DidYouKnowWindow::loadFile(), ChatLogger::loadLast(), UpdaterWindow::loadPatch(), loadQuest(), ServerDialog::loadServers(), SkillDialog::loadSkill(), SkillDialog::loadSkillData(), loadUnit(), SkillDialog::loadXmlFile(), ChatLogger::log(), Logger::log_r(), EventsManager::logEvent(), NetDebugTab::logic(), TargetDebugTab::logic(), MapDebugTab::logic(), StatDebugTab::logic(), ServerDialog::logic(), UpdaterWindow::logic(), MailViewWindow::MailViewWindow(), MapDebugTab::MapDebugTab(), Ea::ChatHandler::me(), WindowMenu::mouseMoved(), EmoteShortcutContainer::mouseMoved(), MiniStatusWindow::mouseMoved(), CharacterDisplay::mouseMoved(), InventoryWindow::mouseMoved(), NotifyManager::notify(), EAthena::AdminHandler::npcMove(), Joystick::open(), DialogsManager::openErrorDialog(), LocalPlayer::pickedUp(), SellDialog::postInit(), WhoIsOnline::prepareNick(), MemoryManager::printAllMemory(), ActorManager::printBeingsToChat(), printVersion(), EAthena::FamilyRecv::processAskForChild(), EAthena::ChatRecv::processColorChat(), EAthena::ChatRecv::processFormatColor(), EAthena::ChatRecv::processFormatMessage(), EAthena::ChatRecv::processFormatMessageNumber(), EAthena::ChatRecv::processFormatMessageSkill(), EAthena::ChatRecv::processFormatMessageString(), EAthena::ChatRecv::processFormatMessageStringColor(), EAthena::GuildRecv::processGuildBasicInfo(), EAthena::HomunculusRecv::processHomunculusFood(), EAthena::ChatRecv::processJoinChannel(), EAthena::PlayerRecv::processKilledBy(), Ea::LoginRecv::processLoginError(), EAthena::LoginRecv::processLoginError2(), EAthena::MailRecv::processNewMail(), EAthena::InventoryRecv::processPlayerItemRentalTime(), EAthena::VendingRecv::processReport(), ShopWindow::processRequest(), EAthena::SkillRecv::processSkillFailed(), Ea::TradeRecv::processTradeRequestContinue(), Ea::TradeRecv::processTradeResponseContinue(), TmwAthena::ChatRecv::processWhisperContinue(), EAthena::ChatRecv::processWhisperResponse(), Ea::ChatRecv::processWhisperResponseContinue(), Net::MessageIn::readBytes(), readField(), Net::MessageIn::readFloat(), readOptionFields(), Setup_Input::refreshAssignedKey(), MailViewWindow::removeMoney(), replaceItemLinks(), AvatarListBox::safeDraw(), SpellManager::save(), Map::saveExtraLayer(), ShopWindow::saveList(), Game::saveScreenshot(), HelpWindow::search(), NpcSellDialog::sellAction(), TmwAthena::BuySellHandler::sendBuyRequest(), TmwAthena::BuySellHandler::sendSellRequest(), LocalPlayer::setAction(), LocalPlayer::setFollow(), LocalPlayer::setImitate(), ItemPopup::setItem(), StatusPopup::setLabelText(), TradeWindow::setMoney(), OnlinePlayer::setText(), Setup_Touch::Setup_Touch(), GraphicsManager::setVideoMode(), CharacterViewSmall::show(), BeingPopup::show(), SkillPopup::show(), PopupMenu::showChangePos(), PopupMenu::showChatPopup(), PopupMenu::showCraftPopup(), OutfitWindow::showCurrentOutfit(), SocialWindow::showGuildInvite(), PopupMenu::showMuteCommands(), ChatTab::showOnline(), SocialWindow::showPartyInvite(), PopupMenu::showPlayerMenu(), PopupMenu::showPlayerPopup(), PopupMenu::showPopup(), QuestsWindow::showQuest(), PopupMenu::showSkillLevelPopup(), PopupMenu::showSkillOffsetPopup(), PopupMenu::showSkillTypePopup(), Being::showTeamBadge(), PopupMenu::showWindowsPopup(), EAthena::AdminHandler::slide(), InventoryWindow::slotsChanged(), StatDebugTab::StatDebugTab(), StatsPageBasic::StatsPageBasic(), StatusWindow::StatusWindow(), InputManager::store(), stringToHexPath(), Being::takeDamage(), TmwAthena::ChatHandler::talkPet(), textToMe(), timeDiffToString(), SkillInfo::toDataStr(), toString(), Logger::unimplemented(), UserAgent::update(), AttrDisplay::update(), KillStats::update(), SkillDialog::update(), SkillInfo::update(), SellDialog::updateButtonsAndLabels(), BuyDialog::updateButtonsAndLabels(), InfoClanTab::updateClan(), StatusWindow::updateInvSlotsBar(), InputManager::updateKeyString(), StatusWindow::updateLevelLabel(), SocialNavigationTab::updateList(), SocialNavigationTab::updateNames(), StatusWindow::updateProgressBar(), ShopWindow::updateShopName(), CharCreateDialog::updateSliders(), WindowManager::updateTitle(), InventoryWindow::updateWeight(), StatusWindow::updateWeightBar(), Actions::uploadUpdate(), UserPalette::UserPalette(), SkillDialog::useSkillDefault(), SkillDialog::useSkillPosition(), SkillDialog::useSkillTarget(), TmwAthena::AdminHandler::warp(), Net::MessageOut::writeCoordinates(), and Net::MessageOut::writeFloat().

◆ strStartWith()

bool strStartWith ( const std::string &  str1,
const std::string &  str2 
)

◆ timeDiffToString()

std::string timeDiffToString ( int  timeDiff)

Definition at line 954 of file stringutils.cpp.

955 {
956  std::string str;
957 
958  const int weeks = timeDiff / 60 / 60 / 24 / 7;
959  if (weeks > 0)
960  {
961  // TRANSLATORS: uptime command
962  str = strprintf(ngettext(N_("%d week"), N_("%d weeks"),
963  weeks), weeks);
964  timeDiff -= weeks * 60 * 60 * 24 * 7;
965  }
966 
967  const int days = timeDiff / 60 / 60 / 24;
968  if (days > 0)
969  {
970  if (!str.empty())
971  str.append(", ");
972  // TRANSLATORS: uptime command
973  str.append(strprintf(ngettext(N_("%d day"), N_("%d days"),
974  days), days));
975  timeDiff -= days * 60 * 60 * 24;
976  }
977  const int hours = timeDiff / 60 / 60;
978  if (hours > 0)
979  {
980  if (!str.empty())
981  str.append(", ");
982  // TRANSLATORS: uptime command
983  str.append(strprintf(ngettext(N_("%d hour"), N_("%d hours"),
984  hours), hours));
985  timeDiff -= hours * 60 * 60;
986  }
987  const int min = timeDiff / 60;
988  if (min > 0)
989  {
990  if (!str.empty())
991  str.append(", ");
992  // TRANSLATORS: uptime command
993  str.append(strprintf(ngettext(N_("%d minute"), N_("%d minutes"),
994  min), min));
995  timeDiff -= min * 60;
996  }
997 
998  if (timeDiff > 0)
999  {
1000  if (!str.empty())
1001  str.append(", ");
1002  // TRANSLATORS: uptime command
1003  str.append(strprintf(ngettext(N_("%d second"), N_("%d seconds"),
1004  timeDiff), timeDiff));
1005  }
1006  if (str.empty())
1007  {
1008  // TRANSLATORS: uptime command
1009  str.append(strprintf(ngettext(N_("%d second"), N_("%d seconds"),
1010  0), 0));
1011  }
1012  return str;
1013 }

References N_, and strprintf().

Referenced by EAthena::InventoryRecv::processPlayerItemRentalTime(), and QuestsWindow::showQuest().

◆ timeToStr()

std::string timeToStr ( const uint32_t  time)

Definition at line 944 of file stringutils.cpp.

945 {
946  char buf[101];
947  const time_t tempTime = time;
948  tm *const timeInfo = localtime(&tempTime);
949  if (strftime(&buf[0], 100, "%Y-%m-%d_%H-%M-%S", timeInfo) != 0U)
950  return std::string(buf);
951  return "unknown";
952 }

Referenced by EAthena::MailRecv::processMailList(), EAthena::Mail2Recv::processMailListPage(), and EAthena::MailRecv::processReadMail().

◆ toLower()

std::string& toLower ( std::string &  str)

Converts the given string to lower case.

Parameters
strthe string to convert to lower case
Returns
a reference to the given string converted to lower case

Definition at line 65 of file stringutils.cpp.

66 {
67  std::transform(str.begin(), str.end(), str.begin(), &tolower);
68  return str;
69 }

Referenced by findI(), findSameSubstringI(), getBoolFromString(), normalize(), and parseBoolean().

◆ toString() [1/7]

std::string toString ( const double  num)

Definition at line 853 of file stringutils.cpp.

854 {
855  return strprintf("%f", static_cast<float>(num));
856 }

References strprintf().

◆ toString() [2/7]

std::string toString ( const float  num)

Definition at line 848 of file stringutils.cpp.

849 {
850  return strprintf("%f", num);
851 }

References strprintf().

◆ toString() [3/7]

std::string toString ( int32_t  num)

Definition at line 828 of file stringutils.cpp.

829 {
830  char buf[30];
831  bool useSign(false);
832  buf[29] = '\0';
833  size_t idx = 28;
834 
835  if (num < 0)
836  {
837  useSign = true;
838  num = -num;
839  }
840  do
841  buf[idx--] = CAST_8((num % 10) + '0');
842  while ((num /= 10) != 0);
843  if (useSign)
844  buf[idx--] = '-';
845  return buf + idx + 1;
846 }

References CAST_8.

◆ toString() [4/7]

std::string toString ( uint16_t  num)

Definition at line 806 of file stringutils.cpp.

807 {
808  char buf[10];
809  buf[9] = '\0';
810  size_t idx = 8;
811  do
812  buf[idx--] = CAST_8((num % 10) + '0');
813  while ((num /= 10) != 0);
814  return buf + idx + 1;
815 }

References CAST_8.

◆ toString() [5/7]

std::string toString ( uint32_t  num)

Converts the given value to a string.

Parameters
numthe value to convert to a string
Returns
the string representation of arg

Definition at line 784 of file stringutils.cpp.

785 {
786  char buf[30];
787  buf[29] = '\0';
788  size_t idx = 28;
789  do
790  buf[idx--] = CAST_8((num % 10) + '0');
791  while ((num /= 10) != 0);
792  return buf + idx + 1;
793 }

References CAST_8.

◆ toString() [6/7]

std::string toString ( uint64_t  num)

Definition at line 795 of file stringutils.cpp.

796 {
797  char buf[100];
798  buf[99] = '\0';
799  size_t idx = 98;
800  do
801  buf[idx--] = CAST_8((num % 10) + '0');
802  while ((num /= 10) != 0);
803  return buf + idx + 1;
804 }

References CAST_8.

◆ toString() [7/7]

std::string toString ( unsigned char  num)

Definition at line 817 of file stringutils.cpp.

818 {
819  char buf[5];
820  buf[4] = '\0';
821  size_t idx = 3;
822  do
823  buf[idx--] = CAST_8((num % 10) + '0');
824  while ((num /= 10) != 0);
825  return buf + idx + 1;
826 }

References CAST_8.

◆ toStringPrint()

std::string toStringPrint ( const unsigned int  val)

◆ toUpper()

std::string& toUpper ( std::string &  str)

Converts the given string to upper case.

Parameters
strthe string to convert to upper case
Returns
a reference to the given string converted to upper case

Definition at line 71 of file stringutils.cpp.

72 {
73  std::transform(str.begin(), str.end(), str.begin(), &toupper);
74  return str;
75 }

◆ trim()

std::string& trim ( std::string &  str)

Trims spaces off the end and the beginning of the given string.

Parameters
strthe string to trim spaces off
Returns
a reference to the trimmed string

Definition at line 46 of file stringutils.cpp.

47 {
48  size_t pos = str.find_last_not_of(' ');
49  if (pos != std::string::npos)
50  {
51  str.erase(pos + 1);
52  pos = str.find_first_not_of(' ');
53 
54  if (pos != std::string::npos)
55  str.erase(0, pos);
56  }
57  else
58  {
59  // There is nothing else but whitespace in the string
60  str.clear();
61  }
62  return str;
63 }

Referenced by getBoolFromString(), normalize(), parseBoolean(), replaceItemLinks(), splitToIntVector(), splitToStringSet(), and splitToStringVector().

◆ unpackList()

std::list<std::string> unpackList ( const std::string &  str)

Definition at line 604 of file stringutils.cpp.

605 {
606  return splitToStringList(str, '|');
607 }

References splitToStringList().

◆ urlJoin()

std::string urlJoin ( std::string  str1,
const std::string &  str2 
)

Definition at line 1129 of file stringutils.cpp.

1131 {
1132  const char sep = '/';
1133  std::string sepStr = "/";
1134 
1135  if (str1.empty())
1136  {
1137  if (str2[0] == sep)
1138  return str2;
1139  return sepStr.append(str2);
1140  }
1141  const size_t sz1 = str1.size();
1142  if (str2.empty())
1143  {
1144  if (str1[sz1 - 1] == sep)
1145  return str1;
1146  return str1.append(sepStr);
1147  }
1148  if (str1[sz1 - 1] == sep)
1149  {
1150  if (str2[0] == sep)
1151  return str1.append(str2.substr(1));
1152  return str1.append(str2);
1153  }
1154  else
1155  {
1156  if (str2[0] == sep)
1157  return str1.append(str2);
1158  return str1.append(sepStr).append(str2);
1159  }
1160 }

Referenced by UpdaterWindow::download().

anonymous_namespace{stringutils.cpp}::base
unsigned int base
Definition: stringutils.cpp:226
splitToStringList
std::list< std::string > splitToStringList(const std::string &text, const char separator)
Definition: stringutils.cpp:472
CAST_SIZE
#define CAST_SIZE
Definition: cast.h:33
anonymous_namespace{stringutils.cpp}::start
unsigned int start
Definition: stringutils.cpp:227
Actions::msg
bool msg(InputEvent &event)
Definition: chat.cpp:38
splitToStringVector
void splitToStringVector(StringVect &tokens, const std::string &text, const char separator)
Definition: stringutils.cpp:484
CAST_8
#define CAST_8
Definition: cast.h:24
StringVect
std::vector< std::string > StringVect
Definition: stringvector.h:28
CAST_U32
#define CAST_U32
Definition: cast.h:30
pathJoin
std::string pathJoin(std::string str1, const std::string &str2)
Definition: stringutils.cpp:1036
replaceRecursiveAll
void replaceRecursiveAll(std::string &context, const std::string &from, const char to)
Definition: stringutils.cpp:385
trim
std::string & trim(std::string &str)
Definition: stringutils.cpp:46
replaceAll
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)
Definition: stringutils.cpp:367
CAST_U8
#define CAST_U8
Definition: cast.h:26
strprintf
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
CAST_S8
#define CAST_S8
Definition: cast.h:25
data
uint32_t data
Definition: maptypeproperty2.h:3
ItemInfo
Definition: iteminfo.h:52
x
x
Definition: graphics_calcImageRect.hpp:72
UTF8_MAX_SIZE
static const size_t UTF8_MAX_SIZE
Definition: utf8.h:26
EmoteDB::size
int size()
Definition: emotedb.cpp:305
StringVectCIter
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:30
CAST_S32
#define CAST_S32
Definition: cast.h:29
ItemInfo::getId
int getId() const
Definition: iteminfo.h:67
toLower
std::string & toLower(std::string &str)
Definition: stringutils.cpp:65
ItemDB::get
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792
strStartWith
bool strStartWith(const std::string &str1, const std::string &str2)
Definition: stringutils.cpp:723
y
y
Definition: graphics_calcImageRect.hpp:72
N_
#define N_(s)
Definition: gettext.h:35
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Actions::url
bool url(InputEvent &event)
Definition: commands.cpp:63
Actions::itemInfo
bool itemInfo(InputEvent &event)
Definition: commands.cpp:104