Mana
Loading...
Searching...
No Matches
Functions
stringutils.cpp File Reference
#include "utils/stringutils.h"
#include <cstring>
#include <algorithm>
#include <cstdarg>
#include <cstdio>

Go to the source code of this file.

Functions

std::string & trim (std::string &str)
 Trims spaces off the end and the beginning of the given string.
 
std::string & toLower (std::string &str)
 Converts the given string to lower case.
 
std::string & toUpper (std::string &str)
 Converts the given string to upper case.
 
unsigned int atox (const std::string &str)
 Converts an ascii hexidecimal string to an integer.
 
const char * ipToString (int address)
 Converts the given IP address to a string.
 
std::string strprintf (char const *format,...)
 A safe version of sprintf that returns a std::string of the result.
 
std::string & replaceCharacters (std::string &str, std::string_view chars, char replacement)
 Replaces a set of characters with another character.
 
std::string & removeColors (std::string &msg)
 Removes colors from a string.
 
bool isWordSeparator (char chr)
 Tells wether the character is a word separator.
 
std::string findSameSubstring (const std::string &str1, const std::string &str2)
 
bool getBoolFromString (std::string text, bool def)
 Returns a bool value depending on the given string value.
 
void fromString (const char *str, std::vector< int > &value)
 
std::string autocomplete (const std::vector< std::string > &candidates, std::string base)
 Returns the most approaching string of base from candidates.
 
std::string normalize (const std::string &name)
 Normalize a string, which means lowercase and trim it.
 
std::string getDirectoryFromURL (const std::string &url)
 Derives a directory from the given URL, stripping the schema and replacing certain invalid characters.
 
std::string join (const std::vector< std::string > &strings, const char *separator)
 Joins a vector of strings into one string, separated by the given separator.
 

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 60 of file stringutils.cpp.

◆ autocomplete()

std::string autocomplete ( const std::vector< std::string > &  candidates,
std::string  base 
)

Returns the most approaching string of base from candidates.

Definition at line 181 of file stringutils.cpp.

◆ findSameSubstring()

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

Definition at line 130 of file stringutils.cpp.

◆ fromString()

void fromString ( const char *  str,
std::vector< int > &  value 
)

Definition at line 156 of file stringutils.cpp.

◆ getBoolFromString()

bool getBoolFromString ( std::string  text,
bool  def = false 
)

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 144 of file stringutils.cpp.

◆ getDirectoryFromURL()

std::string getDirectoryFromURL ( const std::string &  url)

Derives a directory from the given URL, stripping the schema and replacing certain invalid characters.

i.e.: http://www.manasource.org:9601/updates/ -> www.manasource.org_9601/updates/

Definition at line 222 of file stringutils.cpp.

◆ ipToString()

const char * ipToString ( int  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 68 of file stringutils.cpp.

◆ isWordSeparator()

bool isWordSeparator ( char  chr)

Tells wether the character is a word separator.

Definition at line 125 of file stringutils.cpp.

◆ join()

std::string join ( const std::vector< std::string > &  strings,
const char *  separator 
)

Joins a vector of strings into one string, separated by the given separator.

Definition at line 245 of file stringutils.cpp.

◆ normalize()

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

Normalize a string, which means lowercase and trim it.

Definition at line 216 of file stringutils.cpp.

◆ removeColors()

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

Removes colors from a string.

Parameters
msgthe string to remove the colors from
Returns
reference to the modified string

Definition at line 114 of file stringutils.cpp.

◆ replaceCharacters()

std::string & replaceCharacters ( std::string &  str,
std::string_view  chars,
char  replacement = '_' 
)

Replaces a set of characters with another character.

Parameters
strthe string to remove the bad chars from
charsthe bad characters to remove
replacementthe character to replace the bad chars with
Returns
a reference to the string without bad chars

Definition at line 102 of file stringutils.cpp.

◆ strprintf()

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

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

Definition at line 81 of file stringutils.cpp.

◆ 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 48 of file stringutils.cpp.

◆ 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 54 of file stringutils.cpp.

◆ 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 29 of file stringutils.cpp.