#pragma once
#include "JSObject.h"
#include <unicode/ucol.h>
#include <wtf/unicode/icu/ICUHelpers.h>
namespace JSC {
enum class RelevantExtensionKey : uint8_t;
class JSBoundFunction;
class IntlCollator final : public JSNonFinalObject {
public:
using Base = JSNonFinalObject;
static constexpr bool needsDestruction = true;
static void destroy(JSCell* cell)
{
static_cast<IntlCollator*>(cell)->IntlCollator::~IntlCollator();
}
template<typename CellType, SubspaceAccess mode>
static IsoSubspace* subspaceFor(VM& vm)
{
return vm.intlCollatorSpace<mode>();
}
static IntlCollator* create(VM&, Structure*);
static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
DECLARE_INFO;
void initializeCollator(JSGlobalObject*, JSValue locales, JSValue optionsValue);
JSValue compareStrings(JSGlobalObject*, StringView, StringView) const;
JSObject* resolvedOptions(JSGlobalObject*) const;
JSBoundFunction* boundCompare() const { return m_boundCompare.get(); }
void setBoundCompare(VM&, JSBoundFunction*);
bool canDoASCIIUCADUCETComparison() const
{
if (m_canDoASCIIUCADUCETComparison == TriState::Indeterminate)
updateCanDoASCIIUCADUCETComparison();
return m_canDoASCIIUCADUCETComparison == TriState::True;
}
#if ASSERT_ENABLED
static void checkICULocaleInvariants(const HashSet<String>&);
#else
static inline void checkICULocaleInvariants(const HashSet<String>&) { }
#endif
private:
IntlCollator(VM&, Structure*);
void finishCreation(VM&);
static void visitChildren(JSCell*, SlotVisitor&);
bool updateCanDoASCIIUCADUCETComparison() const;
static Vector<String> sortLocaleData(const String&, RelevantExtensionKey);
static Vector<String> searchLocaleData(const String&, RelevantExtensionKey);
enum class Usage : uint8_t { Sort, Search };
enum class Sensitivity : uint8_t { Base, Accent, Case, Variant };
enum class CaseFirst : uint8_t { Upper, Lower, False };
using UCollatorDeleter = ICUDeleter<ucol_close>;
static ASCIILiteral usageString(Usage);
static ASCIILiteral sensitivityString(Sensitivity);
static ASCIILiteral caseFirstString(CaseFirst);
WriteBarrier<JSBoundFunction> m_boundCompare;
std::unique_ptr<UCollator, UCollatorDeleter> m_collator;
String m_locale;
String m_collation;
Usage m_usage;
Sensitivity m_sensitivity;
CaseFirst m_caseFirst;
mutable TriState m_canDoASCIIUCADUCETComparison { TriState::Indeterminate };
bool m_numeric;
bool m_ignorePunctuation;
};
}