diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp new file mode 100644 index 0000000000..89b71b47ed --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibJS/Runtime/Intl/Segmenter.h> + +namespace JS::Intl { + +// 18 Segmenter Objects, https://tc39.es/ecma402/#segmenter-objects +Segmenter::Segmenter(Object& prototype) + : Object(prototype) +{ +} + +void Segmenter::set_segmenter_granularity(StringView segmenter_granularity) +{ + if (segmenter_granularity == "grapheme"sv) + m_segmenter_granularity = SegmenterGranularity::Grapheme; + else if (segmenter_granularity == "word"sv) + m_segmenter_granularity = SegmenterGranularity::Word; + else if (segmenter_granularity == "sentence"sv) + m_segmenter_granularity = SegmenterGranularity::Sentence; + else + VERIFY_NOT_REACHED(); +} + +StringView Segmenter::segmenter_granularity_string() const +{ + switch (m_segmenter_granularity) { + case SegmenterGranularity::Grapheme: + return "grapheme"sv; + case SegmenterGranularity::Word: + return "word"sv; + case SegmenterGranularity::Sentence: + return "sentence"sv; + default: + VERIFY_NOT_REACHED(); + } +} + +} |