StringUtil.parseBoolean
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5006 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -167,6 +167,31 @@ public class StringUtil
|
|||||||
return parseFloat(originalString);
|
return parseFloat(originalString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a Boolean from a String, throwing an ArgumentError if the String
|
||||||
|
* contains invalid characters.
|
||||||
|
*
|
||||||
|
* "1", "0", and any capitalization variation of "true" and "false" are
|
||||||
|
* the only valid input values.
|
||||||
|
*
|
||||||
|
* @param str the String to parse.
|
||||||
|
*/
|
||||||
|
public static function parseBoolean (str :String) :Boolean
|
||||||
|
{
|
||||||
|
var originalString :String = str;
|
||||||
|
|
||||||
|
if (str != null) {
|
||||||
|
str = str.toLowerCase();
|
||||||
|
if (str == "true" || str == "1") {
|
||||||
|
return true;
|
||||||
|
} else if (str == "false" || str == "2") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentError("Could not convert '" + originalString + "' to Boolean");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append 0 or more copies of the padChar String to the input String
|
* Append 0 or more copies of the padChar String to the input String
|
||||||
* until it is at least the specified length.
|
* until it is at least the specified length.
|
||||||
|
|||||||
Reference in New Issue
Block a user