From 5c2894222beed4b30c6be0379cade228c42c5610 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 7 Oct 2016 18:12:26 +0200 Subject: New rtl::splitSurrogates, remove code duplication Change-Id: Ic96b64244f817196ccdfe06b97f7f31291adf372 --- include/rtl/character.hxx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'include/rtl/character.hxx') 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 #include +#include #include @@ -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 -- cgit