diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-04-20 13:50:52 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-04-20 13:51:19 +0200 |
commit | 9561c2f6793bede6e5092c36a4f1c8dbb782c4f4 (patch) | |
tree | cb448ab79c6075f9109120f678da78267891bb7b /include/rtl | |
parent | d0d8e0a2a7244814f783f16c6c8b342fe6d16e79 (diff) |
Clean up new rtl/surrogates.h
Change-Id: Iec781bdbbf216cb14c9ba5be5955123273d7699c
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/character.hxx | 84 | ||||
-rw-r--r-- | include/rtl/surrogates.h | 57 |
2 files changed, 84 insertions, 57 deletions
diff --git a/include/rtl/character.hxx b/include/rtl/character.hxx index f5c9490033ec..52151e8c10ed 100644 --- a/include/rtl/character.hxx +++ b/include/rtl/character.hxx @@ -211,6 +211,90 @@ inline sal_Int32 compareIgnoreAsciiCase(sal_uInt32 code1, sal_uInt32 code2) - static_cast<sal_Int32>(toAsciiLowerCase(code2)); } +/// @cond INTERNAL +namespace detail { + +sal_uInt32 const surrogatesHighFirst = 0xD800; +sal_uInt32 const surrogatesHighLast = 0xDBFF; +sal_uInt32 const surrogatesLowFirst = 0xDC00; +sal_uInt32 const surrogatesLowLast = 0xDFFF; + +} +/// @endcond + +/** Check for high surrogate. + + @param code A Unicode code point. + + @return True if code is a high surrogate code point (0xD800--0xDBFF). + + @since LibreOffice 5.0 +*/ +inline bool isHighSurrogate(sal_uInt32 code) { + assert(code <= 0x10FFFF); + return code >= detail::surrogatesHighFirst + && code <= detail::surrogatesHighLast; +} + +/** Check for low surrogate. + + @param code A Unicode code point. + + @return True if code is a low surrogate code point (0xDC00--0xDFFF). + + @since LibreOffice 5.0 +*/ +inline bool isLowSurrogate(sal_uInt32 code) { + assert(code <= 0x10FFFF); + return code >= detail::surrogatesLowFirst + && code <= detail::surrogatesLowLast; +} + +/** Get high surrogate half of a non-BMP Unicode code point. + + @param code A non-BMP Unicode code point. + + @return The UTF-16 high surrogate half for the give code point. + + @since LibreOffice 5.0 + */ +inline sal_Unicode getHighSurrogate(sal_uInt32 code) { + assert(code <= 0x10FFFF); + assert(code >= 0x10000); + return ((code - 0x10000) >> 10) | detail::surrogatesHighFirst; +} + +/** Get low surrogate half of a non-BMP Unicode code point. + + @param code A non-BMP Unicode code point. + + @return The UTF-16 low surrogate half for the give code point. + + @since LibreOffice 5.0 + */ +inline sal_Unicode getLowSurrogate(sal_uInt32 code) { + assert(code <= 0x10FFFF); + assert(code >= 0x10000); + return ((code - 0x10000) & 0x3FF) | detail::surrogatesLowFirst; +} + +/** Combine surrogates to form a code point. + + @param high A high surrogate code point. + + @param low A low surrogate code point. + + @return The code point represented by the surrogate pair. + + @since LibreOffice 5.0 +*/ +inline sal_uInt32 combineSurrogates(sal_uInt32 high, sal_uInt32 low) { + assert(isHighSurrogate(high)); + assert(isLowSurrogate(low)); + return ((high - detail::surrogatesHighFirst) << 10) + + (low - detail::surrogatesLowFirst) + 0x10000; +} + } #endif diff --git a/include/rtl/surrogates.h b/include/rtl/surrogates.h deleted file mode 100644 index ab98cd666ca3..000000000000 --- a/include/rtl/surrogates.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_RTL_SURROGATES_H -#define INCLUDED_RTL_SURROGATES_H - -#include <sal/config.h> - -#include <sal/types.h> - -#define SAL_RTL_FIRST_HIGH_SURROGATE 0xD800 -#define SAL_RTL_LAST_HIGH_SURROGATE 0xDBFF -#define SAL_RTL_FIRST_LOW_SURROGATE 0xDC00 -#define SAL_RTL_LAST_LOW_SURROGATE 0xDFFF - -#ifdef __cplusplus -extern "C" { -#endif - -inline bool isHighSurrogate(sal_uInt32 utf16) { - return utf16 >= SAL_RTL_FIRST_HIGH_SURROGATE - && utf16 <= SAL_RTL_LAST_HIGH_SURROGATE; -} - -inline bool isLowSurrogate(sal_uInt32 utf16) { - return utf16 >= SAL_RTL_FIRST_LOW_SURROGATE - && utf16 <= SAL_RTL_LAST_LOW_SURROGATE; -} - -inline sal_uInt32 combineSurrogates(sal_uInt32 high, sal_uInt32 low) { - return ((high - SAL_RTL_FIRST_HIGH_SURROGATE) << 10) - + (low - SAL_RTL_FIRST_LOW_SURROGATE) + 0x10000; -} - -#ifdef __cplusplus -} -#endif - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |