diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-10-07 18:12:26 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-10-07 18:12:26 +0200 |
commit | 5c2894222beed4b30c6be0379cade228c42c5610 (patch) | |
tree | 9c797db7bc93db83579f5a1e9a8633d2d087cbca /include/rtl | |
parent | d211dafa9e35d9af26acc274b18a32b8ca0b937a (diff) |
New rtl::splitSurrogates, remove code duplication
Change-Id: Ic96b64244f817196ccdfe06b97f7f31291adf372
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/character.hxx | 26 |
1 files changed, 26 insertions, 0 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 |