Commit afd03186 authored by ap@webkit.org's avatar ap@webkit.org

Reviewed by Darin.

        <rdar://problem/5687269> Need to create a Collator abstraction for WebCore and JavaScriptCore



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30842 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9dc74ec1
2008-03-06 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Darin.
<rdar://problem/5687269> Need to create a Collator abstraction for WebCore and JavaScriptCore
* wtf/Threading.h:
(WTF::initializeThreading):
* wtf/ThreadingGtk.cpp:
(WTF::initializeThreading):
* wtf/ThreadingNone.cpp:
* wtf/ThreadingPthreads.cpp:
* wtf/ThreadingWin.cpp:
Added AtomicallyInitializedStatic.
* kjs/string_object.cpp: (KJS::localeCompare): Changed to use Collator.
* GNUmakefile.am:
* JavaScriptCore.exp:
* JavaScriptCore.pri:
* JavaScriptCore.vcproj/WTF/WTF.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* JavaScriptCoreSources.bkl:
Added new fiiles to projects.
* wtf/unicode/Collator.h: Added.
(WTF::Collator::):
* wtf/unicode/CollatorDefault.cpp: Added.
(WTF::Collator::Collator):
(WTF::Collator::~Collator):
(WTF::Collator::setOrderLowerFirst):
(WTF::Collator::collate):
* wtf/unicode/icu/CollatorICU.cpp: Added.
(WTF::cachedCollatorMutex):
(WTF::Collator::Collator):
(WTF::Collator::~Collator):
(WTF::Collator::setOrderLowerFirst):
(WTF::Collator::collate):
(WTF::Collator::createCollator):
(WTF::Collator::releaseCollator):
2008-03-05 Kevin Ollivier <kevino@theolliviers.com> 2008-03-05 Kevin Ollivier <kevino@theolliviers.com>
Fix the wx build after the bindings move. Fix the wx build after the bindings move.
......
...@@ -48,6 +48,8 @@ javascriptcore_sources += \ ...@@ -48,6 +48,8 @@ javascriptcore_sources += \
JavaScriptCore/wtf/Assertions.cpp \ JavaScriptCore/wtf/Assertions.cpp \
JavaScriptCore/wtf/HashTable.cpp \ JavaScriptCore/wtf/HashTable.cpp \
JavaScriptCore/wtf/ThreadingGtk.cpp \ JavaScriptCore/wtf/ThreadingGtk.cpp \
JavaScriptCore/wtf/unicode/CollatorDefault.cpp \
JavaScriptCore/wtf/unicode/icu/CollatorICU.cpp \
JavaScriptCore/wtf/unicode/UTF8.cpp JavaScriptCore/wtf/unicode/UTF8.cpp
# Debug build # Debug build
......
...@@ -209,6 +209,7 @@ __ZN3WTF15ThreadConditionC1Ev ...@@ -209,6 +209,7 @@ __ZN3WTF15ThreadConditionC1Ev
__ZN3WTF15ThreadConditionD1Ev __ZN3WTF15ThreadConditionD1Ev
__ZN3WTF16fastZeroedMallocEm __ZN3WTF16fastZeroedMallocEm
__ZN3WTF23waitForThreadCompletionEjPPv __ZN3WTF23waitForThreadCompletionEjPPv
__ZN3WTF32atomicallyInitializedStaticMutexE
__ZN3WTF5Mutex4lockEv __ZN3WTF5Mutex4lockEv
__ZN3WTF5Mutex6unlockEv __ZN3WTF5Mutex6unlockEv
__ZN3WTF5Mutex7tryLockEv __ZN3WTF5Mutex7tryLockEv
...@@ -267,8 +268,11 @@ _jscore_collector_introspection ...@@ -267,8 +268,11 @@ _jscore_collector_introspection
_jscore_fastmalloc_introspection _jscore_fastmalloc_introspection
_kJSClassDefinitionEmpty _kJSClassDefinitionEmpty
_kjs_strtod _kjs_strtod
__ZN3WTF8Collator18setOrderLowerFirstEb
__ZN3WTF8CollatorC1EPKc
__ZN3WTF8CollatorD1Ev
__ZNK3WTF8Collator7collateEPKtmS2_m
__ZN3KJS10throwErrorEPNS_9ExecStateENS_9ErrorTypeERKNS_7UStringE __ZN3KJS10throwErrorEPNS_9ExecStateENS_9ErrorTypeERKNS_7UStringE
__ZNK3KJS8JSObject11hasPropertyEPNS_9ExecStateEj __ZNK3KJS8JSObject11hasPropertyEPNS_9ExecStateEj
__ZN3KJS7UString6appendEPKc __ZN3KJS7UString6appendEPKc
__ZN3KJS7CStringaSERKS0_ __ZN3KJS7CStringaSERKS0_
...@@ -36,6 +36,8 @@ KJSBISON += \ ...@@ -36,6 +36,8 @@ KJSBISON += \
SOURCES += \ SOURCES += \
wtf/Assertions.cpp \ wtf/Assertions.cpp \
wtf/HashTable.cpp \ wtf/HashTable.cpp \
wtf/unicode/CollatorDefault.cpp \
wtf/unicode/icu/CollatorICU.cpp \
wtf/unicode/UTF8.cpp \ wtf/unicode/UTF8.cpp \
bindings/NP_jsobject.cpp \ bindings/NP_jsobject.cpp \
bindings/npruntime.cpp \ bindings/npruntime.cpp \
......
...@@ -361,6 +361,18 @@ ...@@ -361,6 +361,18 @@
RelativePath="..\..\wtf\unicode\Unicode.h" RelativePath="..\..\wtf\unicode\Unicode.h"
> >
</File> </File>
<File
RelativePath="..\..\wtf\unicode\Collator.h"
>
</File>
<File
RelativePath="..\..\wtf\unicode\CollatorDefault.cpp"
>
</File>
<File
RelativePath="..\..\wtf\unicode\icu\CollatorICU.cpp"
>
</File>
<File <File
RelativePath="..\..\wtf\unicode\icu\UnicodeIcu.h" RelativePath="..\..\wtf\unicode\icu\UnicodeIcu.h"
> >
......
...@@ -190,6 +190,9 @@ ...@@ -190,6 +190,9 @@
E11D51760B2E798D0056C188 /* StringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = E11D51750B2E798D0056C188 /* StringExtras.h */; settings = {ATTRIBUTES = (Private, ); }; }; E11D51760B2E798D0056C188 /* StringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = E11D51750B2E798D0056C188 /* StringExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
E195679609E7CF1200B89D13 /* UnicodeIcu.h in Headers */ = {isa = PBXBuildFile; fileRef = E195678F09E7CF1200B89D13 /* UnicodeIcu.h */; settings = {ATTRIBUTES = (Private, ); }; }; E195679609E7CF1200B89D13 /* UnicodeIcu.h in Headers */ = {isa = PBXBuildFile; fileRef = E195678F09E7CF1200B89D13 /* UnicodeIcu.h */; settings = {ATTRIBUTES = (Private, ); }; };
E195679809E7CF1200B89D13 /* Unicode.h in Headers */ = {isa = PBXBuildFile; fileRef = E195679409E7CF1200B89D13 /* Unicode.h */; settings = {ATTRIBUTES = (Private, ); }; }; E195679809E7CF1200B89D13 /* Unicode.h in Headers */ = {isa = PBXBuildFile; fileRef = E195679409E7CF1200B89D13 /* Unicode.h */; settings = {ATTRIBUTES = (Private, ); }; };
E1A862A90D7EBB76001EC6AA /* CollatorICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1A862A80D7EBB76001EC6AA /* CollatorICU.cpp */; };
E1A862AB0D7EBB7D001EC6AA /* Collator.h in Headers */ = {isa = PBXBuildFile; fileRef = E1A862AA0D7EBB7D001EC6AA /* Collator.h */; settings = {ATTRIBUTES = (Private, ); }; };
E1A862D60D7F2B5C001EC6AA /* CollatorDefault.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1A862D50D7F2B5C001EC6AA /* CollatorDefault.cpp */; };
E1EE79230D6C95CD00FEA3BA /* Threading.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE79220D6C95CD00FEA3BA /* Threading.h */; settings = {ATTRIBUTES = (Private, ); }; }; E1EE79230D6C95CD00FEA3BA /* Threading.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE79220D6C95CD00FEA3BA /* Threading.h */; settings = {ATTRIBUTES = (Private, ); }; };
E1EE79280D6C964500FEA3BA /* Locker.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE79270D6C964500FEA3BA /* Locker.h */; settings = {ATTRIBUTES = (Private, ); }; }; E1EE79280D6C964500FEA3BA /* Locker.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE79270D6C964500FEA3BA /* Locker.h */; settings = {ATTRIBUTES = (Private, ); }; };
E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */; }; E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */; };
...@@ -486,6 +489,9 @@ ...@@ -486,6 +489,9 @@
E11D51750B2E798D0056C188 /* StringExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringExtras.h; sourceTree = "<group>"; }; E11D51750B2E798D0056C188 /* StringExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringExtras.h; sourceTree = "<group>"; };
E195678F09E7CF1200B89D13 /* UnicodeIcu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicodeIcu.h; sourceTree = "<group>"; }; E195678F09E7CF1200B89D13 /* UnicodeIcu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicodeIcu.h; sourceTree = "<group>"; };
E195679409E7CF1200B89D13 /* Unicode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unicode.h; sourceTree = "<group>"; }; E195679409E7CF1200B89D13 /* Unicode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unicode.h; sourceTree = "<group>"; };
E1A862A80D7EBB76001EC6AA /* CollatorICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CollatorICU.cpp; sourceTree = "<group>"; };
E1A862AA0D7EBB7D001EC6AA /* Collator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Collator.h; sourceTree = "<group>"; };
E1A862D50D7F2B5C001EC6AA /* CollatorDefault.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CollatorDefault.cpp; sourceTree = "<group>"; };
E1EE79220D6C95CD00FEA3BA /* Threading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Threading.h; sourceTree = "<group>"; }; E1EE79220D6C95CD00FEA3BA /* Threading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Threading.h; sourceTree = "<group>"; };
E1EE79270D6C964500FEA3BA /* Locker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Locker.h; sourceTree = "<group>"; }; E1EE79270D6C964500FEA3BA /* Locker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Locker.h; sourceTree = "<group>"; };
E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadingPthreads.cpp; sourceTree = "<group>"; }; E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadingPthreads.cpp; sourceTree = "<group>"; };
...@@ -926,6 +932,8 @@ ...@@ -926,6 +932,8 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
E195678E09E7CF1200B89D13 /* icu */, E195678E09E7CF1200B89D13 /* icu */,
E1A862AA0D7EBB7D001EC6AA /* Collator.h */,
E1A862D50D7F2B5C001EC6AA /* CollatorDefault.cpp */,
E195679409E7CF1200B89D13 /* Unicode.h */, E195679409E7CF1200B89D13 /* Unicode.h */,
E1EF79A80CE97BA60088D500 /* UTF8.cpp */, E1EF79A80CE97BA60088D500 /* UTF8.cpp */,
E1EF79A90CE97BA60088D500 /* UTF8.h */, E1EF79A90CE97BA60088D500 /* UTF8.h */,
...@@ -936,6 +944,7 @@ ...@@ -936,6 +944,7 @@
E195678E09E7CF1200B89D13 /* icu */ = { E195678E09E7CF1200B89D13 /* icu */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
E1A862A80D7EBB76001EC6AA /* CollatorICU.cpp */,
E195678F09E7CF1200B89D13 /* UnicodeIcu.h */, E195678F09E7CF1200B89D13 /* UnicodeIcu.h */,
); );
path = icu; path = icu;
...@@ -1079,6 +1088,7 @@ ...@@ -1079,6 +1088,7 @@
932F5B5C0822A1C700736975 /* ustring.h in Headers */, 932F5B5C0822A1C700736975 /* ustring.h in Headers */,
14ABB36F099C076400E2A24F /* value.h in Headers */, 14ABB36F099C076400E2A24F /* value.h in Headers */,
E1EE79280D6C964500FEA3BA /* Locker.h in Headers */, E1EE79280D6C964500FEA3BA /* Locker.h in Headers */,
E1A862AB0D7EBB7D001EC6AA /* Collator.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -1329,6 +1339,8 @@ ...@@ -1329,6 +1339,8 @@
937013480CA97E0E00FA14D3 /* pcre_ucp_searchfuncs.cpp in Sources */, 937013480CA97E0E00FA14D3 /* pcre_ucp_searchfuncs.cpp in Sources */,
93E26BD408B1514100F85226 /* pcre_xclass.cpp in Sources */, 93E26BD408B1514100F85226 /* pcre_xclass.cpp in Sources */,
E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */, E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */,
E1A862A90D7EBB76001EC6AA /* CollatorICU.cpp in Sources */,
E1A862D60D7F2B5C001EC6AA /* CollatorDefault.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
......
...@@ -100,6 +100,8 @@ Source files for JSCore. ...@@ -100,6 +100,8 @@ Source files for JSCore.
wtf/HashTable.cpp wtf/HashTable.cpp
wtf/TCSystemAlloc.cpp wtf/TCSystemAlloc.cpp
wtf/ThreadingNone.cpp wtf/ThreadingNone.cpp
wtf/unicode/CollatorDefault.cpp
wtf/unicode/icu/CollatorICU.cpp
wtf/unicode/UTF8.cpp wtf/unicode/UTF8.cpp
</set> </set>
......
...@@ -30,13 +30,7 @@ ...@@ -30,13 +30,7 @@
#include "operations.h" #include "operations.h"
#include "regexp_object.h" #include "regexp_object.h"
#include <wtf/MathExtras.h> #include <wtf/MathExtras.h>
#include <wtf/unicode/Unicode.h> #include <wtf/unicode/Collator.h>
#if PLATFORM(CF)
#include <CoreFoundation/CoreFoundation.h>
#elif PLATFORM(WIN_OS)
#include <windows.h>
#endif
using namespace WTF; using namespace WTF;
...@@ -294,26 +288,10 @@ static inline UString substituteBackreferences(const UString &replacement, const ...@@ -294,26 +288,10 @@ static inline UString substituteBackreferences(const UString &replacement, const
return substitutedReplacement; return substitutedReplacement;
} }
static inline int localeCompare(const UString& a, const UString& b) static inline int localeCompare(const UString& a, const UString& b)
{ {
#if PLATFORM(WIN_OS) return Collator::userDefault()->collate(reinterpret_cast<const ::UChar*>(a.data()), a.size(), reinterpret_cast<const ::UChar*>(b.data()), b.size());
int retval = CompareStringW(LOCALE_USER_DEFAULT, 0,
reinterpret_cast<LPCWSTR>(a.data()), a.size(),
reinterpret_cast<LPCWSTR>(b.data()), b.size());
return !retval ? retval : retval - 2;
#elif PLATFORM(CF)
CFStringRef sa = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(a.data()), a.size(), kCFAllocatorNull);
CFStringRef sb = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(b.data()), b.size(), kCFAllocatorNull);
int retval = CFStringCompare(sa, sb, kCFCompareLocalized);
CFRelease(sa);
CFRelease(sb);
return retval;
#else
return compare(a, b);
#endif
} }
static JSValue *replace(ExecState *exec, StringImp* sourceVal, JSValue *pattern, JSValue *replacement) static JSValue *replace(ExecState *exec, StringImp* sourceVal, JSValue *pattern, JSValue *replacement)
......
...@@ -91,6 +91,12 @@ class QWaitCondition; ...@@ -91,6 +91,12 @@ class QWaitCondition;
#include <stdint.h> #include <stdint.h>
// For portability, we do not use thread-safe statics natively supported by some compilers (e.g. gcc).
#define AtomicallyInitializedStatic(T, name) \
WTF::atomicallyInitializedStaticMutex->lock(); \
static T name; \
WTF::atomicallyInitializedStaticMutex->unlock();
namespace WTF { namespace WTF {
typedef uint32_t ThreadIdentifier; typedef uint32_t ThreadIdentifier;
...@@ -232,9 +238,13 @@ private: ...@@ -232,9 +238,13 @@ private:
void initializeThreading(); void initializeThreading();
extern Mutex* atomicallyInitializedStaticMutex;
#if !PLATFORM(GTK) #if !PLATFORM(GTK)
inline void initializeThreading() inline void initializeThreading()
{ {
if (!atomicallyInitializedStaticMutex)
atomicallyInitializedStaticMutex = new Mutex;
} }
#endif #endif
......
...@@ -36,10 +36,15 @@ ...@@ -36,10 +36,15 @@
namespace WTF { namespace WTF {
Mutex* atomicallyInitializedStaticMutex;
void initializeThreading() void initializeThreading()
{ {
if (!g_thread_supported()) if (!g_thread_supported()) {
g_thread_init(NULL); g_thread_init(NULL);
ASSERT(!atomicallyInitializedStaticMutex);
atomicallyInitializedStaticMutex = new Mutex;
}
ASSERT(g_thread_supported()); ASSERT(g_thread_supported());
} }
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
namespace WTF { namespace WTF {
Mutex* atomicallyInitializedStaticMutex;
ThreadIdentifier createThread(ThreadFunction, void*) { return 0; } ThreadIdentifier createThread(ThreadFunction, void*) { return 0; }
int waitForThreadCompletion(ThreadIdentifier, void**) { return 0; } int waitForThreadCompletion(ThreadIdentifier, void**) { return 0; }
void detachThread(ThreadIdentifier) { } void detachThread(ThreadIdentifier) { }
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
namespace WTF { namespace WTF {
Mutex* atomicallyInitializedStaticMutex;
static Mutex& threadMapMutex() static Mutex& threadMapMutex()
{ {
static Mutex mutex; static Mutex mutex;
......
...@@ -68,6 +68,8 @@ ...@@ -68,6 +68,8 @@
namespace WTF { namespace WTF {
Mutex* atomicallyInitializedStaticMutex;
static Mutex& threadMapMutex() static Mutex& threadMapMutex()
{ {
static Mutex mutex; static Mutex mutex;
......
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 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
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WTF_Collator_h
#define WTF_Collator_h
#include <memory>
#include <wtf/Noncopyable.h>
#include <wtf/unicode/Unicode.h>
#if USE(ICU_UNICODE) && !UCONFIG_NO_COLLATION
struct UCollator;
#endif
namespace WTF {
class Collator : Noncopyable {
public:
enum Result { Equal = 0, Greater = 1, Less = -1 };
Collator(const char* locale); // Parsing is lenient; e.g. language identifiers (such as "en-US") are accepted, too.
~Collator();
void setOrderLowerFirst(bool);
static std::auto_ptr<Collator> userDefault();
Result collate(const ::UChar*, size_t, const ::UChar*, size_t) const;
private:
#if USE(ICU_UNICODE) && !UCONFIG_NO_COLLATION
void createCollator() const;
void releaseCollator();
mutable UCollator* m_collator;
#endif
char* m_locale;
bool m_lowerFirst;
};
}
using WTF::Collator;
#endif
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 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
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "Collator.h"
#if !USE(ICU_UNICODE) || UCONFIG_NO_COLLATION
namespace WTF {
Collator::Collator(const char*)
{
}
Collator::~Collator()
{
}
void Collator::setOrderLowerFirst(bool)
{
}
std::auto_ptr<Collator> Collator::userDefault()
{
return std::auto_ptr<Collator>(new Collator);
}
// 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 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;
}
}
#endif
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 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
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "Collator.h"
#if USE(ICU_UNICODE) && !UCONFIG_NO_COLLATION
#include "Assertions.h"
#include "Threading.h"
#include <unicode/ucol.h>
#if PLATFORM(DARWIN)
#include <Corefoundation/CoreFoundation.h>
#endif
namespace WTF {
static UCollator* cachedCollator;
static Mutex& cachedCollatorMutex()
{
AtomicallyInitializedStatic(Mutex, mutex);
return mutex;
}
Collator::Collator(const char* locale)
: m_collator(0)
, m_locale(locale ? strdup(locale) : 0)
, m_lowerFirst(false)
{
}
std::auto_ptr<Collator> Collator::userDefault()
{
#if PLATFORM(DARWIN)
// Mac OS X doesn't set UNIX locale to match user-selected one, so ICU default doesn't work.
CFStringRef collationOrder = (CFStringRef)CFPreferencesCopyValue(CFSTR("AppleCollationOrder"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
char buf[256];
if (collationOrder) {
CFStringGetCString(collationOrder, buf, sizeof(buf), kCFStringEncodingASCII);
CFRelease(collationOrder);
return std::auto_ptr<Collator>(new Collator(buf));
} else
return std::auto_ptr<Collator>(new Collator(""));
#else
return std::auto_ptr<Collator>(new Collator(0));
#endif
}
Collator::~Collator()
{
releaseCollator();
free(m_locale);
}
void Collator::setOrderLowerFirst(bool lowerFirst)
{
m_lowerFirst = lowerFirst;
}