From 9124003eb1e398957a85c5c009ac5eddf5e6f28e Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Sun, 14 Aug 2011 01:37:52 +0100 Subject: ByteString::IsNumericAscii->comphelper::string::isAsciiDecimalString shrink ByteString api, remove need for intermediate OString/ByteString with random-ish encoding solely for check --- comphelper/inc/comphelper/string.hxx | 21 +++++++++++++++++++++ comphelper/source/misc/string.cxx | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'comphelper') 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 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: */ -- cgit