aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarlson2k <k2k@narod.ru>2013-11-12 23:44:46 +0400
committerKarlson2k <k2k@narod.ru>2013-12-09 00:34:10 +0400
commit7d057d7c9f145f39bf1be8bc68619a50f72deadf (patch)
tree6beb9ae142c2c1a74a9dff8ff898fbf1cbd4a25c
parent8f830c1b9a4446f9b68f0dbd693fcda2788eff26 (diff)
StringUtils: add "isasciidigit", "isasciixdigit", "asciidigitvalue", "asciixdigitvalue", "isasciiuppercaseletter", "isasciilowercaseletter" and "isasciialphanum" for locale-independent ASCII operations
-rw-r--r--xbmc/utils/StringUtils.cpp22
-rw-r--r--xbmc/utils/StringUtils.h26
2 files changed, 48 insertions, 0 deletions
diff --git a/xbmc/utils/StringUtils.cpp b/xbmc/utils/StringUtils.cpp
index e34a2a5785..cee1a87f9c 100644
--- a/xbmc/utils/StringUtils.cpp
+++ b/xbmc/utils/StringUtils.cpp
@@ -727,6 +727,28 @@ bool StringUtils::IsInteger(const CStdString& str)
return i == str.size() && n > 0;
}
+int StringUtils::asciidigitvalue(char chr)
+{
+ if (!isasciidigit(chr))
+ return -1;
+
+ return chr - '0';
+}
+
+int StringUtils::asciixdigitvalue(char chr)
+{
+ int v = asciidigitvalue(chr);
+ if (v >= 0)
+ return v;
+ if (chr >= 'a' && chr <= 'f')
+ return chr - 'a' + 10;
+ if (chr >= 'A' && chr <= 'F')
+ return chr - 'A' + 10;
+
+ return -1;
+}
+
+
void StringUtils::RemoveCRLF(CStdString& strLine)
{
StringUtils::TrimRight(strLine, "\n\r");
diff --git a/xbmc/utils/StringUtils.h b/xbmc/utils/StringUtils.h
index 1d1aade92a..3354edd049 100644
--- a/xbmc/utils/StringUtils.h
+++ b/xbmc/utils/StringUtils.h
@@ -124,6 +124,32 @@ public:
\return true if the string is an integer, false otherwise.
*/
static bool IsInteger(const CStdString& str);
+
+ /* The next several isasciiXX and asciiXXvalue functions are locale independent (US-ASCII only),
+ * as opposed to standard ::isXX (::isalpha, ::isdigit...) which are locale dependent.
+ * Next functions get parameter as char and don't need double cast ((int)(unsigned char) is required for standard functions). */
+ inline static bool isasciidigit(char chr) // locale independent
+ {
+ return chr >= '0' && chr <= '9';
+ }
+ inline static bool isasciixdigit(char chr) // locale independent
+ {
+ return (chr >= '0' && chr <= '9') || (chr >= 'a' && chr <= 'f') || (chr >= 'A' && chr <= 'F');
+ }
+ static int asciidigitvalue(char chr); // locale independent
+ static int asciixdigitvalue(char chr); // locale independent
+ inline static bool isasciiuppercaseletter(char chr) // locale independent
+ {
+ return (chr >= 'A' && chr <= 'Z');
+ }
+ inline static bool isasciilowercaseletter(char chr) // locale independent
+ {
+ return (chr >= 'a' && chr <= 'z');
+ }
+ inline static bool isasciialphanum(char chr) // locale independent
+ {
+ return isasciiuppercaseletter(chr) || isasciilowercaseletter(chr) || isasciidigit(chr);
+ }
static CStdString SizeToString(int64_t size);
static const CStdString EmptyString;
static const std::string Empty;