/src/serenity/Userland/Libraries/LibWeb/DOM/CharacterData.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/String.h> |
10 | | #include <AK/Utf16View.h> |
11 | | #include <LibLocale/Forward.h> |
12 | | #include <LibWeb/DOM/ChildNode.h> |
13 | | #include <LibWeb/DOM/Node.h> |
14 | | #include <LibWeb/DOM/NonDocumentTypeChildNode.h> |
15 | | |
16 | | namespace Web::DOM { |
17 | | |
18 | | // https://dom.spec.whatwg.org/#characterdata |
19 | | class CharacterData |
20 | | : public Node |
21 | | , public ChildNode<CharacterData> |
22 | | , public NonDocumentTypeChildNode<CharacterData> { |
23 | | WEB_PLATFORM_OBJECT(CharacterData, Node); |
24 | | JS_DECLARE_ALLOCATOR(CharacterData); |
25 | | |
26 | | public: |
27 | | virtual ~CharacterData() override; |
28 | | |
29 | 0 | String const& data() const { return m_data; } |
30 | | void set_data(String const&); |
31 | | |
32 | | unsigned length_in_utf16_code_units() const |
33 | 0 | { |
34 | 0 | return AK::utf16_code_unit_length_from_utf8(m_data); |
35 | 0 | } |
36 | | |
37 | | WebIDL::ExceptionOr<String> substring_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units) const; |
38 | | WebIDL::ExceptionOr<void> append_data(String const&); |
39 | | WebIDL::ExceptionOr<void> insert_data(size_t offset_in_utf16_code_units, String const&); |
40 | | WebIDL::ExceptionOr<void> delete_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units); |
41 | | WebIDL::ExceptionOr<void> replace_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units, String const&); |
42 | | |
43 | | Locale::Segmenter& grapheme_segmenter() const; |
44 | | Locale::Segmenter& word_segmenter() const; |
45 | | |
46 | | protected: |
47 | | CharacterData(Document&, NodeType, String const&); |
48 | | |
49 | | virtual void initialize(JS::Realm&) override; |
50 | | |
51 | | private: |
52 | | String m_data; |
53 | | |
54 | | mutable OwnPtr<Locale::Segmenter> m_grapheme_segmenter; |
55 | | mutable OwnPtr<Locale::Segmenter> m_word_segmenter; |
56 | | }; |
57 | | |
58 | | } |