OpenXcom  1.0
Open-source clone of the original X-Com
Functions | Variables
OpenXcom::Unicode Namespace Reference

Functions for dealing with encoding, strings, text and all related operations. More...

Functions

void getUtf8Locale ()
 Store a UTF-8 locale to use when dealing with character conversions. More...
 
UString convUtf8ToUtf32 (const std::string &src)
 Takes a Unicode 32-bit string and converts it to a 8-bit string encoded in UTF-8. More...
 
std::string convUtf32ToUtf8 (const UString &src)
 Takes a Unicode 32-bit string and converts it to a 8-bit string encoded in UTF-8. More...
 
std::string convWcToMb (const std::wstring &src, unsigned int cp)
 Takes a wide-character string and converts it to a multibyte 8-bit string in a given encoding. More...
 
std::wstring convMbToWc (const std::string &src, unsigned int cp)
 Takes a multibyte 8-bit string in a given encoding and converts it to a wide-character string. More...
 
std::string convPathToUtf8 (const std::string &src)
 Takes a filesystem path and converts it to a UTF-8 string. More...
 
std::string convUtf8ToPath (const std::string &src)
 Takes a UTF-8 string and converts it to a filesystem path. More...
 
bool naturalCompare (const std::string &a, const std::string &b)
 Compares two UTF-8 strings using natural human ordering. More...
 
bool caseCompare (const std::string &a, const std::string &b)
 Compares two UTF-8 strings ignoring case. More...
 
bool caseFind (const std::string &haystack, const std::string &needle)
 Searches for a substring in another string ignoring case. More...
 
void upperCase (std::string &s)
 Uppercases a UTF-8 string, modified in place. More...
 
void lowerCase (std::string &s)
 Lowercases a UTF-8 string, modified in place. More...
 
void replace (std::string &str, const std::string &find, const std::string &replace)
 Replaces every instance of a substring. More...
 
std::string formatNumber (int64_t value, const std::string &currency)
 Takes an integer value and formats it as number with separators (spacing the thousands). More...
 
std::string formatFunding (int64_t funds)
 Takes an integer value and formats it as currency, spacing the thousands and adding a $ sign to the front. More...
 
std::string formatPercentage (int value)
 Takes an integer value and formats it as percentage, adding a % sign. More...
 
bool isLinebreak (UCode c)
 non-breaking space More...
 
bool isSpace (UCode c)
 Checks if a character is a blank space (includes non-breaking spaces).
 
bool isSeparator (UCode c)
 Checks if a character is a word separator.
 
bool isPrintable (UCode c)
 Checks if a character is visible to the user.
 

Variables

const char TOK_COLOR_FLIP = 1
 line break and change to small font
 
const unsigned char TOK_NBSP = 0xA0
 alternate between primary and secondary color
 

Detailed Description

Functions for dealing with encoding, strings, text and all related operations.

Function Documentation

◆ caseCompare()

bool OpenXcom::Unicode::caseCompare ( const std::string &  a,
const std::string &  b 
)

Compares two UTF-8 strings ignoring case.

Compares two strings case-insensitive.

Parameters
aString A.
bString B.
Returns
String A comes before String B.

◆ caseFind()

bool OpenXcom::Unicode::caseFind ( const std::string &  haystack,
const std::string &  needle 
)

Searches for a substring in another string ignoring case.

Find a string in another case-insensitive.

Parameters
haystackString to search.
needleString to find.
Returns
True if the needle is in the haystack.

◆ convMbToWc()

std::wstring OpenXcom::Unicode::convMbToWc ( const std::string &  src,
unsigned int  cp 
)

Takes a multibyte 8-bit string in a given encoding and converts it to a wide-character string.

Used for Win32 APIs.

Parameters
srcMultibyte string.
cpCodepage of the source string.
Returns
Wide-character string.

◆ convPathToUtf8()

std::string OpenXcom::Unicode::convPathToUtf8 ( const std::string &  src)

Takes a filesystem path and converts it to a UTF-8 string.

Converts a path to a UTF-8 string.

On Windows the C paths use the local ANSI codepage. Used for SDL APIs.

Parameters
srcFilesystem path.
Returns
UTF-8 string.

◆ convUtf32ToUtf8()

std::string OpenXcom::Unicode::convUtf32ToUtf8 ( const UString &  src)

Takes a Unicode 32-bit string and converts it to a 8-bit string encoded in UTF-8.

Converts a UTF-32 string to UTF-8.

Used for rendering text.

Note
Adapted from https://stackoverflow.com/a/148766/2683561
Parameters
srcUnicode string.
Returns
UTF-8 string.

◆ convUtf8ToPath()

std::string OpenXcom::Unicode::convUtf8ToPath ( const std::string &  src)

Takes a UTF-8 string and converts it to a filesystem path.

Converts a UTF-8 string to a path.

On Windows the C paths use the local ANSI codepage. Used for SDL APIs.

Parameters
srcUTF-8 string.
Returns
Filesystem path.

◆ convUtf8ToUtf32()

UString OpenXcom::Unicode::convUtf8ToUtf32 ( const std::string &  src)

Takes a Unicode 32-bit string and converts it to a 8-bit string encoded in UTF-8.

Converts a UTF-8 string to UTF-32.

Used for rendering text.

Note
Adapted from https://stackoverflow.com/a/148766/2683561
Parameters
srcUTF-8 string.
Returns
Unicode string.

◆ convWcToMb()

std::string OpenXcom::Unicode::convWcToMb ( const std::wstring &  src,
unsigned int  cp 
)

Takes a wide-character string and converts it to a multibyte 8-bit string in a given encoding.

Used for Win32 APIs.

Parameters
srcWide-character string.
cpCodepage of the destination string.
Returns
Multibyte string.

◆ formatFunding()

std::string OpenXcom::Unicode::formatFunding ( int64_t  funds)

Takes an integer value and formats it as currency, spacing the thousands and adding a $ sign to the front.

Formats an integer value as currency.

Parameters
fundsThe funding value.
Returns
The formatted string.

◆ formatNumber()

std::string OpenXcom::Unicode::formatNumber ( int64_t  value,
const std::string &  currency 
)

Takes an integer value and formats it as number with separators (spacing the thousands).

Formats an integer value as number with separators.

Parameters
valueThe value.
currencyCurrency symbol.
Returns
The formatted string.

◆ formatPercentage()

std::string OpenXcom::Unicode::formatPercentage ( int  value)

Takes an integer value and formats it as percentage, adding a % sign.

Formats an integer value as percentage.

Parameters
valueThe percentage value.
Returns
The formatted string.

◆ getUtf8Locale()

void OpenXcom::Unicode::getUtf8Locale ( )

Store a UTF-8 locale to use when dealing with character conversions.

Find a UTF-8 locale.

Windows doesn't have a UTF-8 locale so we just use its APIs directly.

◆ isLinebreak()

bool OpenXcom::Unicode::isLinebreak ( UCode  c)
inline

non-breaking space

Checks if a character is a linebreak.

◆ lowerCase()

void OpenXcom::Unicode::lowerCase ( std::string &  s)

Lowercases a UTF-8 string, modified in place.

Lowercases a string in place.

Used for case-insensitive comparisons.

Parameters
sSource string.

◆ naturalCompare()

bool OpenXcom::Unicode::naturalCompare ( const std::string &  a,
const std::string &  b 
)

Compares two UTF-8 strings using natural human ordering.

Compares two strings by natural order.

Parameters
aString A.
bString B.
Returns
String A comes before String B.

◆ replace()

void OpenXcom::Unicode::replace ( std::string &  str,
const std::string &  find,
const std::string &  replace 
)

Replaces every instance of a substring.

Replaces a substring.

Parameters
strThe string to modify.
findThe substring to find.
replaceThe substring to replace it with.

◆ upperCase()

void OpenXcom::Unicode::upperCase ( std::string &  s)

Uppercases a UTF-8 string, modified in place.

Uppercases a string in place.

Used for case-insensitive comparisons.

Parameters
sSource string.