summaryrefslogtreecommitdiff
path: root/src/corefx
diff options
context:
space:
mode:
authorEric Erhardt <eric.erhardt@microsoft.com>2015-11-25 17:05:28 -0600
committerEric Erhardt <eric.erhardt@microsoft.com>2015-12-07 09:44:43 -0600
commit0bfacb1f616c3de99aa27f612b27cc5b51a02bef (patch)
tree4267ce8b02c0d9025649e67d99173210141065c0 /src/corefx
parent29fcc5288868df48ff1e156f8be85f33ce7d7e78 (diff)
downloadcoreclr-0bfacb1f616c3de99aa27f612b27cc5b51a02bef.tar.gz
coreclr-0bfacb1f616c3de99aa27f612b27cc5b51a02bef.tar.bz2
coreclr-0bfacb1f616c3de99aa27f612b27cc5b51a02bef.zip
Adding support for String CompareOptions IgnoreNonSpace and IgnoreSymbols.
Diffstat (limited to 'src/corefx')
-rw-r--r--src/corefx/System.Globalization.Native/collation.cpp38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/corefx/System.Globalization.Native/collation.cpp b/src/corefx/System.Globalization.Native/collation.cpp
index 5a918d293c..c305ccffff 100644
--- a/src/corefx/System.Globalization.Native/collation.cpp
+++ b/src/corefx/System.Globalization.Native/collation.cpp
@@ -13,8 +13,8 @@
#include <unicode/utf16.h>
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;