diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-12-17 20:21:47 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-12-17 21:50:27 +0000 |
commit | 2b6d04b8493a6b05c8ed0afb0c1e96d441ba876b (patch) | |
tree | 2e9d2aeac8cfe475daf872cbc07edc00ffc445b0 /comphelper | |
parent | f7b30ab0141e2038b0e5e882d634065878c24c3f (diff) |
move and rename sanitizeString for reuse
Change-Id: I8378f3df79e511cf2d385ace1cd7964ab1c76e7b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144388
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/misc/string.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index d0f7cb9ca423..da5c8b92c05c 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -32,6 +32,7 @@ #include <rtl/ustrbuf.hxx> #include <rtl/string.hxx> #include <rtl/strbuf.hxx> +#include <sal/log.hxx> #include <sal/types.h> #include <comphelper/string.hxx> @@ -652,6 +653,32 @@ void replaceAt(OUStringBuffer& rIn, sal_Int32 nIndex, sal_Int32 nCount, std::u16 rIn.setLength(nNewLength); } +OUString sanitizeStringSurrogates(const OUString& rString) +{ + sal_Int32 i=0; + while (i < rString.getLength()) + { + sal_Unicode c = rString[i]; + if (rtl::isHighSurrogate(c)) + { + if (i+1 == rString.getLength() + || !rtl::isLowSurrogate(rString[i+1])) + { + SAL_WARN("comphelper", "Surrogate error: high without low"); + return rString.copy(0, i); + } + ++i; //skip correct low + } + if (rtl::isLowSurrogate(c)) //bare low without preceding high + { + SAL_WARN("comphelper", "Surrogate error: low without high"); + return rString.copy(0, i); + } + ++i; + } + return rString; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |