diff options
Diffstat (limited to 'thirdparty/icu4c/common/uprops.cpp')
-rw-r--r-- | thirdparty/icu4c/common/uprops.cpp | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/thirdparty/icu4c/common/uprops.cpp b/thirdparty/icu4c/common/uprops.cpp index 1604ad9a17..5186a0c75c 100644 --- a/thirdparty/icu4c/common/uprops.cpp +++ b/thirdparty/icu4c/common/uprops.cpp @@ -30,7 +30,9 @@ #include "unicode/unorm2.h" #include "unicode/uscript.h" #include "unicode/ustring.h" +#include "unicode/utf16.h" #include "cstring.h" +#include "emojiprops.h" #include "mutex.h" #include "normalizer2impl.h" #include "umutex.h" @@ -322,6 +324,10 @@ static UBool isRegionalIndicator(const BinaryProperty &/*prop*/, UChar32 c, UPro return 0x1F1E6<=c && c<=0x1F1FF; } +static UBool hasEmojiProperty(const BinaryProperty &/*prop*/, UChar32 c, UProperty which) { + return EmojiProps::hasBinaryProperty(c, which); +} + static const BinaryProperty binProps[UCHAR_BINARY_LIMIT]={ /* * column and mask values for binary properties from u_getUnicodeProperties(). @@ -388,14 +394,21 @@ static const BinaryProperty binProps[UCHAR_BINARY_LIMIT]={ { UPROPS_SRC_CASE_AND_NORM, 0, changesWhenCasefolded }, { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CHANGES_WHEN_CASEMAPPED { UPROPS_SRC_NFKC_CF, 0, changesWhenNFKC_Casefolded }, - { 2, U_MASK(UPROPS_2_EMOJI), defaultContains }, - { 2, U_MASK(UPROPS_2_EMOJI_PRESENTATION), defaultContains }, - { 2, U_MASK(UPROPS_2_EMOJI_MODIFIER), defaultContains }, - { 2, U_MASK(UPROPS_2_EMOJI_MODIFIER_BASE), defaultContains }, - { 2, U_MASK(UPROPS_2_EMOJI_COMPONENT), defaultContains }, + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_EMOJI + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_EMOJI_PRESENTATION + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_EMOJI_MODIFIER + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_EMOJI_MODIFIER_BASE + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_EMOJI_COMPONENT { 2, 0, isRegionalIndicator }, { 1, U_MASK(UPROPS_PREPENDED_CONCATENATION_MARK), defaultContains }, - { 2, U_MASK(UPROPS_2_EXTENDED_PICTOGRAPHIC), defaultContains }, + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_EXTENDED_PICTOGRAPHIC + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_BASIC_EMOJI + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_EMOJI_KEYCAP_SEQUENCE + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_RGI_EMOJI_MODIFIER_SEQUENCE + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_RGI_EMOJI_FLAG_SEQUENCE + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_RGI_EMOJI_TAG_SEQUENCE + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_RGI_EMOJI_ZWJ_SEQUENCE + { UPROPS_SRC_EMOJI, 0, hasEmojiProperty }, // UCHAR_RGI_EMOJI }; U_CAPI UBool U_EXPORT2 @@ -410,6 +423,26 @@ u_hasBinaryProperty(UChar32 c, UProperty which) { } } +U_CAPI UBool U_EXPORT2 +u_stringHasBinaryProperty(const UChar *s, int32_t length, UProperty which) { + if (s == nullptr && length != 0) { return false; } + if (length == 1) { + return u_hasBinaryProperty(s[0], which); // single code point + } else if (length == 2 || (length < 0 && *s != 0)) { // not empty string + // first code point + int32_t i = 0; + UChar32 c; + U16_NEXT(s, i, length, c); + if (length > 0 ? i == length : s[i] == 0) { + return u_hasBinaryProperty(c, which); // single code point + } + } + // Only call into EmojiProps for a relevant property, + // so that we not unnecessarily try to load its data file. + return UCHAR_BASIC_EMOJI <= which && which <= UCHAR_RGI_EMOJI && + EmojiProps::hasBinaryProperty(s, length, which); +} + struct IntProperty; typedef int32_t IntPropertyGetValue(const IntProperty &prop, UChar32 c, UProperty which); |