mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:22:43 +00:00 
			
		
		
		
	 5e1499d104
			
		
	
	
		5e1499d104
		
	
	
	
	
		
			
			This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).
This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
		
	
			
		
			
				
	
	
		
			66 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/ByteString.h>
 | |
| #include <AK/NonnullRefPtr.h>
 | |
| #include <AK/RefCounted.h>
 | |
| #include <AK/Types.h>
 | |
| #include <AK/Utf16View.h>
 | |
| #include <AK/Vector.h>
 | |
| #include <LibJS/Runtime/Completion.h>
 | |
| 
 | |
| namespace JS {
 | |
| namespace Detail {
 | |
| 
 | |
| class Utf16StringImpl : public RefCounted<Utf16StringImpl> {
 | |
| public:
 | |
|     ~Utf16StringImpl() = default;
 | |
| 
 | |
|     [[nodiscard]] static NonnullRefPtr<Utf16StringImpl> create();
 | |
|     [[nodiscard]] static NonnullRefPtr<Utf16StringImpl> create(Utf16Data);
 | |
|     [[nodiscard]] static NonnullRefPtr<Utf16StringImpl> create(StringView);
 | |
|     [[nodiscard]] static NonnullRefPtr<Utf16StringImpl> create(Utf16View const&);
 | |
| 
 | |
|     Utf16Data const& string() const;
 | |
|     Utf16View view() const;
 | |
| 
 | |
| private:
 | |
|     Utf16StringImpl() = default;
 | |
|     explicit Utf16StringImpl(Utf16Data string);
 | |
| 
 | |
|     Utf16Data m_string;
 | |
| };
 | |
| 
 | |
| }
 | |
| 
 | |
| class Utf16String {
 | |
| public:
 | |
|     [[nodiscard]] static Utf16String create();
 | |
|     [[nodiscard]] static Utf16String create(Utf16Data);
 | |
|     [[nodiscard]] static Utf16String create(StringView);
 | |
|     [[nodiscard]] static Utf16String create(Utf16View const&);
 | |
| 
 | |
|     Utf16Data const& string() const;
 | |
|     Utf16View view() const;
 | |
|     Utf16View substring_view(size_t code_unit_offset, size_t code_unit_length) const;
 | |
|     Utf16View substring_view(size_t code_unit_offset) const;
 | |
| 
 | |
|     [[nodiscard]] String to_utf8() const;
 | |
|     [[nodiscard]] ByteString to_byte_string() const;
 | |
|     u16 code_unit_at(size_t index) const;
 | |
| 
 | |
|     size_t length_in_code_units() const;
 | |
|     bool is_empty() const;
 | |
| 
 | |
| private:
 | |
|     explicit Utf16String(NonnullRefPtr<Detail::Utf16StringImpl>);
 | |
| 
 | |
|     NonnullRefPtr<Detail::Utf16StringImpl> m_string;
 | |
| };
 | |
| 
 | |
| }
 |