Minetest  5.4.0
string.cpp File Reference
#include "string.h"
#include "pointer.h"
#include "numeric.h"
#include "log.h"
#include "hex.h"
#include "porting.h"
#include "translation.h"
#include <algorithm>
#include <array>
#include <sstream>
#include <iomanip>
#include <map>
#include <iconv.h>
+ Include dependency graph for string.cpp:

Classes

struct  ColorContainer
 

Functions

static bool parseHexColorString (const std::string &value, video::SColor &color, unsigned char default_alpha=0xff)
 
static bool parseNamedColorString (const std::string &value, video::SColor &color)
 
static bool convert (const char *to, const char *from, char *outbuf, size_t *outbuf_size, char *inbuf, size_t inbuf_size)
 
std::wstring utf8_to_wide (const std::string &input)
 
std::string wide_to_utf8 (const std::wstring &input)
 
wchar_t * utf8_to_wide_c (const char *str)
 
std::string urlencode (const std::string &str)
 
std::string urldecode (const std::string &str)
 
u32 readFlagString (std::string str, const FlagDesc *flagdesc, u32 *flagmask)
 
std::string writeFlagString (u32 flags, const FlagDesc *flagdesc, u32 flagmask)
 
size_t mystrlcpy (char *dst, const char *src, size_t size)
 
char * mystrtok_r (char *s, const char *sep, char **lasts)
 
u64 read_seed (const char *str)
 
bool parseColorString (const std::string &value, video::SColor &color, bool quiet, unsigned char default_alpha)
 
void str_replace (std::string &str, char from, char to)
 Replace all occurrences of the character from in str with to. More...
 
void translate_all (const std::wstring &s, size_t &i, Translations *translations, std::wstring &res)
 
void translate_string (const std::wstring &s, Translations *translations, const std::wstring &textdomain, size_t &i, std::wstring &res)
 
std::wstring translate_string (const std::wstring &s, Translations *translations)
 
std::wstring translate_string (const std::wstring &s)
 
std::string sanitizeDirName (const std::string &str, const std::string &optional_prefix)
 Sanitize the name of a new directory. More...
 

Variables

const char * DEFAULT_ENCODING = "WCHAR_T"
 
static const ColorContainer named_colors
 
static const std::array< std::wstring, 22 > disallowed_dir_names
 
static const std::wstring disallowed_path_chars = L"<>:\"/\\|?*."
 List of characters that are blacklisted from created directories. More...
 

Function Documentation

◆ convert()

static bool convert ( const char *  to,
const char *  from,
char *  outbuf,
size_t *  outbuf_size,
char *  inbuf,
size_t  inbuf_size 
)
static

Referenced by utf8_to_wide(), and wide_to_utf8().

+ Here is the caller graph for this function:

◆ mystrlcpy()

size_t mystrlcpy ( char *  dst,
const char *  src,
size_t  size 
)

References MYMIN.

◆ mystrtok_r()

char* mystrtok_r ( char *  s,
const char *  sep,
char **  lasts 
)

◆ parseColorString()

bool parseColorString ( const std::string &  value,
video::SColor &  color,
bool  quiet,
unsigned char  default_alpha 
)

References errorstream, parseHexColorString(), and parseNamedColorString().

Referenced by EnrichedString::addAtEnd(), check_color(), TextureSource::generateImagePart(), StyleSpec::getColor(), StyleSpec::getColorArray(), CItemDefManager::getItemstackColor(), ParsedText::globalTag(), GUIFormSpecMenu::parseBackgroundColor(), GUIFormSpecMenu::parseBox(), GUIFormSpecMenu::parseListColors(), GUIFormSpecMenu::parseTooltip(), read_color(), ParsedText::Element::setStyle(), GUITable::setTable(), and GUITable::setTextList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseHexColorString()

static bool parseHexColorString ( const std::string &  value,
video::SColor &  color,
unsigned char  default_alpha = 0xff 
)
static

References hex_digit_decode().

Referenced by parseColorString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseNamedColorString()

static bool parseNamedColorString ( const std::string &  value,
video::SColor &  color 
)
static

References ColorContainer::colors, hex_digit_decode(), lowercase(), and named_colors.

Referenced by parseColorString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_seed()

u64 read_seed ( const char *  str)

References murmur_hash_64_ua().

Referenced by MapgenParams::readParams().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readFlagString()

u32 readFlagString ( std::string  str,
const FlagDesc flagdesc,
u32 *  flagmask 
)

References FlagDesc::flag, and FlagDesc::name.

Referenced by Settings::getFlagStr(), read_flags(), and TestSettings::testFlagDesc().

+ Here is the caller graph for this function:

◆ sanitizeDirName()

std::string sanitizeDirName ( const std::string &  str,
const std::string &  optional_prefix 
)

Sanitize the name of a new directory.

This consists of two stages:

  1. Check for 'reserved filenames' that can't be used on some filesystems and add a prefix to them
  2. Remove 'unsafe' characters from the name by replacing them with '_'

References disallowed_dir_names, disallowed_path_chars, str_equal(), utf8_to_wide(), and wide_to_utf8().

Referenced by ModApiMainMenu::l_create_world().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ str_replace()

void str_replace ( std::string &  str,
char  from,
char  to 
)

Replace all occurrences of the character from in str with to.

Parameters
strThe string to (potentially) modify.
fromThe character in str to replace.
toThe replacement character.

Referenced by TextureSource::generateImagePart(), Client::initLocalMapSaving(), and TestUtilities::testStringReplace().

+ Here is the caller graph for this function:

◆ translate_all()

void translate_all ( const std::wstring &  s,
size_t &  i,
Translations translations,
std::wstring &  res 
)

References split(), and translate_string().

Referenced by translate_string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ translate_string() [1/3]

std::wstring translate_string ( const std::wstring &  s)

References g_client_translations, and translate_string().

+ Here is the call graph for this function:

◆ translate_string() [2/3]

std::wstring translate_string ( const std::wstring &  s,
Translations translations 
)

References translate_all().

Referenced by unescape_translate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ translate_string() [3/3]

void translate_string ( const std::wstring &  s,
Translations translations,
const std::wstring &  textdomain,
size_t &  i,
std::wstring &  res 
)

References errorstream, Translations::getTranslation(), split(), translate_all(), and wide_to_utf8().

Referenced by ChatBackend::addMessage(), Camera::drawNametags(), ModApiEnvMod::l_get_translated_string(), EnrichedString::operator=(), GUIFormSpecMenu::parseButton(), GUIFormSpecMenu::parseCheckbox(), GUIFormSpecMenu::parseHyperText(), GUIFormSpecMenu::parseLabel(), GUIFormSpecMenu::parsePwdField(), GUIFormSpecMenu::parseSimpleField(), GUIFormSpecMenu::parseTextArea(), GUIEngine::setTopleftText(), translate_all(), and translate_string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ urldecode()

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

References hex_digit_decode().

Referenced by TestUtilities::testUrlDecode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ urlencode()

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

Referenced by HTTPFetchOngoing::HTTPFetchOngoing(), and TestUtilities::testUrlEncode().

+ Here is the caller graph for this function:

◆ utf8_to_wide()

std::wstring utf8_to_wide ( const std::string &  input)

References convert(), DEFAULT_ENCODING, hex_encode(), infostream, and SANITY_CHECK.

Referenced by GUITable::allocString(), Game::createClient(), ProfilerGraph::draw(), drawItemStack(), Hud::drawLuaElements(), GUIFormSpecMenu::drawMenu(), Camera::drawNametags(), Game::getServerContent(), FontEngine::getTextWidth(), Server::handleChat(), Game::handlePointingAtNode(), Game::handlePointingAtObject(), GameUI::init(), ModApiServer::l_chat_send_all(), ModApiServer::l_chat_send_player(), ModApiClient::l_display_chat_message(), ModApiEnvMod::l_get_translated_string(), ModApiServer::l_kick_player(), ModApiClient::l_send_chat_message(), Translations::loadTranslation(), Client::makeScreenshot(), ChatPrompt::nickCompletion(), GUIFormSpecMenu::parseButton(), GUIFormSpecMenu::parseCheckbox(), GUIFormSpecMenu::parseDropDown(), GUIFormSpecMenu::parseHyperText(), GUIFormSpecMenu::parseImageButton(), GUIFormSpecMenu::parseItemImageButton(), GUIFormSpecMenu::parseLabel(), GUIFormSpecMenu::parsePwdField(), GUIFormSpecMenu::parseSimpleField(), GUIFormSpecMenu::parseTabHeader(), GUIFormSpecMenu::parseTable(), GUIFormSpecMenu::parseTextArea(), GUIFormSpecMenu::parseTextList(), GUIFormSpecMenu::parseTooltip(), GUIFormSpecMenu::parseVertLabel(), Server::printToConsoleOnly(), Server::ProcessData(), GUIConfirmRegistration::processInput(), Game::processKeyInput(), ClientLauncher::run(), sanitizeDirName(), GUIEngine::setTopleftText(), TestUtilities::testStrEqual(), TestUtilities::testUTF8(), TestUtilities::testWrapRows(), std::to_wstring(), Game::toggleMinimap(), GameUI::update(), Game::updateChat(), GameUI::updateProfiler(), utf8_to_stringw(), and utf8_to_wide_c().

+ Here is the call graph for this function:

◆ utf8_to_wide_c()

wchar_t* utf8_to_wide_c ( const char *  str)

References utf8_to_wide().

Referenced by GUIConfirmRegistration::regenerateGui(), and wgettext().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wide_to_utf8()

◆ writeFlagString()

std::string writeFlagString ( u32  flags,
const FlagDesc flagdesc,
u32  flagmask 
)

References FlagDesc::name.

Referenced by push_flags_string(), Settings::setDefault(), and Settings::setFlagStr().

+ Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_ENCODING

const char* DEFAULT_ENCODING = "WCHAR_T"

Referenced by utf8_to_wide(), and wide_to_utf8().

◆ disallowed_dir_names

const std::array<std::wstring, 22> disallowed_dir_names
static
Initial value:
= {
L"CON",
L"PRN",
L"AUX",
L"NUL",
L"COM1",
L"COM2",
L"COM3",
L"COM4",
L"COM5",
L"COM6",
L"COM7",
L"COM8",
L"COM9",
L"LPT1",
L"LPT2",
L"LPT3",
L"LPT4",
L"LPT5",
L"LPT6",
L"LPT7",
L"LPT8",
L"LPT9",
}

Referenced by sanitizeDirName().

◆ disallowed_path_chars

const std::wstring disallowed_path_chars = L"<>:\"/\\|?*."
static

List of characters that are blacklisted from created directories.

Referenced by sanitizeDirName().

◆ named_colors

const ColorContainer named_colors
static

Referenced by parseNamedColorString().