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

Stephan Bergmann sbergman at redhat.com
Fri Oct 7 16:14:56 UTC 2016


 include/rtl/character.hxx         |   26 ++++++++++++++++++++++++++
 sal/rtl/ustring.cxx               |    8 +-------
 svtools/source/svhtml/htmlout.cxx |   10 +---------
 3 files changed, 28 insertions(+), 16 deletions(-)

New commits:
commit 5c2894222beed4b30c6be0379cade228c42c5610
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Oct 7 18:12:26 2016 +0200

    New rtl::splitSurrogates, remove code duplication
    
    Change-Id: Ic96b64244f817196ccdfe06b97f7f31291adf372

diff --git a/include/rtl/character.hxx b/include/rtl/character.hxx
index ba3088e..4546c9f 100644
--- a/include/rtl/character.hxx
+++ b/include/rtl/character.hxx
@@ -23,6 +23,7 @@
 #include <sal/config.h>
 
 #include <cassert>
+#include <cstddef>
 
 #include <sal/types.h>
 
@@ -308,6 +309,31 @@ inline sal_uInt32 combineSurrogates(sal_uInt32 high, sal_uInt32 low) {
         + (low - detail::surrogatesLowFirst) + 0x10000;
 }
 
+/** Split a Unicode code point into UTF-16 code units.
+
+    @param code  A Unicode code point.
+
+    @param output  A non-null pointer to an array with space for at least two
+    sal_Unicode UTF-16 code units.
+
+    @return  The number of UTF-16 code units placed into the output (either one
+    or two).
+
+    @since LibreOffice 5.3
+*/
+inline std::size_t splitSurrogates(sal_uInt32 code, sal_Unicode * output) {
+    assert(isUnicodeCodePoint(code));
+    assert(output != NULL);
+    if (code < 0x10000) {
+        output[0] = code;
+        return 1;
+    } else {
+        output[0] = getHighSurrogate(code);
+        output[1] = getLowSurrogate(code);
+        return 2;
+    }
+}
+
 }
 
 #endif
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx
index b1fb82a..3d15727 100644
--- a/sal/rtl/ustring.cxx
+++ b/sal/rtl/ustring.cxx
@@ -598,13 +598,7 @@ void SAL_CALL rtl_uString_newFromCodePoints(
     }
     p = (*newString)->buffer;
     for (i = 0; i < codePointCount; ++i) {
-        sal_uInt32 c = codePoints[i];
-        if (c < 0x10000) {
-            *p++ = (sal_Unicode) c;
-        } else {
-            *p++ = rtl::getHighSurrogate(c);
-            *p++ = rtl::getLowSurrogate(c);
-        }
+        p += rtl::splitSurrogates(codePoints[i], p);
     }
     RTL_LOG_STRING_NEW( *newString );
 }
diff --git a/svtools/source/svhtml/htmlout.cxx b/svtools/source/svhtml/htmlout.cxx
index 5413e91..baf8cc6 100644
--- a/svtools/source/svhtml/htmlout.cxx
+++ b/svtools/source/svhtml/htmlout.cxx
@@ -449,15 +449,7 @@ static OString lcl_ConvertCharToHTML( sal_uInt32 c,
         sal_Size nSrcChars;
 
         sal_Unicode utf16[2];
-        sal_Size n;
-        if (c < 0x10000) {
-            utf16[0] = c;
-            n = 1;
-        } else {
-            utf16[0] = rtl::getHighSurrogate(c);
-            utf16[1] = rtl::getLowSurrogate(c);
-            n = 2;
-        }
+        auto n = rtl::splitSurrogates(c, utf16);
         sal_Size nLen = rtl_convertUnicodeToText(rContext.m_hConv,
                                                  rContext.m_hContext, utf16, n,
                                                  cBuffer, TXTCONV_BUFFER_SIZE,


More information about the Libreoffice-commits mailing list