From 0bfacb1f616c3de99aa27f612b27cc5b51a02bef Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 25 Nov 2015 17:05:28 -0600 Subject: [PATCH] Adding support for String CompareOptions IgnoreNonSpace and IgnoreSymbols. --- .../System.Globalization.Native/collation.cpp | 38 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/corefx/System.Globalization.Native/collation.cpp b/src/corefx/System.Globalization.Native/collation.cpp index 5a918d2..c305ccf 100644 --- a/src/corefx/System.Globalization.Native/collation.cpp +++ b/src/corefx/System.Globalization.Native/collation.cpp @@ -13,8 +13,8 @@ #include const int32_t CompareOptionsIgnoreCase = 1; -// const int32_t CompareOptionsIgnoreNonSpace = 2; -// const int32_t CompareOptionsIgnoreSymbols = 4; +const int32_t CompareOptionsIgnoreNonSpace = 2; +const int32_t CompareOptionsIgnoreSymbols = 4; // const int32_t CompareOptionsIgnoreKanaType = 8; // const int32_t CompareOptionsIgnoreWidth = 0x10; // const int32_t CompareOptionsStringSort = 0x20000000; @@ -39,18 +39,46 @@ typedef struct _sort_handle } SortHandle; /* - * To collator returned by this function is owned by the callee and must be + * The collator returned by this function is owned by the callee and must be * closed when this method returns with a U_SUCCESS UErrorCode. * * On error, the return value is undefined. */ UCollator* CloneCollatorWithOptions(const UCollator* pCollator, int32_t options, UErrorCode* pErr) { + UColAttributeValue strength = UCOL_DEFAULT; + + bool isIgnoreCase = (options & CompareOptionsIgnoreCase) == CompareOptionsIgnoreCase; + bool isIgnoreNonSpace = (options & CompareOptionsIgnoreNonSpace) == CompareOptionsIgnoreNonSpace; + bool isIgnoreSymbols = (options & CompareOptionsIgnoreSymbols) == CompareOptionsIgnoreSymbols; + + if (isIgnoreCase) + { + strength = UCOL_SECONDARY; + } + + if (isIgnoreNonSpace) + { + strength = UCOL_PRIMARY; + } + UCollator* pClonedCollator = ucol_safeClone(pCollator, nullptr, nullptr, pErr); - if ((options & CompareOptionsIgnoreCase) == CompareOptionsIgnoreCase) + if (isIgnoreSymbols) + { + ucol_setAttribute(pClonedCollator, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, pErr); + } + + if (strength != UCOL_DEFAULT) { - ucol_setAttribute(pClonedCollator, UCOL_STRENGTH, UCOL_SECONDARY, pErr); + ucol_setAttribute(pClonedCollator, UCOL_STRENGTH, strength, pErr); + + // casing differs at the tertiary level. + // if strength is less than tertiary, but we are not ignoring case, then we need to flip CASE_LEVEL On + if (strength < UCOL_TERTIARY && !isIgnoreCase) + { + ucol_setAttribute(pClonedCollator, UCOL_CASE_LEVEL, UCOL_ON, pErr); + } } return pClonedCollator; -- 2.7.4