diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-05-05 09:46:52 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-05-05 11:30:12 +0200 |
commit | 28cc0bff10f5dcec0c7b698ae7ba275845b2cad1 (patch) | |
tree | cdcccaa2356b8bea6c5b919faa6cd497a72e2336 /comphelper/source/misc | |
parent | c1bd421eae5449a005f2ee0f01b3b4e72002296e (diff) |
Break comphelper::adjustIndexToStartOfSurrogate out of o3tl::iterateCodePoints
...as what they do is orthogonal (and it turned out that the use case that
motivated the addition of o3tl::iterateCodePoints in the first place needs them
independently, anyway)
Change-Id: Id33901a2f7ac627253654ee6d883305dcf5a456f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151415
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'comphelper/source/misc')
-rw-r--r-- | comphelper/source/misc/string.cxx | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index da5c8b92c05c..0fdd24c83d7e 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -19,6 +19,7 @@ #include <sal/config.h> +#include <cassert> #include <cstddef> #include <string_view> #include <utility> @@ -679,6 +680,14 @@ OUString sanitizeStringSurrogates(const OUString& rString) return rString; } +sal_Int32 adjustIndexToStartOfSurrogate(OUString const & string, sal_Int32 index) { + assert(index >= 0 && index <= string.getLength()); + return + (index > 0 && rtl::isHighSurrogate(string[index - 1]) + && index < string.getLength() && rtl::isLowSurrogate(string[index])) + ? index - 1 : index; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |