COMMON: Add Common::parseBool

svn-id: r48566
This commit is contained in:
Max Horn 2010-04-06 09:27:13 +00:00
parent 77c1e0dfe1
commit 7c510f2dfa
2 changed files with 33 additions and 0 deletions

View File

@ -84,6 +84,27 @@ void hexdump(const byte * data, int len, int bytesPerLine, int startOffset) {
#pragma mark -
bool parseBool(const Common::String &val, bool &valAsBool) {
if (val.equalsIgnoreCase("true") ||
val.equalsIgnoreCase("yes") ||
val.equals("1")) {
valAsBool = true;
return true;
}
if (val.equalsIgnoreCase("false") ||
val.equalsIgnoreCase("no") ||
val.equals("0")) {
valAsBool = false;
return true;
}
return false;
}
#pragma mark -
const LanguageDescription g_languages[] = {
{"zh-cn", "Chinese (China)", ZH_CNA},
{"zh", "Chinese (Taiwan)", ZH_TWN},

View File

@ -76,6 +76,18 @@ namespace Common {
extern void hexdump(const byte * data, int len, int bytesPerLine = 16, int startOffset = 0);
/**
* Parse a string for a boolean value.
* The strings "true", "yes", and "1" are interpreted as true.
* The strings "false", "no", and "0" are interpreted as false.
* This function ignores case.
*
* @param[in] val the string to parse
* @param[out] valAsBool the parsing result
* @return true if the string parsed correctly, false if an error occurred.
*/
bool parseBool(const Common::String &val, bool &valAsBool);
/**
* List of game language.
*/