summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rtl/character.hxx26
-rw-r--r--sal/rtl/ustring.cxx8
-rw-r--r--svtools/source/svhtml/htmlout.cxx10
3 files changed, 28 insertions, 16 deletions
diff --git a/include/rtl/character.hxx b/include/rtl/character.hxx
index ba3088efdeda..4546c9f2d5e0 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 b1fb82a375dd..3d157270ef3c 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 5413e91da00f..baf8cc6dae2c 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,