summaryrefslogtreecommitdiff
path: root/Source/WTF/wtf/unicode/CollatorDefault.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WTF/wtf/unicode/CollatorDefault.cpp')
-rw-r--r--Source/WTF/wtf/unicode/CollatorDefault.cpp48
1 files changed, 17 insertions, 31 deletions
diff --git a/Source/WTF/wtf/unicode/CollatorDefault.cpp b/Source/WTF/wtf/unicode/CollatorDefault.cpp
index d56bb5a38..eab171bf2 100644
--- a/Source/WTF/wtf/unicode/CollatorDefault.cpp
+++ b/Source/WTF/wtf/unicode/CollatorDefault.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -33,41 +33,27 @@
namespace WTF {
-Collator::Collator(const char*)
+int Collator::collate(StringView a, StringView b) const
{
-}
-
-Collator::~Collator()
-{
-}
+ unsigned commonLength = std::min(a.length(), b.length());
+ for (unsigned i = 0; i < commonLength; ++i) {
+ if (a[i] < b[i])
+ return -1;
+ if (a[i] > b[i])
+ return 1;
+ }
-void Collator::setOrderLowerFirst(bool)
-{
-}
+ if (a.length() < b.length())
+ return -1;
+ if (a.length() > b.length())
+ return 1;
-std::unique_ptr<Collator> Collator::userDefault()
-{
- return std::make_unique<Collator>(nullptr);
+ return 0;
}
-// A default implementation for platforms that lack Unicode-aware collation.
-Collator::Result Collator::collate(const UChar* lhs, size_t lhsLength, const UChar* rhs, size_t rhsLength) const
+int Collator::collateUTF8(const char* a, const char* b) const
{
- int lmin = lhsLength < rhsLength ? lhsLength : rhsLength;
- int l = 0;
- while (l < lmin && *lhs == *rhs) {
- lhs++;
- rhs++;
- l++;
- }
-
- if (l < lmin)
- return (*lhs > *rhs) ? Greater : Less;
-
- if (lhsLength == rhsLength)
- return Equal;
-
- return (lhsLength > rhsLength) ? Greater : Less;
+ return collate(String::fromUTF8(a), String::fromUTF8(b));
}
}