#include "config.h"
#include "Hyphenation.h"
#include "AtomicStringKeyedMRUCache.h"
#include "TextBreakIteratorInternalICU.h"
#include <wtf/ListHashSet.h>
#include <wtf/RetainPtr.h>
#include <wtf/UnusedParam.h>
namespace WebCore {
#if !PLATFORM(WIN) || (defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
template<>
RetainPtr<CFLocaleRef> AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef> >::createValueForNullKey()
{
RetainPtr<CFLocaleRef> locale(AdoptCF, CFLocaleCopyCurrent());
return CFStringIsHyphenationAvailableForLocale(locale.get()) ? locale : 0;
}
template<>
RetainPtr<CFLocaleRef> AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef> >::createValueForKey(const AtomicString& localeIdentifier)
{
RetainPtr<CFStringRef> cfLocaleIdentifier(AdoptCF, localeIdentifier.createCFString());
RetainPtr<CFLocaleRef> locale(AdoptCF, CFLocaleCreate(kCFAllocatorDefault, cfLocaleIdentifier.get()));
return CFStringIsHyphenationAvailableForLocale(locale.get()) ? locale : 0;
}
static AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef> >& cfLocaleCache()
{
DEFINE_STATIC_LOCAL(AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef> >, cache, ());
return cache;
}
bool canHyphenate(const AtomicString& localeIdentifier)
{
#if !(defined(WTF_ARM_ARCH_VERSION) && WTF_ARM_ARCH_VERSION == 6)
return cfLocaleCache().get(localeIdentifier);
#else
UNUSED_PARAM(localeIdentifier);
return false;
#endif
}
size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeIndex, const AtomicString& localeIdentifier)
{
RetainPtr<CFStringRef> string(AdoptCF, CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(characters), length, kCFAllocatorNull));
RetainPtr<CFLocaleRef> locale = cfLocaleCache().get(localeIdentifier);
ASSERT(locale);
CFIndex result = CFStringGetHyphenationLocationBeforeIndex(string.get(), beforeIndex, CFRangeMake(0, length), 0, locale.get(), 0);
return result == kCFNotFound ? 0 : result;
}
#else
bool canHyphenate(const AtomicString&)
{
return false;
}
size_t lastHyphenLocation(const UChar*, size_t, size_t, const AtomicString&)
{
ASSERT_NOT_REACHED();
return 0;
}
#endif // PLATFORM(WIN) && (!defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7)
}