2021-09-06 22:18:48 -04:00
/*
2022-01-31 13:07:22 -05:00
* Copyright ( c ) 2022 , Tim Flynn < trflynn89 @ serenityos . org >
2021-09-06 22:18:48 -04:00
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
# pragma once
# include <AK/Array.h>
2022-12-04 18:02:33 +00:00
# include <AK/DeprecatedString.h>
2021-09-06 22:18:48 -04:00
# include <AK/StringView.h>
2022-02-20 21:00:37 +02:00
# include <LibJS/Runtime/Intl/CollatorCompareFunction.h>
2021-09-06 22:18:48 -04:00
# include <LibJS/Runtime/Object.h>
namespace JS : : Intl {
class Collator final : public Object {
JS_OBJECT ( Collator , Object ) ;
public :
enum class Usage {
Sort ,
Search ,
} ;
enum class Sensitivity {
Base ,
Accent ,
Case ,
Variant ,
} ;
enum class CaseFirst {
Upper ,
Lower ,
False ,
} ;
static constexpr auto relevant_extension_keys ( )
{
2022-03-15 10:33:30 -04:00
// 10.2.3 Internal slots, https://tc39.es/ecma402/#sec-intl-collator-internal-slots
2021-09-06 22:18:48 -04:00
// The value of the [[RelevantExtensionKeys]] internal slot is a List that must include the element "co", may include any or all of the elements "kf" and "kn", and must not include any other elements.
return AK : : Array { " co " sv , " kf " sv , " kn " sv } ;
}
virtual ~ Collator ( ) override = default ;
2022-12-04 18:02:33 +00:00
DeprecatedString const & locale ( ) const { return m_locale ; }
void set_locale ( DeprecatedString locale ) { m_locale = move ( locale ) ; }
2021-09-06 22:18:48 -04:00
Usage usage ( ) const { return m_usage ; }
void set_usage ( StringView usage ) ;
StringView usage_string ( ) const ;
Sensitivity sensitivity ( ) const { return m_sensitivity ; }
void set_sensitivity ( StringView sensitivity ) ;
StringView sensitivity_string ( ) const ;
CaseFirst case_first ( ) const { return m_case_first ; }
void set_case_first ( StringView case_first ) ;
StringView case_first_string ( ) const ;
2022-12-04 18:02:33 +00:00
DeprecatedString const & collation ( ) const { return m_collation ; }
void set_collation ( DeprecatedString collation ) { m_collation = move ( collation ) ; }
2021-09-06 22:18:48 -04:00
bool ignore_punctuation ( ) const { return m_ignore_punctuation ; }
void set_ignore_punctuation ( bool ignore_punctuation ) { m_ignore_punctuation = ignore_punctuation ; }
bool numeric ( ) const { return m_numeric ; }
void set_numeric ( bool numeric ) { m_numeric = numeric ; }
2022-02-20 21:00:37 +02:00
CollatorCompareFunction * bound_compare ( ) const { return m_bound_compare ; }
void set_bound_compare ( CollatorCompareFunction * bound_compare ) { m_bound_compare = bound_compare ; }
2021-09-06 22:18:48 -04:00
private :
2022-08-28 23:51:28 +02:00
explicit Collator ( Object & prototype ) ;
2022-02-20 21:00:37 +02:00
virtual void visit_edges ( Visitor & ) override ;
2022-12-04 18:02:33 +00:00
DeprecatedString m_locale ; // [[Locale]]
2022-02-20 21:00:37 +02:00
Usage m_usage { Usage : : Sort } ; // [[Usage]]
Sensitivity m_sensitivity { Sensitivity : : Variant } ; // [[Sensitivity]]
CaseFirst m_case_first { CaseFirst : : False } ; // [[CaseFirst]]
2022-12-04 18:02:33 +00:00
DeprecatedString m_collation ; // [[Collation]]
2022-02-20 21:00:37 +02:00
bool m_ignore_punctuation { false } ; // [[IgnorePunctuation]]
bool m_numeric { false } ; // [[Numeric]]
CollatorCompareFunction * m_bound_compare { nullptr } ; // [[BoundCompare]]
2021-09-06 22:18:48 -04:00
} ;
}