diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-08-14 01:37:52 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-08-15 09:21:48 +0100 |
commit | 9124003eb1e398957a85c5c009ac5eddf5e6f28e (patch) | |
tree | d1348216600b18f3daa08224a4d4492b53337813 /comphelper | |
parent | a6825d680c7f49dd462a858cc8691757a6dd4cba (diff) |
ByteString::IsNumericAscii->comphelper::string::isAsciiDecimalString
shrink ByteString api, remove need for intermediate OString/ByteString
with random-ish encoding solely for check
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/inc/comphelper/string.hxx | 21 | ||||
-rw-r--r-- | comphelper/source/misc/string.cxx | 23 |
2 files changed, 44 insertions, 0 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index e71a008c5e3e..dd3261bef085 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -193,6 +193,27 @@ public: const ::com::sun::star::lang::Locale& getLocale() const { return m_aLocale; } }; +/** Determine if an OString contains solely ascii numeric digits + + @param rString An OString + + @return false if string contains any characters outside + the ascii '0'-'9' range + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isAsciiDecimalString(const rtl::OString &rString); + +/** Determine if an OUString contains solely ascii numeric digits + + @param rString An OUString + + @return false if string contains any characters outside + the ascii '0'-'9' range + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isAsciiDecimalString(const rtl::OUString &rString); + + } } #endif diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index 18ad6ad4fe9f..249ef2e87800 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -308,6 +308,29 @@ NaturalStringSorter::NaturalStringSorter( uno::UNO_QUERY_THROW); } +namespace +{ + template <typename T> bool tmpl_isAsciiDecimalString(const T &rString) + { + for (sal_Int32 i = 0; i < rString.getLength(); ++i) + { + if ((rString[i] < '0') || (rString[i] > '9')) + return false; + } + return true; + } +} + +bool isAsciiDecimalString(const rtl::OString &rString) +{ + return tmpl_isAsciiDecimalString(rString); +} + +bool isAsciiDecimalString(const rtl::OUString &rString) +{ + return tmpl_isAsciiDecimalString(rString); +} + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |