[Libreoffice-commits] core.git: include/rtl writerfilter/source

Stephan Bergmann sbergman at redhat.com
Wed Mar 22 20:31:35 UTC 2017


 include/rtl/character.hxx                             |   23 ++++++++++++++++++
 writerfilter/source/rtftok/rtfdispatchdestination.cxx |   12 +++++++--
 writerfilter/source/rtftok/rtftokenizer.cxx           |   10 +++----
 3 files changed, 37 insertions(+), 8 deletions(-)

New commits:
commit f5c93d4149e7ae967e98dbce72528a04a204ca95
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Mar 22 21:31:00 2017 +0100

    Use rtl::isAscii* instead of ctype.h is* (and fix passing plain char)
    
    and add rtl::isAsciiWhiteSpace
    
    Change-Id: Iac71975f718b9360ea9dc94485c069c5e7cb91c7

diff --git a/include/rtl/character.hxx b/include/rtl/character.hxx
index 4ccc632afb4a..b83121a4a6d4 100644
--- a/include/rtl/character.hxx
+++ b/include/rtl/character.hxx
@@ -239,6 +239,29 @@ template<typename T> inline bool isAsciiOctalDigit(T code)
 { return isAsciiOctalDigit(sal_uInt32(code)); }
 #endif
 
+/** Check for ASCII white space character.
+
+    @param code  A Unicode code point.
+
+    @return  True if code is an ASCII white space character as defined by C for
+    isspace in the "C" locale (ASCII ' ', '\f', '\n', '\r', '\t' '\v').
+
+    @since LibreOffice 5.4
+*/
+inline bool isAsciiWhiteSpace(sal_uInt32 code)
+{
+    assert(isUnicodeCodePoint(code));
+    return code == ' ' || code == '\f' || code == '\n' || code == '\r'
+        || code == '\t' || code == '\v';
+}
+
+#if defined LIBO_INTERNAL_ONLY
+bool isAsciiWhiteSpace(char) = delete;
+bool isAsciiWhiteSpace(signed char) = delete;
+template<typename T> inline bool isAsciiWhiteSpace(T code)
+{ return isAsciiWhiteSpace(sal_uInt32(code)); }
+#endif
+
 /** Convert a character, if ASCII, to upper case.
 
     @param code  A Unicode code point.
diff --git a/writerfilter/source/rtftok/rtfdispatchdestination.cxx b/writerfilter/source/rtftok/rtfdispatchdestination.cxx
index 0c44e25b4dd2..3863309b3601 100644
--- a/writerfilter/source/rtftok/rtfdispatchdestination.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchdestination.cxx
@@ -13,6 +13,7 @@
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 
 #include <filter/msfilter/escherex.hxx>
+#include <rtl/character.hxx>
 #include <tools/stream.hxx>
 
 #include <dmapper/DomainMapperFactory.hxx>
@@ -71,11 +72,16 @@ RTFError RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
                 Strm().ReadChar(ch);
                 if ('\\' == ch)
                     bInKeyword = true;
-                if (!bInKeyword  && isalnum(ch))
+                if (!bInKeyword
+                    && rtl::isAsciiAlphanumeric(static_cast<unsigned char>(ch)))
                     aBuf.append(ch);
-                else if (bInKeyword && isspace(ch))
+                else if (bInKeyword
+                         && rtl::isAsciiWhiteSpace(
+                             static_cast<unsigned char>(ch)))
                     bInKeyword = false;
-                if (!aBuf.isEmpty() && !isalnum(ch))
+                if (!aBuf.isEmpty()
+                    && !rtl::isAsciiAlphanumeric(
+                        static_cast<unsigned char>(ch)))
                     bFoundCode = true;
             }
 
diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx
index fd0fd2f9d44e..91b41eb5242e 100644
--- a/writerfilter/source/rtftok/rtftokenizer.cxx
+++ b/writerfilter/source/rtftok/rtftokenizer.cxx
@@ -166,7 +166,7 @@ RTFError RTFTokenizer::resolveParse()
 int RTFTokenizer::asHex(char ch)
 {
     int ret = 0;
-    if (isdigit(ch))
+    if (rtl::isAsciiDigit(static_cast<unsigned char>(ch)))
         ret = ch - '0';
     else
     {
@@ -203,7 +203,7 @@ RTFError RTFTokenizer::resolveKeyword()
     if (Strm().IsEof())
         return RTFError::UNEXPECTED_EOF;
 
-    if (!isalpha(ch))
+    if (!rtl::isAsciiAlpha(static_cast<unsigned char>(ch)))
     {
         aBuf.append(ch);
         OString aKeyword = aBuf.makeStringAndClear();
@@ -211,7 +211,7 @@ RTFError RTFTokenizer::resolveKeyword()
         // without doing any SeekRel()
         return dispatchKeyword(aKeyword, bParam, nParam);
     }
-    while (isalpha(ch))
+    while (rtl::isAsciiAlpha(static_cast<unsigned char>(ch)))
     {
         aBuf.append(ch);
         Strm().ReadChar(ch);
@@ -234,13 +234,13 @@ RTFError RTFTokenizer::resolveKeyword()
         if (Strm().IsEof())
             return RTFError::UNEXPECTED_EOF;
     }
-    if (isdigit(ch))
+    if (rtl::isAsciiDigit(static_cast<unsigned char>(ch)))
     {
         OStringBuffer aParameter;
 
         // we have a parameter
         bParam = true;
-        while (isdigit(ch))
+        while (rtl::isAsciiDigit(static_cast<unsigned char>(ch)))
         {
             aParameter.append(ch);
             Strm().ReadChar(ch);


More information about the Libreoffice-commits mailing list