mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Merge pull request #13270 from unknownbrackets/headers2
More header cleanups
This commit is contained in:
commit
c45b6c5ac6
36 changed files with 245 additions and 312 deletions
|
@ -16,6 +16,9 @@
|
|||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#if PPSSPP_ARCH(ARM) || PPSSPP_ARCH(ARM64)
|
||||
|
||||
#include <ctype.h>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#endif
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "base/NativeApp.h"
|
||||
#include "file/ini_file.h"
|
||||
#include "input/input_state.h"
|
||||
|
@ -916,7 +917,7 @@ void LoadFromIni(IniFile &file) {
|
|||
return;
|
||||
}
|
||||
|
||||
IniFile::Section *controls = file.GetOrCreateSection("ControlMapping");
|
||||
Section *controls = file.GetOrCreateSection("ControlMapping");
|
||||
for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) {
|
||||
std::string value;
|
||||
controls->Get(psp_button_names[i].name, &value, "");
|
||||
|
@ -943,7 +944,7 @@ void LoadFromIni(IniFile &file) {
|
|||
}
|
||||
|
||||
void SaveToIni(IniFile &file) {
|
||||
IniFile::Section *controls = file.GetOrCreateSection("ControlMapping");
|
||||
Section *controls = file.GetOrCreateSection("ControlMapping");
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) {
|
||||
std::vector<KeyDef> keys;
|
||||
|
|
|
@ -185,14 +185,14 @@ void LogManager::ChangeFileLog(const char *filename) {
|
|||
}
|
||||
}
|
||||
|
||||
void LogManager::SaveConfig(IniFile::Section *section) {
|
||||
void LogManager::SaveConfig(Section *section) {
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) {
|
||||
section->Set((std::string(log_[i].m_shortName) + "Enabled").c_str(), log_[i].enabled);
|
||||
section->Set((std::string(log_[i].m_shortName) + "Level").c_str(), (int)log_[i].level);
|
||||
}
|
||||
}
|
||||
|
||||
void LogManager::LoadConfig(IniFile::Section *section, bool debugDefaults) {
|
||||
void LogManager::LoadConfig(Section *section, bool debugDefaults) {
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) {
|
||||
bool enabled = false;
|
||||
int level = 0;
|
||||
|
|
|
@ -180,6 +180,6 @@ public:
|
|||
|
||||
void ChangeFileLog(const char *filename);
|
||||
|
||||
void SaveConfig(IniFile::Section *section);
|
||||
void LoadConfig(IniFile::Section *section, bool debugDefaults);
|
||||
void SaveConfig(Section *section);
|
||||
void LoadConfig(Section *section, bool debugDefaults);
|
||||
};
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
#include "base/display.h"
|
||||
#include "base/NativeApp.h"
|
||||
|
@ -202,7 +203,7 @@ struct ConfigSetting {
|
|||
return type_ != TYPE_TERMINATOR;
|
||||
}
|
||||
|
||||
bool Get(IniFile::Section *section) {
|
||||
bool Get(Section *section) {
|
||||
switch (type_) {
|
||||
case TYPE_BOOL:
|
||||
if (cb_.b) {
|
||||
|
@ -255,7 +256,7 @@ struct ConfigSetting {
|
|||
}
|
||||
}
|
||||
|
||||
void Set(IniFile::Section *section) {
|
||||
void Set(Section *section) {
|
||||
if (!save_)
|
||||
return;
|
||||
|
||||
|
@ -1107,9 +1108,9 @@ static ConfigSectionSettings sections[] = {
|
|||
{"Theme", themeSettings},
|
||||
};
|
||||
|
||||
static void IterateSettings(IniFile &iniFile, std::function<void(IniFile::Section *section, ConfigSetting *setting)> func) {
|
||||
static void IterateSettings(IniFile &iniFile, std::function<void(Section *section, ConfigSetting *setting)> func) {
|
||||
for (size_t i = 0; i < ARRAY_SIZE(sections); ++i) {
|
||||
IniFile::Section *section = iniFile.GetOrCreateSection(sections[i].section);
|
||||
Section *section = iniFile.GetOrCreateSection(sections[i].section);
|
||||
for (auto setting = sections[i].settings; setting->HasMore(); ++setting) {
|
||||
func(section, setting);
|
||||
}
|
||||
|
@ -1146,8 +1147,8 @@ std::map<std::string, std::pair<std::string, int>> GetLangValuesMapping() {
|
|||
langCodeMapping["CHINESE_TRADITIONAL"] = PSP_SYSTEMPARAM_LANGUAGE_CHINESE_TRADITIONAL;
|
||||
langCodeMapping["CHINESE_SIMPLIFIED"] = PSP_SYSTEMPARAM_LANGUAGE_CHINESE_SIMPLIFIED;
|
||||
|
||||
IniFile::Section *langRegionNames = mapping.GetOrCreateSection("LangRegionNames");
|
||||
IniFile::Section *systemLanguage = mapping.GetOrCreateSection("SystemLanguage");
|
||||
Section *langRegionNames = mapping.GetOrCreateSection("LangRegionNames");
|
||||
Section *systemLanguage = mapping.GetOrCreateSection("SystemLanguage");
|
||||
|
||||
for (size_t i = 0; i < keys.size(); i++) {
|
||||
std::string langName;
|
||||
|
@ -1186,7 +1187,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
|
|||
// Continue anyway to initialize the config.
|
||||
}
|
||||
|
||||
IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) {
|
||||
IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) {
|
||||
setting->Get(section);
|
||||
});
|
||||
|
||||
|
@ -1194,7 +1195,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
|
|||
if (!File::Exists(currentDirectory))
|
||||
currentDirectory = "";
|
||||
|
||||
IniFile::Section *log = iniFile.GetOrCreateSection(logSectionName);
|
||||
Section *log = iniFile.GetOrCreateSection(logSectionName);
|
||||
|
||||
bool debugDefaults = false;
|
||||
#ifdef _DEBUG
|
||||
|
@ -1202,7 +1203,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
|
|||
#endif
|
||||
LogManager::GetInstance()->LoadConfig(log, debugDefaults);
|
||||
|
||||
IniFile::Section *recent = iniFile.GetOrCreateSection("Recent");
|
||||
Section *recent = iniFile.GetOrCreateSection("Recent");
|
||||
recent->Get("MaxRecent", &iMaxRecent, 30);
|
||||
|
||||
// Fix issue from switching from uint (hex in .ini) to int (dec)
|
||||
|
@ -1248,7 +1249,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
|
|||
}
|
||||
|
||||
// Check for an old dpad setting
|
||||
IniFile::Section *control = iniFile.GetOrCreateSection("Control");
|
||||
Section *control = iniFile.GetOrCreateSection("Control");
|
||||
float f;
|
||||
control->Get("DPadRadius", &f, 0.0f);
|
||||
if (f > 0.0f) {
|
||||
|
@ -1337,13 +1338,13 @@ void Config::Save(const char *saveReason) {
|
|||
// Need to do this somewhere...
|
||||
bFirstRun = false;
|
||||
|
||||
IterateSettings(iniFile, [&](IniFile::Section *section, ConfigSetting *setting) {
|
||||
IterateSettings(iniFile, [&](Section *section, ConfigSetting *setting) {
|
||||
if (!bGameSpecific || !setting->perGame_) {
|
||||
setting->Set(section);
|
||||
}
|
||||
});
|
||||
|
||||
IniFile::Section *recent = iniFile.GetOrCreateSection("Recent");
|
||||
Section *recent = iniFile.GetOrCreateSection("Recent");
|
||||
recent->Set("MaxRecent", iMaxRecent);
|
||||
|
||||
for (int i = 0; i < iMaxRecent; i++) {
|
||||
|
@ -1356,7 +1357,7 @@ void Config::Save(const char *saveReason) {
|
|||
}
|
||||
}
|
||||
|
||||
IniFile::Section *pinnedPaths = iniFile.GetOrCreateSection("PinnedPaths");
|
||||
Section *pinnedPaths = iniFile.GetOrCreateSection("PinnedPaths");
|
||||
pinnedPaths->Clear();
|
||||
for (size_t i = 0; i < vPinnedPaths.size(); ++i) {
|
||||
char keyName[64];
|
||||
|
@ -1365,17 +1366,17 @@ void Config::Save(const char *saveReason) {
|
|||
}
|
||||
|
||||
if (!bGameSpecific) {
|
||||
IniFile::Section *postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting");
|
||||
Section *postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting");
|
||||
postShaderSetting->Clear();
|
||||
for (auto it = mPostShaderSetting.begin(), end = mPostShaderSetting.end(); it != end; ++it) {
|
||||
postShaderSetting->Set(it->first.c_str(), it->second);
|
||||
}
|
||||
}
|
||||
|
||||
IniFile::Section *control = iniFile.GetOrCreateSection("Control");
|
||||
Section *control = iniFile.GetOrCreateSection("Control");
|
||||
control->Delete("DPadRadius");
|
||||
|
||||
IniFile::Section *log = iniFile.GetOrCreateSection(logSectionName);
|
||||
Section *log = iniFile.GetOrCreateSection(logSectionName);
|
||||
if (LogManager::GetInstance())
|
||||
LogManager::GetInstance()->SaveConfig(log);
|
||||
|
||||
|
@ -1613,16 +1614,16 @@ bool Config::saveGameConfig(const std::string &pGameId, const std::string &title
|
|||
|
||||
IniFile iniFile;
|
||||
|
||||
IniFile::Section *top = iniFile.GetOrCreateSection("");
|
||||
Section *top = iniFile.GetOrCreateSection("");
|
||||
top->AddComment(StringFromFormat("Game config for %s - %s", pGameId.c_str(), title.c_str()));
|
||||
|
||||
IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) {
|
||||
IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) {
|
||||
if (setting->perGame_) {
|
||||
setting->Set(section);
|
||||
}
|
||||
});
|
||||
|
||||
IniFile::Section *postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting");
|
||||
Section *postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting");
|
||||
postShaderSetting->Clear();
|
||||
for (auto it = mPostShaderSetting.begin(), end = mPostShaderSetting.end(); it != end; ++it) {
|
||||
postShaderSetting->Set(it->first.c_str(), it->second);
|
||||
|
@ -1652,7 +1653,7 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title
|
|||
mPostShaderSetting[it.first] = std::stof(it.second);
|
||||
}
|
||||
|
||||
IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) {
|
||||
IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) {
|
||||
if (setting->perGame_) {
|
||||
setting->Get(section);
|
||||
}
|
||||
|
@ -1670,7 +1671,7 @@ void Config::unloadGameConfig() {
|
|||
iniFile.Load(iniFilename_);
|
||||
|
||||
// Reload game specific settings back to standard.
|
||||
IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) {
|
||||
IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) {
|
||||
if (setting->perGame_) {
|
||||
setting->Get(section);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include "util/text/parsers.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <thread>
|
||||
|
||||
#include "base/stringutil.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "thread/threadutil.h"
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include "base/stringutil.h"
|
||||
#include "file/free.h"
|
||||
#include "file/zip_read.h"
|
||||
#include "i18n/i18n.h"
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <mutex>
|
||||
|
||||
#include "base/timeutil.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "thread/threadutil.h"
|
||||
#include "util/text/parsers.h"
|
||||
|
|
|
@ -22,9 +22,11 @@
|
|||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include "base/stringutil.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "ext/xxhash.h"
|
||||
#include "file/ini_file.h"
|
||||
#include "util/text/parsers.h"
|
||||
#include "Common/ColorConv.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Core/Config.h"
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
#include "file/file_util.h"
|
||||
|
@ -29,6 +30,7 @@
|
|||
#include "ext/libzip/zip.h"
|
||||
#endif
|
||||
#include "util/text/utf8.h"
|
||||
#include "file/ini_file.h"
|
||||
|
||||
#include "Common/Log.h"
|
||||
#include "Common/FileUtil.h"
|
||||
|
|
|
@ -103,7 +103,7 @@ void LoadPostShaderInfo(const std::vector<std::string> &directories) {
|
|||
|
||||
// Alright, let's loop through the sections and see if any is a shader.
|
||||
for (size_t i = 0; i < ini.Sections().size(); i++) {
|
||||
IniFile::Section §ion = ini.Sections()[i];
|
||||
Section §ion = ini.Sections()[i];
|
||||
std::string shaderType;
|
||||
section.Get("Type", &shaderType, "render");
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <map>
|
||||
#include "gfx/d3d9_shader.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "math/lin/matrix4x4.h"
|
||||
#include "math/math_util.h"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
#include "profiler/profiler.h"
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "base/stringutil.h"
|
||||
#include "ext/cityhash/city.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "ui/ui.h"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include "base/display.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "gfx_es2/gpu_features.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "ui/ui_context.h"
|
||||
|
|
|
@ -44,8 +44,9 @@
|
|||
#endif
|
||||
|
||||
#include "base/display.h"
|
||||
#include "base/timeutil.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "base/timeutil.h"
|
||||
#include "base/NativeApp.h"
|
||||
#include "file/vfs.h"
|
||||
#include "file/zip_read.h"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include "base/stringutil.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "gfx_es2/draw_buffer.h"
|
||||
#include "ui/view.h"
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <netfw.h>
|
||||
#endif
|
||||
|
||||
#include "base/stringutil.h"
|
||||
#include "base/timeutil.h"
|
||||
#include "file/path.h"
|
||||
// TODO: For text align flags, probably shouldn't be in gfx_es2/...
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/display.h"
|
||||
#include "base/stringutil.h"
|
||||
// TODO: For text align flags, probably shouldn't be in gfx_es2/...
|
||||
#include "gfx_es2/draw_buffer.h"
|
||||
#include "i18n/i18n.h"
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <functional>
|
||||
|
||||
#include "base/colorutil.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "base/timeutil.h"
|
||||
#include "gfx_es2/draw_buffer.h"
|
||||
#include "i18n/i18n.h"
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "base/stringutil.h"
|
||||
#include "util/text/parsers.h"
|
||||
#include "Common/ColorConv.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Core/Screenshot.h"
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "base/display.h"
|
||||
#include "base/NativeApp.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "base/timeutil.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "input/input_state.h"
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "CommonWindows.h"
|
||||
#include <shellapi.h>
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#include "base/stringutil.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "util/text/utf8.h"
|
||||
#include "base/NativeApp.h"
|
||||
|
|
|
@ -31,8 +31,9 @@
|
|||
#include <ShlObj.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
#include "base/NativeApp.h"
|
||||
#include "base/display.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "base/NativeApp.h"
|
||||
#include "file/vfs.h"
|
||||
#include "file/zip_read.h"
|
||||
#include "i18n/i18n.h"
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
#include <errno.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
@ -22,8 +22,6 @@
|
|||
#include "base/stringutil.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
// Function Cross-Compatibility
|
||||
#define strcasecmp _stricmp
|
||||
|
||||
void OutputDebugStringUTF8(const char *p) {
|
||||
wchar_t temp[4096];
|
||||
|
@ -84,46 +82,6 @@ void StringUpper(char *str, int len) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned int parseHex(const char *_szValue)
|
||||
{
|
||||
int Value = 0;
|
||||
size_t Finish = strlen(_szValue);
|
||||
if (Finish > 8 ) { Finish = 8; }
|
||||
|
||||
for (size_t Count = 0; Count < Finish; Count++) {
|
||||
Value = (Value << 4);
|
||||
switch( _szValue[Count] ) {
|
||||
case '0': break;
|
||||
case '1': Value += 1; break;
|
||||
case '2': Value += 2; break;
|
||||
case '3': Value += 3; break;
|
||||
case '4': Value += 4; break;
|
||||
case '5': Value += 5; break;
|
||||
case '6': Value += 6; break;
|
||||
case '7': Value += 7; break;
|
||||
case '8': Value += 8; break;
|
||||
case '9': Value += 9; break;
|
||||
case 'A': Value += 10; break;
|
||||
case 'a': Value += 10; break;
|
||||
case 'B': Value += 11; break;
|
||||
case 'b': Value += 11; break;
|
||||
case 'C': Value += 12; break;
|
||||
case 'c': Value += 12; break;
|
||||
case 'D': Value += 13; break;
|
||||
case 'd': Value += 13; break;
|
||||
case 'E': Value += 14; break;
|
||||
case 'e': Value += 14; break;
|
||||
case 'F': Value += 15; break;
|
||||
case 'f': Value += 15; break;
|
||||
default:
|
||||
Value = (Value >> 4);
|
||||
Count = Finish;
|
||||
}
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
|
||||
void DataToHexString(const uint8_t *data, size_t size, std::string *output) {
|
||||
Buffer buffer;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
|
@ -223,49 +181,6 @@ std::string ArrayToString(const uint8_t *data, uint32_t size, int line_len, bool
|
|||
return oss.str();
|
||||
}
|
||||
|
||||
bool TryParse(const std::string &str, uint32_t *const output)
|
||||
{
|
||||
char *endptr = NULL;
|
||||
|
||||
// Holy crap this is ugly.
|
||||
|
||||
// Reset errno to a value other than ERANGE
|
||||
errno = 0;
|
||||
|
||||
unsigned long value = strtoul(str.c_str(), &endptr, 0);
|
||||
|
||||
if (!endptr || *endptr)
|
||||
return false;
|
||||
|
||||
if (errno == ERANGE)
|
||||
return false;
|
||||
|
||||
if (ULONG_MAX > UINT_MAX) {
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable:4309)
|
||||
#endif
|
||||
// Note: The typecasts avoid GCC warnings when long is 32 bits wide.
|
||||
if (value >= static_cast<unsigned long>(0x100000000ull)
|
||||
&& value <= static_cast<unsigned long>(0xFFFFFFFF00000000ull))
|
||||
return false;
|
||||
}
|
||||
|
||||
*output = static_cast<uint32_t>(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TryParse(const std::string &str, bool *const output)
|
||||
{
|
||||
if ("1" == str || !strcasecmp("true", str.c_str()))
|
||||
*output = true;
|
||||
else if ("0" == str || !strcasecmp("false", str.c_str()))
|
||||
*output = false;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SplitString(const std::string& str, const char delim, std::vector<std::string>& output)
|
||||
{
|
||||
size_t next = 0;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
|
@ -9,6 +8,7 @@
|
|||
#ifdef _MSC_VER
|
||||
#pragma warning (disable:4996)
|
||||
#define strncasecmp _strnicmp
|
||||
#define strcasecmp _stricmp
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
@ -37,7 +37,7 @@ inline bool startsWith(const std::string &str, const std::string &what) {
|
|||
inline bool endsWith(const std::string &str, const std::string &what) {
|
||||
if (str.size() < what.size())
|
||||
return false;
|
||||
return str.substr(str.size() - what.size()) == what;
|
||||
return str.substr(str.size() - what.size()) == what;
|
||||
}
|
||||
|
||||
// Only use on strings where you're only concerned about ASCII.
|
||||
|
@ -56,13 +56,9 @@ inline bool endsWithNoCase(const std::string &str, const std::string &what) {
|
|||
|
||||
void DataToHexString(const uint8_t *data, size_t size, std::string *output);
|
||||
inline void StringToHexString(const std::string &data, std::string *output) {
|
||||
DataToHexString((uint8_t *)(&data[0]), data.size(), output);
|
||||
DataToHexString((uint8_t *)(&data[0]), data.size(), output);
|
||||
}
|
||||
|
||||
|
||||
// highly unsafe and not recommended.
|
||||
unsigned int parseHex(const char* _szValue);
|
||||
|
||||
std::string StringFromFormat(const char* format, ...);
|
||||
std::string StringFromInt(int value);
|
||||
std::string StringFromBool(bool value);
|
||||
|
@ -72,23 +68,6 @@ std::string ArrayToString(const uint8_t *data, uint32_t size, int line_len = 20,
|
|||
std::string StripSpaces(const std::string &s);
|
||||
std::string StripQuotes(const std::string &s);
|
||||
|
||||
bool TryParse(const std::string &str, bool *const output);
|
||||
bool TryParse(const std::string &str, uint32_t *const output);
|
||||
|
||||
template <typename N>
|
||||
static bool TryParse(const std::string &str, N *const output)
|
||||
{
|
||||
std::istringstream iss(str);
|
||||
|
||||
N tmp = 0;
|
||||
if (iss >> tmp)
|
||||
{
|
||||
*output = tmp;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
void SplitString(const std::string& str, const char delim, std::vector<std::string>& output);
|
||||
|
||||
void GetQuotedStrings(const std::string& str, std::vector<std::string>& output);
|
||||
|
@ -98,14 +77,6 @@ std::string ReplaceAll(std::string input, const std::string& src, const std::str
|
|||
// Compare two strings, ignore the difference between the ignorestr1 and the ignorestr2 in str1 and str2.
|
||||
int strcmpIgnore(std::string str1, std::string str2, std::string ignorestr1, std::string ignorestr2);
|
||||
|
||||
template <typename N>
|
||||
static std::string ValueToString(const N value)
|
||||
{
|
||||
std::stringstream string;
|
||||
string << value;
|
||||
return string.str();
|
||||
}
|
||||
|
||||
void StringTrimEndNonAlphaNum(char *str);
|
||||
void SkipSpace(const char **ptr);
|
||||
void StringUpper(char *str);
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <direct.h>
|
||||
#ifndef strcasecmp
|
||||
#define strcasecmp _stricmp
|
||||
#endif
|
||||
#else
|
||||
#include <strings.h>
|
||||
#include <dirent.h>
|
||||
|
@ -23,6 +20,7 @@
|
|||
|
||||
#include "base/logging.h"
|
||||
#include "base/basictypes.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "file/file_util.h"
|
||||
#include "util/text/utf8.h"
|
||||
|
||||
|
|
|
@ -2,28 +2,28 @@
|
|||
// Taken from Dolphin but relicensed by me, Henrik Rydgard, under the MIT
|
||||
// license as I wrote the whole thing originally and it has barely changed.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "file/ini_file.h"
|
||||
#include "file/vfs.h"
|
||||
#include "util/text/parsers.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../util/text/utf8.h"
|
||||
// Function Cross-Compatibility
|
||||
#define strcasecmp _stricmp
|
||||
#include "util/text/utf8.h"
|
||||
#endif
|
||||
|
||||
static bool ParseLineKey(const std::string &line, size_t &pos, std::string *keyOut) {
|
||||
|
@ -148,11 +148,11 @@ static std::string EscapeComments(const std::string &value) {
|
|||
return result;
|
||||
}
|
||||
|
||||
void IniFile::Section::Clear() {
|
||||
void Section::Clear() {
|
||||
lines.clear();
|
||||
}
|
||||
|
||||
std::string* IniFile::Section::GetLine(const char* key, std::string* valueOut, std::string* commentOut)
|
||||
std::string* Section::GetLine(const char* key, std::string* valueOut, std::string* commentOut)
|
||||
{
|
||||
for (std::vector<std::string>::iterator iter = lines.begin(); iter != lines.end(); ++iter)
|
||||
{
|
||||
|
@ -165,7 +165,7 @@ std::string* IniFile::Section::GetLine(const char* key, std::string* valueOut, s
|
|||
return 0;
|
||||
}
|
||||
|
||||
void IniFile::Section::Set(const char* key, const char* newValue)
|
||||
void Section::Set(const char* key, const char* newValue)
|
||||
{
|
||||
std::string value, commented;
|
||||
std::string* line = GetLine(key, &value, &commented);
|
||||
|
@ -181,7 +181,7 @@ void IniFile::Section::Set(const char* key, const char* newValue)
|
|||
}
|
||||
}
|
||||
|
||||
void IniFile::Section::Set(const char* key, const std::string& newValue, const std::string& defaultValue)
|
||||
void Section::Set(const char* key, const std::string& newValue, const std::string& defaultValue)
|
||||
{
|
||||
if (newValue != defaultValue)
|
||||
Set(key, newValue);
|
||||
|
@ -189,7 +189,7 @@ void IniFile::Section::Set(const char* key, const std::string& newValue, const s
|
|||
Delete(key);
|
||||
}
|
||||
|
||||
bool IniFile::Section::Get(const char* key, std::string* value, const char* defaultValue)
|
||||
bool Section::Get(const char* key, std::string* value, const char* defaultValue)
|
||||
{
|
||||
const std::string* line = GetLine(key, value, 0);
|
||||
if (!line)
|
||||
|
@ -203,7 +203,7 @@ bool IniFile::Section::Get(const char* key, std::string* value, const char* defa
|
|||
return true;
|
||||
}
|
||||
|
||||
void IniFile::Section::Set(const char* key, const float newValue, const float defaultValue)
|
||||
void Section::Set(const char* key, const float newValue, const float defaultValue)
|
||||
{
|
||||
if (newValue != defaultValue)
|
||||
Set(key, newValue);
|
||||
|
@ -211,7 +211,7 @@ void IniFile::Section::Set(const char* key, const float newValue, const float de
|
|||
Delete(key);
|
||||
}
|
||||
|
||||
void IniFile::Section::Set(const char* key, int newValue, int defaultValue)
|
||||
void Section::Set(const char* key, int newValue, int defaultValue)
|
||||
{
|
||||
if (newValue != defaultValue)
|
||||
Set(key, newValue);
|
||||
|
@ -219,7 +219,7 @@ void IniFile::Section::Set(const char* key, int newValue, int defaultValue)
|
|||
Delete(key);
|
||||
}
|
||||
|
||||
void IniFile::Section::Set(const char* key, bool newValue, bool defaultValue)
|
||||
void Section::Set(const char* key, bool newValue, bool defaultValue)
|
||||
{
|
||||
if (newValue != defaultValue)
|
||||
Set(key, newValue);
|
||||
|
@ -227,7 +227,7 @@ void IniFile::Section::Set(const char* key, bool newValue, bool defaultValue)
|
|||
Delete(key);
|
||||
}
|
||||
|
||||
void IniFile::Section::Set(const char* key, const std::vector<std::string>& newValues)
|
||||
void Section::Set(const char* key, const std::vector<std::string>& newValues)
|
||||
{
|
||||
std::string temp;
|
||||
// Join the strings with ,
|
||||
|
@ -242,11 +242,11 @@ void IniFile::Section::Set(const char* key, const std::vector<std::string>& newV
|
|||
Set(key, temp.c_str());
|
||||
}
|
||||
|
||||
void IniFile::Section::AddComment(const std::string &comment) {
|
||||
void Section::AddComment(const std::string &comment) {
|
||||
lines.push_back("# " + comment);
|
||||
}
|
||||
|
||||
bool IniFile::Section::Get(const char* key, std::vector<std::string>& values)
|
||||
bool Section::Get(const char* key, std::vector<std::string>& values)
|
||||
{
|
||||
std::string temp;
|
||||
bool retval = Get(key, &temp, 0);
|
||||
|
@ -274,7 +274,7 @@ bool IniFile::Section::Get(const char* key, std::vector<std::string>& values)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool IniFile::Section::Get(const char* key, int* value, int defaultValue)
|
||||
bool Section::Get(const char* key, int* value, int defaultValue)
|
||||
{
|
||||
std::string temp;
|
||||
bool retval = Get(key, &temp, 0);
|
||||
|
@ -284,7 +284,7 @@ bool IniFile::Section::Get(const char* key, int* value, int defaultValue)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool IniFile::Section::Get(const char* key, uint32_t* value, uint32_t defaultValue)
|
||||
bool Section::Get(const char* key, uint32_t* value, uint32_t defaultValue)
|
||||
{
|
||||
std::string temp;
|
||||
bool retval = Get(key, &temp, 0);
|
||||
|
@ -294,7 +294,7 @@ bool IniFile::Section::Get(const char* key, uint32_t* value, uint32_t defaultVal
|
|||
return false;
|
||||
}
|
||||
|
||||
bool IniFile::Section::Get(const char* key, bool* value, bool defaultValue)
|
||||
bool Section::Get(const char* key, bool* value, bool defaultValue)
|
||||
{
|
||||
std::string temp;
|
||||
bool retval = Get(key, &temp, 0);
|
||||
|
@ -304,7 +304,7 @@ bool IniFile::Section::Get(const char* key, bool* value, bool defaultValue)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool IniFile::Section::Get(const char* key, float* value, float defaultValue)
|
||||
bool Section::Get(const char* key, float* value, float defaultValue)
|
||||
{
|
||||
std::string temp;
|
||||
bool retval = Get(key, &temp, 0);
|
||||
|
@ -314,7 +314,7 @@ bool IniFile::Section::Get(const char* key, float* value, float defaultValue)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool IniFile::Section::Get(const char* key, double* value, double defaultValue)
|
||||
bool Section::Get(const char* key, double* value, double defaultValue)
|
||||
{
|
||||
std::string temp;
|
||||
bool retval = Get(key, &temp, 0);
|
||||
|
@ -324,7 +324,7 @@ bool IniFile::Section::Get(const char* key, double* value, double defaultValue)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool IniFile::Section::Exists(const char *key) const
|
||||
bool Section::Exists(const char *key) const
|
||||
{
|
||||
for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
|
||||
{
|
||||
|
@ -336,7 +336,7 @@ bool IniFile::Section::Exists(const char *key) const
|
|||
return false;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> IniFile::Section::ToMap() const
|
||||
std::map<std::string, std::string> Section::ToMap() const
|
||||
{
|
||||
std::map<std::string, std::string> outMap;
|
||||
for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
|
||||
|
@ -350,7 +350,7 @@ std::map<std::string, std::string> IniFile::Section::ToMap() const
|
|||
}
|
||||
|
||||
|
||||
bool IniFile::Section::Delete(const char *key)
|
||||
bool Section::Delete(const char *key)
|
||||
{
|
||||
std::string* line = GetLine(key, 0, 0);
|
||||
for (std::vector<std::string>::iterator liter = lines.begin(); liter != lines.end(); ++liter)
|
||||
|
@ -366,7 +366,7 @@ bool IniFile::Section::Delete(const char *key)
|
|||
|
||||
// IniFile
|
||||
|
||||
const IniFile::Section* IniFile::GetSection(const char* sectionName) const
|
||||
const Section* IniFile::GetSection(const char* sectionName) const
|
||||
{
|
||||
for (std::vector<Section>::const_iterator iter = sections.begin(); iter != sections.end(); ++iter)
|
||||
if (!strcasecmp(iter->name().c_str(), sectionName))
|
||||
|
@ -374,7 +374,7 @@ const IniFile::Section* IniFile::GetSection(const char* sectionName) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
IniFile::Section* IniFile::GetSection(const char* sectionName)
|
||||
Section* IniFile::GetSection(const char* sectionName)
|
||||
{
|
||||
for (std::vector<Section>::iterator iter = sections.begin(); iter != sections.end(); ++iter)
|
||||
if (!strcasecmp(iter->name().c_str(), sectionName))
|
||||
|
@ -382,7 +382,7 @@ IniFile::Section* IniFile::GetSection(const char* sectionName)
|
|||
return 0;
|
||||
}
|
||||
|
||||
IniFile::Section* IniFile::GetOrCreateSection(const char* sectionName)
|
||||
Section* IniFile::GetOrCreateSection(const char* sectionName)
|
||||
{
|
||||
Section* section = GetSection(sectionName);
|
||||
if (!section)
|
||||
|
|
|
@ -4,126 +4,90 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <istream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "base/stringutil.h"
|
||||
|
||||
class Section
|
||||
{
|
||||
friend class IniFile;
|
||||
|
||||
public:
|
||||
Section() {}
|
||||
Section(const std::string& name) : name_(name) {}
|
||||
|
||||
bool Exists(const char *key) const;
|
||||
bool Delete(const char *key);
|
||||
|
||||
void Clear();
|
||||
|
||||
std::map<std::string, std::string> ToMap() const;
|
||||
|
||||
std::string* GetLine(const char* key, std::string* valueOut, std::string* commentOut);
|
||||
void Set(const char* key, const char* newValue);
|
||||
void Set(const char* key, const std::string& newValue, const std::string& defaultValue);
|
||||
|
||||
void Set(const std::string &key, const std::string &value) {
|
||||
Set(key.c_str(), value.c_str());
|
||||
}
|
||||
bool Get(const char* key, std::string* value, const char* defaultValue);
|
||||
|
||||
void Set(const char* key, uint32_t newValue) {
|
||||
Set(key, StringFromFormat("0x%08x", newValue).c_str());
|
||||
}
|
||||
void Set(const char* key, float newValue) {
|
||||
Set(key, StringFromFormat("%f", newValue).c_str());
|
||||
}
|
||||
void Set(const char* key, const float newValue, const float defaultValue);
|
||||
void Set(const char* key, double newValue) {
|
||||
Set(key, StringFromFormat("%f", newValue).c_str());
|
||||
}
|
||||
|
||||
void Set(const char* key, int newValue, int defaultValue);
|
||||
void Set(const char* key, int newValue) {
|
||||
Set(key, StringFromInt(newValue).c_str());
|
||||
}
|
||||
|
||||
void Set(const char* key, bool newValue, bool defaultValue);
|
||||
void Set(const char* key, bool newValue) {
|
||||
Set(key, StringFromBool(newValue).c_str());
|
||||
}
|
||||
void Set(const char* key, const std::vector<std::string>& newValues);
|
||||
|
||||
// Declare without a body to make it fail to compile. This is to prevent accidentally
|
||||
// setting a pointer as a bool. The failure is in the linker unfortunately, but that's better
|
||||
// than accidentally succeeding in a bad way.
|
||||
template<class T>
|
||||
void Set(const char *key, T *ptr);
|
||||
|
||||
void AddComment(const std::string &comment);
|
||||
|
||||
bool Get(const char* key, int* value, int defaultValue = 0);
|
||||
bool Get(const char* key, uint32_t* value, uint32_t defaultValue = 0);
|
||||
bool Get(const char* key, bool* value, bool defaultValue = false);
|
||||
bool Get(const char* key, float* value, float defaultValue = false);
|
||||
bool Get(const char* key, double* value, double defaultValue = false);
|
||||
bool Get(const char* key, std::vector<std::string>& values);
|
||||
|
||||
bool operator < (const Section& other) const {
|
||||
return name_ < other.name_;
|
||||
}
|
||||
|
||||
const std::string &name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<std::string> lines;
|
||||
std::string name_;
|
||||
std::string comment;
|
||||
};
|
||||
|
||||
class IniFile
|
||||
{
|
||||
public:
|
||||
class Section
|
||||
{
|
||||
friend class IniFile;
|
||||
|
||||
public:
|
||||
Section() {}
|
||||
Section(const std::string& name) : name_(name) {}
|
||||
|
||||
bool Exists(const char *key) const;
|
||||
bool Delete(const char *key);
|
||||
|
||||
void Clear();
|
||||
|
||||
std::map<std::string, std::string> ToMap() const;
|
||||
|
||||
std::string* GetLine(const char* key, std::string* valueOut, std::string* commentOut);
|
||||
void Set(const char* key, const char* newValue);
|
||||
void Set(const char* key, const std::string& newValue, const std::string& defaultValue);
|
||||
|
||||
void Set(const std::string &key, const std::string &value) {
|
||||
Set(key.c_str(), value.c_str());
|
||||
}
|
||||
bool Get(const char* key, std::string* value, const char* defaultValue);
|
||||
|
||||
void Set(const char* key, uint32_t newValue) {
|
||||
Set(key, StringFromFormat("0x%08x", newValue).c_str());
|
||||
}
|
||||
void Set(const char* key, float newValue) {
|
||||
Set(key, StringFromFormat("%f", newValue).c_str());
|
||||
}
|
||||
void Set(const char* key, const float newValue, const float defaultValue);
|
||||
void Set(const char* key, double newValue) {
|
||||
Set(key, StringFromFormat("%f", newValue).c_str());
|
||||
}
|
||||
|
||||
void Set(const char* key, int newValue, int defaultValue);
|
||||
void Set(const char* key, int newValue) {
|
||||
Set(key, StringFromInt(newValue).c_str());
|
||||
}
|
||||
|
||||
void Set(const char* key, bool newValue, bool defaultValue);
|
||||
void Set(const char* key, bool newValue) {
|
||||
Set(key, StringFromBool(newValue).c_str());
|
||||
}
|
||||
void Set(const char* key, const std::vector<std::string>& newValues);
|
||||
|
||||
template<typename U, typename V>
|
||||
void Set(const char* key, const std::map<U,V>& newValues)
|
||||
{
|
||||
std::vector<std::string> temp;
|
||||
for(typename std::map<U,V>::const_iterator it = newValues.begin(); it != newValues.end(); it++)
|
||||
{
|
||||
temp.push_back(ValueToString<U>(it->first)+"_"+ValueToString<V>(it->second));
|
||||
}
|
||||
Set(key,temp);
|
||||
}
|
||||
|
||||
// Declare without a body to make it fail to compile. This is to prevent accidentally
|
||||
// setting a pointer as a bool. The failure is in the linker unfortunately, but that's better
|
||||
// than accidentally succeeding in a bad way.
|
||||
template<class T>
|
||||
void Set(const char *key, T *ptr);
|
||||
|
||||
void AddComment(const std::string &comment);
|
||||
|
||||
bool Get(const char* key, int* value, int defaultValue = 0);
|
||||
bool Get(const char* key, uint32_t* value, uint32_t defaultValue = 0);
|
||||
bool Get(const char* key, bool* value, bool defaultValue = false);
|
||||
bool Get(const char* key, float* value, float defaultValue = false);
|
||||
bool Get(const char* key, double* value, double defaultValue = false);
|
||||
bool Get(const char* key, std::vector<std::string>& values);
|
||||
template<typename U, typename V>
|
||||
bool Get(const char* key, std::map<U,V>& values)
|
||||
{
|
||||
std::vector<std::string> temp;
|
||||
if(!Get(key,temp))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
values.clear();
|
||||
for(size_t i = 0; i < temp.size(); i++)
|
||||
{
|
||||
std::vector<std::string> key_val;
|
||||
SplitString(temp[i],'_',key_val);
|
||||
if(key_val.size() < 2)
|
||||
continue;
|
||||
U mapKey;
|
||||
V mapValue;
|
||||
if(!TryParse<U>(key_val[0],&mapKey))
|
||||
continue;
|
||||
if(!TryParse<V>(key_val[1],&mapValue))
|
||||
continue;
|
||||
values[mapKey] = mapValue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator < (const Section& other) const {
|
||||
return name_ < other.name_;
|
||||
}
|
||||
|
||||
const std::string &name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<std::string> lines;
|
||||
std::string name_;
|
||||
std::string comment;
|
||||
};
|
||||
|
||||
bool Load(const char* filename);
|
||||
bool Load(const std::string &filename) { return Load(filename.c_str()); }
|
||||
bool Load(std::istream &istream);
|
||||
|
@ -189,6 +153,4 @@ private:
|
|||
|
||||
const Section* GetSection(const char* section) const;
|
||||
Section* GetSection(const char* section);
|
||||
std::string* GetLine(const char* section, const char* key);
|
||||
void CreateSection(const char* section);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "base/logging.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "i18n/i18n.h"
|
||||
#include "file/ini_file.h"
|
||||
#include "file/vfs.h"
|
||||
|
@ -95,7 +96,7 @@ bool I18NRepo::LoadIni(const std::string &languageID, const std::string &overrid
|
|||
|
||||
Clear();
|
||||
|
||||
const std::vector<IniFile::Section> §ions = ini.Sections();
|
||||
const std::vector<Section> §ions = ini.Sections();
|
||||
|
||||
std::lock_guard<std::mutex> guard(catsLock_);
|
||||
for (auto iter = sections.begin(); iter != sections.end(); ++iter) {
|
||||
|
@ -108,7 +109,7 @@ bool I18NRepo::LoadIni(const std::string &languageID, const std::string &overrid
|
|||
return true;
|
||||
}
|
||||
|
||||
I18NCategory *I18NRepo::LoadSection(const IniFile::Section *section, const char *name) {
|
||||
I18NCategory *I18NRepo::LoadSection(const Section *section, const char *name) {
|
||||
I18NCategory *cat = new I18NCategory(this, name);
|
||||
std::map<std::string, std::string> sectionMap = section->ToMap();
|
||||
cat->SetMap(sectionMap);
|
||||
|
@ -123,13 +124,13 @@ void I18NRepo::SaveIni(const std::string &languageID) {
|
|||
std::lock_guard<std::mutex> guard(catsLock_);
|
||||
for (auto iter = cats_.begin(); iter != cats_.end(); ++iter) {
|
||||
std::string categoryName = iter->first;
|
||||
IniFile::Section *section = ini.GetOrCreateSection(categoryName.c_str());
|
||||
Section *section = ini.GetOrCreateSection(categoryName.c_str());
|
||||
SaveSection(ini, section, iter->second);
|
||||
}
|
||||
ini.Save(GetIniPath(languageID));
|
||||
}
|
||||
|
||||
void I18NRepo::SaveSection(IniFile &ini, IniFile::Section *section, std::shared_ptr<I18NCategory> cat) {
|
||||
void I18NRepo::SaveSection(IniFile &ini, Section *section, std::shared_ptr<I18NCategory> cat) {
|
||||
const std::map<std::string, std::string> &missed = cat->Missed();
|
||||
|
||||
for (auto iter = missed.begin(); iter != missed.end(); ++iter) {
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "file/ini_file.h"
|
||||
#include "base/basictypes.h"
|
||||
|
||||
// Reasonably thread safe.
|
||||
|
||||
class I18NRepo;
|
||||
class IniFile;
|
||||
class Section;
|
||||
|
||||
struct I18NEntry {
|
||||
I18NEntry(const std::string &t) : text(t), readFlag(false) {}
|
||||
|
@ -89,8 +91,8 @@ public:
|
|||
private:
|
||||
std::string GetIniPath(const std::string &languageID) const;
|
||||
void Clear();
|
||||
I18NCategory *LoadSection(const IniFile::Section *section, const char *name);
|
||||
void SaveSection(IniFile &ini, IniFile::Section *section, std::shared_ptr<I18NCategory> cat);
|
||||
I18NCategory *LoadSection(const Section *section, const char *name);
|
||||
void SaveSection(IniFile &ini, Section *section, std::shared_ptr<I18NCategory> cat);
|
||||
|
||||
mutable std::mutex catsLock_;
|
||||
std::map<std::string, std::shared_ptr<I18NCategory>> cats_;
|
||||
|
|
|
@ -23,11 +23,6 @@
|
|||
// TODO: Not a great cross dependency.
|
||||
#include "Common/Crypto/sha1.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
// Function Cross-Compatibility
|
||||
#define strcasecmp _stricmp
|
||||
#endif
|
||||
|
||||
static const char *const WEBSOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
|
||||
namespace net {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include "base/display.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "input/input_state.h"
|
||||
#include "input/keycodes.h"
|
||||
#include "math/curves.h"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <climits>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "base/stringutil.h"
|
||||
#include "util/text/parsers.h"
|
||||
|
||||
bool Version::ParseVersionString(std::string str) {
|
||||
|
@ -37,3 +39,44 @@ bool ParseMacAddress(std::string str, uint8_t macAddr[6]) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TryParse(const std::string &str, uint32_t *const output) {
|
||||
char *endptr = NULL;
|
||||
|
||||
// Holy crap this is ugly.
|
||||
|
||||
// Reset errno to a value other than ERANGE
|
||||
errno = 0;
|
||||
|
||||
unsigned long value = strtoul(str.c_str(), &endptr, 0);
|
||||
|
||||
if (!endptr || *endptr)
|
||||
return false;
|
||||
|
||||
if (errno == ERANGE)
|
||||
return false;
|
||||
|
||||
if (ULONG_MAX > UINT_MAX) {
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable:4309)
|
||||
#endif
|
||||
// Note: The typecasts avoid GCC warnings when long is 32 bits wide.
|
||||
if (value >= static_cast<unsigned long>(0x100000000ull)
|
||||
&& value <= static_cast<unsigned long>(0xFFFFFFFF00000000ull))
|
||||
return false;
|
||||
}
|
||||
|
||||
*output = static_cast<uint32_t>(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TryParse(const std::string &str, bool *const output) {
|
||||
if ("1" == str || !strcasecmp("true", str.c_str()))
|
||||
*output = true;
|
||||
else if ("0" == str || !strcasecmp("false", str.c_str()))
|
||||
*output = false;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
|
||||
|
@ -53,4 +54,19 @@ private:
|
|||
bool ParseVersionString(std::string str);
|
||||
};
|
||||
|
||||
bool ParseMacAddress(std::string str, uint8_t macAddr[6]);
|
||||
bool ParseMacAddress(std::string str, uint8_t macAddr[6]);
|
||||
|
||||
bool TryParse(const std::string &str, bool *const output);
|
||||
bool TryParse(const std::string &str, uint32_t *const output);
|
||||
|
||||
template <typename N>
|
||||
static bool TryParse(const std::string &str, N *const output) {
|
||||
std::istringstream iss(str);
|
||||
|
||||
N tmp = 0;
|
||||
if (iss >> tmp) {
|
||||
*output = tmp;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue