/src/serenity/AK/DeprecatedFlyString.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/ByteString.h> |
10 | | #include <AK/StringUtils.h> |
11 | | |
12 | | namespace AK { |
13 | | |
14 | | class DeprecatedFlyString { |
15 | | public: |
16 | | DeprecatedFlyString() |
17 | 25.9k | : m_impl(StringImpl::the_empty_stringimpl()) |
18 | 25.9k | { |
19 | 25.9k | } |
20 | | DeprecatedFlyString(DeprecatedFlyString const& other) |
21 | 1.00k | : m_impl(other.impl()) |
22 | 1.00k | { |
23 | 1.00k | } |
24 | | DeprecatedFlyString(DeprecatedFlyString&& other) |
25 | 850 | : m_impl(move(other.m_impl)) |
26 | 850 | { |
27 | 850 | } |
28 | | DeprecatedFlyString(ByteString const&); |
29 | | DeprecatedFlyString(StringView); |
30 | | DeprecatedFlyString(char const* string) |
31 | 534 | : DeprecatedFlyString(static_cast<ByteString>(string)) |
32 | 534 | { |
33 | 534 | } |
34 | | |
35 | | static DeprecatedFlyString from_fly_impl(NonnullRefPtr<StringImpl const> impl) |
36 | 0 | { |
37 | 0 | VERIFY(impl->is_fly()); |
38 | 0 | DeprecatedFlyString string; |
39 | 0 | string.m_impl = move(impl); |
40 | 0 | return string; |
41 | 0 | } |
42 | | |
43 | | DeprecatedFlyString& operator=(DeprecatedFlyString const& other) |
44 | 0 | { |
45 | 0 | m_impl = other.m_impl; |
46 | 0 | return *this; |
47 | 0 | } |
48 | | |
49 | | DeprecatedFlyString& operator=(DeprecatedFlyString&& other) |
50 | 0 | { |
51 | 0 | m_impl = move(other.m_impl); |
52 | 0 | return *this; |
53 | 0 | } |
54 | | |
55 | 28.0k | bool is_empty() const { return !m_impl->length(); } |
56 | | |
57 | 3.18k | bool operator==(DeprecatedFlyString const& other) const { return m_impl == other.m_impl; } |
58 | | |
59 | | bool operator==(ByteString const&) const; |
60 | | |
61 | | bool operator==(StringView) const; |
62 | | |
63 | | bool operator==(char const*) const; |
64 | | |
65 | 1.01k | NonnullRefPtr<StringImpl const> impl() const { return m_impl; } |
66 | 0 | char const* characters() const { return m_impl->characters(); } |
67 | 0 | size_t length() const { return m_impl->length(); } |
68 | | |
69 | 2.25k | ALWAYS_INLINE u32 hash() const { return m_impl->existing_hash(); } |
70 | 284 | ALWAYS_INLINE StringView view() const { return m_impl->view(); } |
71 | | |
72 | | DeprecatedFlyString to_lowercase() const; |
73 | | |
74 | | template<Arithmetic T> |
75 | | Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const |
76 | 0 | { |
77 | 0 | return view().to_number<T>(trim_whitespace); |
78 | 0 | } Unexecuted instantiation: _ZNK2AK19DeprecatedFlyString9to_numberITkNS_8Concepts10ArithmeticEjEENS_8OptionalIT_EENS_14TrimWhitespaceE Unexecuted instantiation: _ZNK2AK19DeprecatedFlyString9to_numberITkNS_8Concepts10ArithmeticEdEENS_8OptionalIT_EENS_14TrimWhitespaceE |
79 | | |
80 | | bool equals_ignoring_ascii_case(StringView) const; |
81 | | bool starts_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; |
82 | | bool ends_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; |
83 | | |
84 | | static void did_destroy_impl(Badge<StringImpl>, StringImpl&); |
85 | | |
86 | | template<typename... Ts> |
87 | | [[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const |
88 | 0 | { |
89 | 0 | return (... || this->operator==(forward<Ts>(strings))); |
90 | 0 | } Unexecuted instantiation: bool AK::DeprecatedFlyString::is_one_of<AK::StringView, AK::StringView>(AK::StringView&&, AK::StringView&&) const Unexecuted instantiation: bool AK::DeprecatedFlyString::is_one_of<char const (&) [10], char const (&) [11], char const (&) [18], char const (&) [11], char const (&) [12], char const (&) [11], char const (&) [12], char const (&) [14], char const (&) [15]>(char const (&) [10], char const (&) [11], char const (&) [18], char const (&) [11], char const (&) [12], char const (&) [11], char const (&) [12], char const (&) [14], char const (&) [15]) const Unexecuted instantiation: bool AK::DeprecatedFlyString::is_one_of<char const (&) [8], char const (&) [7], char const (&) [10]>(char const (&) [8], char const (&) [7], char const (&) [10]) const |
91 | | |
92 | | private: |
93 | | NonnullRefPtr<StringImpl const> m_impl; |
94 | | }; |
95 | | |
96 | | template<> |
97 | | struct Traits<DeprecatedFlyString> : public DefaultTraits<DeprecatedFlyString> { |
98 | 2.25k | static unsigned hash(DeprecatedFlyString const& s) { return s.hash(); } |
99 | | }; |
100 | | |
101 | | } |
102 | | |
103 | | #if USING_AK_GLOBALLY |
104 | | using AK::DeprecatedFlyString; |
105 | | #endif |