#include "config.h"
#include "Hyphenation.h"
#include "AtomicStringKeyedMRUCache.h"
#include "Language.h"
#include "TextBreakIteratorInternalICU.h"
#include <wtf/ListHashSet.h>
#include <wtf/RetainPtr.h>
#include <wtf/text/StringView.h>
namespace WebCore {
template<>
RetainPtr<CFLocaleRef> AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef>>::createValueForNullKey()
{
RetainPtr<CFLocaleRef> locale = adoptCF(CFLocaleCreate(0, defaultLanguage().createCFString().get()));
return CFStringIsHyphenationAvailableForLocale(locale.get()) ? locale : 0;
}
template<>
RetainPtr<CFLocaleRef> AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef>>::createValueForKey(const AtomicString& localeIdentifier)
{
RetainPtr<CFLocaleRef> locale = adoptCF(CFLocaleCreate(kCFAllocatorDefault, localeIdentifier.string().createCFString().get()));
return CFStringIsHyphenationAvailableForLocale(locale.get()) ? locale : 0;
}
static AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef>>& cfLocaleCache()
{
DEPRECATED_DEFINE_STATIC_LOCAL(AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef>>, cache, ());
return cache;
}
bool canHyphenate(const AtomicString& localeIdentifier)
{
#if !PLATFORM(IOS)
return cfLocaleCache().get(localeIdentifier);
#else
#if !(defined(WTF_ARM_ARCH_VERSION) && WTF_ARM_ARCH_VERSION == 6)
return cfLocaleCache().get(localeIdentifier);
#else
UNUSED_PARAM(localeIdentifier);
return false;
#endif
#endif // PLATFORM(IOS)
}
size_t lastHyphenLocation(StringView text, size_t beforeIndex, const AtomicString& localeIdentifier)
{
RetainPtr<CFLocaleRef> locale = cfLocaleCache().get(localeIdentifier);
ASSERT(locale);
CFOptionFlags searchAcrossWordBoundaries = 1;
CFIndex result = CFStringGetHyphenationLocationBeforeIndex(text.createCFStringWithoutCopying().get(), beforeIndex, CFRangeMake(0, text.length()), searchAcrossWordBoundaries, locale.get(), 0);
return result == kCFNotFound ? 0 : result;
}
}