diff options
author | Eike Rathke <erack@redhat.com> | 2022-09-13 11:04:20 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2022-09-13 12:37:12 +0200 |
commit | c0d09eb46665a0b2ab86f263cc95662f406d83d2 (patch) | |
tree | 7a1a98f9e6b368c7a5cde5ceef1c349dd61da5ab /unotools | |
parent | b7d63694985bbb1cf86eb71769feadb28ce68c17 (diff) |
Empty string has no characters of any type
Change-Id: Id7244032d52360d2b0ea57fba023dff162a29d95
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139831
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/i18n/charclass.cxx | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/unotools/source/i18n/charclass.cxx b/unotools/source/i18n/charclass.cxx index 4573687c4d29..be3a9f4f0ee0 100644 --- a/unotools/source/i18n/charclass.cxx +++ b/unotools/source/i18n/charclass.cxx @@ -132,6 +132,9 @@ bool CharClass::isLetter( const OUString& rStr, sal_Int32 nPos ) const bool CharClass::isLetter( const OUString& rStr ) const { + if (rStr.isEmpty()) + return false; + try { sal_Int32 nPos = 0; @@ -170,6 +173,9 @@ bool CharClass::isDigit( const OUString& rStr, sal_Int32 nPos ) const bool CharClass::isNumeric( const OUString& rStr ) const { + if (rStr.isEmpty()) + return false; + try { sal_Int32 nPos = 0; @@ -226,6 +232,9 @@ bool CharClass::isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const bool CharClass::isLetterNumeric( const OUString& rStr ) const { + if (rStr.isEmpty()) + return false; + try { sal_Int32 nPos = 0; @@ -264,10 +273,16 @@ bool CharClass::isUpper( const OUString& rStr, sal_Int32 nPos ) const bool CharClass::isUpper( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const { + if (rStr.isEmpty()) + return false; + + assert(nPos >= 0 && nPos < rStr.getLength() && nCount > 0); + if (nPos < 0 || nPos >= rStr.getLength() || nCount == 0) + return false; + try { - assert(nPos >= 0 && nCount >= 0); - sal_Int32 nLen = std::min( nPos + nCount, rStr.getLength()); + const sal_Int32 nLen = std::min( nPos + nCount, rStr.getLength()); while (nPos < nLen) { if (!isUpper( rStr, nPos)) |