Colobot
Loading...
Searching...
No Matches
stringutils.h File Reference

Some useful string operations. More...

#include <cstddef>
#include <string>
#include <sstream>
Include dependency graph for stringutils.h:

Functions

template<class T>
std::string StrUtils::ToString (T value, bool *ok=nullptr)
 Converts a value to string.
template<class T>
StrUtils::FromString (const std::string &str, bool *ok=nullptr)
 Converts a value to string.
unsigned int StrUtils::HexStringToInt (const std::string &str)
 Converts string of hex characters to int.
std::string StrUtils::Format (const char *fmt,...)
 Replacement for sprintf().
std::string StrUtils::Replace (const std::string &str, const std::string &oldStr, const std::string &newStr)
 Returns a string with every occurence of oldStr in str replaced to newStr.
std::string StrUtils::UnicodeCharToUtf8 (unsigned int ch)
 Converts a wide Unicode char to a single UTF-8 encoded char.
std::string StrUtils::UnicodeStringToUtf8 (const std::wstring &str)
 Converts a wide Unicode string to a UTF-8 encoded string.
unsigned int StrUtils::Utf8CharToUnicode (const std::string &ch)
 Converts a UTF-8 encoded single character to wide Unicode char.
std::wstring StrUtils::Utf8StringToUnicode (const std::string &str)
 Converts a UTF-8 encoded string to wide Unicode string.
int StrUtils::Utf8CharSizeAt (const std::string &str, unsigned int pos)
 Returns the size in bytes of UTF-8 character at given pos in a UTF-8 str.
std::size_t StrUtils::Utf8StringLength (const std::string &str)
 Returns the length in characters of UTF-8 string str.
bool StrUtils::isUtf8ContinuationByte (char c)
 Returns true if char is continuation UTF-8 byte.

Detailed Description

Some useful string operations.

Function Documentation

◆ ToString()

template<class T>
std::string StrUtils::ToString ( T value,
bool * ok = nullptr )

Converts a value to string.

If given, ok is set to true/false on success/failure. Warning: To avoid unnecessary problems, always give full template qualifier e.g. ToString<int>

◆ FromString()

template<class T>
T StrUtils::FromString ( const std::string & str,
bool * ok = nullptr )

Converts a value to string.

If given, ok is set to true/false on success/failure. Warning: To avoid unnecessary problems, always give full template qualifier e.g. FromString<int>

◆ HexStringToInt()

unsigned int StrUtils::HexStringToInt ( const std::string & str)

Converts string of hex characters to int.

◆ Format()

std::string StrUtils::Format ( const char * fmt,
... )

Replacement for sprintf().

◆ Replace()

std::string StrUtils::Replace ( const std::string & str,
const std::string & oldStr,
const std::string & newStr )

Returns a string with every occurence of oldStr in str replaced to newStr.

◆ UnicodeCharToUtf8()

std::string StrUtils::UnicodeCharToUtf8 ( unsigned int ch)

Converts a wide Unicode char to a single UTF-8 encoded char.

◆ UnicodeStringToUtf8()

std::string StrUtils::UnicodeStringToUtf8 ( const std::wstring & str)

Converts a wide Unicode string to a UTF-8 encoded string.

◆ Utf8CharToUnicode()

unsigned int StrUtils::Utf8CharToUnicode ( const std::string & ch)

Converts a UTF-8 encoded single character to wide Unicode char.

◆ Utf8StringToUnicode()

std::wstring StrUtils::Utf8StringToUnicode ( const std::string & str)

Converts a UTF-8 encoded string to wide Unicode string.

◆ Utf8CharSizeAt()

int StrUtils::Utf8CharSizeAt ( const std::string & str,
unsigned int pos )

Returns the size in bytes of UTF-8 character at given pos in a UTF-8 str.

◆ Utf8StringLength()

std::size_t StrUtils::Utf8StringLength ( const std::string & str)

Returns the length in characters of UTF-8 string str.

◆ isUtf8ContinuationByte()

bool StrUtils::isUtf8ContinuationByte ( char c)

Returns true if char is continuation UTF-8 byte.