Very basic internationalization. Does not work on Android yet due to location of ini files.

This commit is contained in:
Henrik Rydgard committed 2013-04-18 12:06:26 +02:00
1 parent 8bc942f4ad
commit 32f344d6bd
20 files changed
+294 -1009

No files matched your search

-139
View File
@@ -51,134 +51,6 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
}
}
std::string StringFromFormat(const char* format, ...)
{
va_list args;
char *buf = NULL;
std::string temp = "";
#ifdef _WIN32
int required = 0;
va_start(args, format);
required = _vscprintf(format, args);
buf = new char[required + 1];
if(vsnprintf(buf, required, format, args) < 0)
buf[0] = '\0';
va_end(args);
buf[required] = '\0';
temp = buf;
delete[] buf;
#else
va_start(args, format);
if(vasprintf(&buf, format, args) < 0)
buf = NULL;
va_end(args);
if(buf != NULL) {
temp = buf;
free(buf);
}
#endif
return temp;
}
// For Debugging. Read out an u8 array.
std::string ArrayToString(const u8 *data, u32 size, int line_len, bool spaces)
{
std::ostringstream oss;
oss << std::setfill('0') << std::hex;
for (int line = 0; size; ++data, --size)
{
oss << std::setw(2) << (int)*data;
if (line_len == ++line)
{
oss << '\n';
line = 0;
}
else if (spaces)
oss << ' ';
}
return oss.str();
}
// Turns " hej " into "hej". Also handles tabs.
std::string StripSpaces(const std::string &str)
{
const size_t s = str.find_first_not_of(" \t\r\n");
if (str.npos != s)
return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1);
else
return "";
}
// "\"hello\"" is turned to "hello"
// This one assumes that the string has already been space stripped in both
// ends, as done by StripSpaces above, for example.
std::string StripQuotes(const std::string& s)
{
if (s.size() && '\"' == s[0] && '\"' == *s.rbegin())
return s.substr(1, s.size() - 2);
else
return s;
}
bool TryParse(const std::string &str, u32 *const output)
{
char *endptr = NULL;
// 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<u32>(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;
}
std::string StringFromInt(int value)
{
char temp[16];
sprintf(temp, "%i", value);
return temp;
}
std::string StringFromBool(bool value)
{
return value ? "True" : "False";
}
bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension)
{
if (full_path.empty())
@@ -223,17 +95,6 @@ void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _P
_CompleteFilename += _Filename;
}
void SplitString(const std::string& str, const char delim, std::vector<std::string>& output)
{
std::istringstream iss(str);
output.resize(1);
while (std::getline(iss, *output.rbegin(), delim))
output.push_back("");
output.pop_back();
}
std::string TabsToSpaces(int tab_size, const std::string &in)
{
const std::string spaces(tab_size, ' ');