ladybird/Tests/AK
Andreas Kling a3e82eaad3 AK: Introduce the new String, replacement for DeprecatedString
DeprecatedString (formerly String) has been with us since the start,
and it has served us well. However, it has a number of shortcomings
that I'd like to address.

Some of these issues are hard if not impossible to solve incrementally
inside of DeprecatedString, so instead of doing that, let's build a new
String class and then incrementally move over to it instead.

Problems in DeprecatedString:

- It assumes string allocation never fails. This makes it impossible
  to use in allocation-sensitive contexts, and is the reason we had to
  ban DeprecatedString from the kernel entirely.

- The awkward null state. DeprecatedString can be null. It's different
  from the empty state, although null strings are considered empty.
  All code is immediately nicer when using Optional<DeprecatedString>
  but DeprecatedString came before Optional, which is how we ended up
  like this.

- The encoding of the underlying data is ambiguous. For the most part,
  we use it as if it's always UTF-8, but there have been cases where
  we pass around strings in other encodings (e.g ISO8859-1)

- operator[] and length() are used to iterate over DeprecatedString one
  byte at a time. This is done all over the codebase, and will *not*
  give the right results unless the string is all ASCII.

How we solve these issues in the new String:

- Functions that may allocate now return ErrorOr<String> so that ENOMEM
  errors can be passed to the caller.

- String has no null state. Use Optional<String> when needed.

- String is always UTF-8. This is validated when constructing a String.
  We may need to add a bypass for this in the future, for cases where
  you have a known-good string, but for now: validate all the things!

- There is no operator[] or length(). You can get the underlying data
  with bytes(), but for iterating over code points, you should be using
  an UTF-8 iterator.

Furthermore, it has two nifty new features:

- String implements a small string optimization (SSO) for strings that
  can fit entirely within a pointer. This means up to 3 bytes on 32-bit
  platforms, and 7 bytes on 64-bit platforms. Such small strings will
  not be heap-allocated.

- String can create substrings without making a deep copy of the
  substring. Instead, the superstring gets +1 refcount from the
  substring, and it acts like a view into the superstring. To make
  substrings like this, use the substring_with_shared_superstring() API.

One caveat:

- String does not guarantee that the underlying data is null-terminated
  like DeprecatedString does today. While this was nifty in a handful of
  places where we were calling C functions, it did stand in the way of
  shared-superstring substrings.
2022-12-06 15:21:26 +01:00
..
CMakeLists.txt AK: Introduce the new String, replacement for DeprecatedString 2022-12-06 15:21:26 +01:00
TestAllOf.cpp AK+Everywhere: Stop including Vector.h from StringView.h 2021-11-10 21:58:58 +01:00
TestAnyOf.cpp AK+Everywhere: Stop including Vector.h from StringView.h 2021-11-10 21:58:58 +01:00
TestArbitrarySizedEnum.cpp AK: Add an ArbitrarySizedEnum template 2022-03-27 18:54:56 +02:00
TestArray.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestAtomic.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestBadge.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestBase64.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestBinaryHeap.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestBinarySearch.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestBitCast.cpp Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
TestBitmap.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestBuiltinWrappers.cpp AK: Add BuiltinWrappers.h 2021-12-18 23:36:08 +01:00
TestByteBuffer.cpp Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr 2022-01-24 22:36:09 +01:00
TestCharacterTypes.cpp Tests: Reduce runtime of TestCharacterTypes 2021-06-24 09:16:28 +02:00
TestChecked.cpp Tests: Add tests for Checked<T>::div() overflow 2021-05-07 09:26:11 +02:00
TestCircularDeque.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestCircularDuplexStream.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestCircularQueue.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestComplex.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestDeprecatedString.cpp Everywhere: Rename to_{string => deprecated_string}() where applicable 2022-12-06 08:54:33 +01:00
TestDisjointChunks.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestDistinctNumeric.cpp AK: Add optional explicit cast to underlying type to DistinctNumeric 2022-11-11 17:50:53 +03:30
TestDoublyLinkedList.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestEndian.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestEnumBits.cpp AK/Tests: Add test for EnumBits has_any_flag() 2021-07-16 11:49:50 +02:00
TestFind.cpp Tests: Remove unused header includes 2021-08-01 08:10:16 +02:00
TestFixedArray.cpp AK+Tests: Don't double-destroy NoAllocationGuard in TestFixedArray 2022-09-15 23:04:46 +00:00
TestFixedPoint.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestFloatingPoint.cpp AK: Add FloatingPoint.h 2022-08-27 12:28:05 +02:00
TestFloatingPointParsing.cpp AK: Add an exact and fast hex float parsing algorithm 2022-10-23 15:48:45 +02:00
TestFormat.cpp Everywhere: Rename to_{string => deprecated_string}() where applicable 2022-12-06 08:54:33 +01:00
TestGenericLexer.cpp AK: Add GenericLexer API to consume an escaped Unicode code point 2021-08-19 23:49:25 +02:00
TestHashFunctions.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestHashMap.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestHashTable.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestHex.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestIndexSequence.cpp AK+Everywhere: Stop including Vector.h from StringView.h 2021-11-10 21:58:58 +01:00
TestIntegerMath.cpp AK: Introduce IntegralMath.h starting with pow<I> 2022-02-06 17:52:33 +00:00
TestIntrusiveList.cpp AK+Everywhere: Reduce the number of template parameters of IntrusiveList 2021-09-10 18:05:46 +03:00
TestIntrusiveRedBlackTree.cpp AK+Kernel: Reduce the number of template parameters of IntrusiveRBTree 2021-09-10 18:05:46 +03:00
TestIPv4Address.cpp Everywhere: Rename to_{string => deprecated_string}() where applicable 2022-12-06 08:54:33 +01:00
TestIPv6Address.cpp Everywhere: Rename to_{string => deprecated_string}() where applicable 2022-12-06 08:54:33 +01:00
TestJSON.cpp Everywhere: Rename to_{string => deprecated_string}() where applicable 2022-12-06 08:54:33 +01:00
TestLEB128.cpp AK: Handle LEB128 encoded values that are too large for the result type 2021-05-31 14:25:27 +04:30
TestLexicalPath.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestMACAddress.cpp Everywhere: Rename to_{string => deprecated_string}() where applicable 2022-12-06 08:54:33 +01:00
TestMemory.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestMemoryStream.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestNeverDestroyed.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestNonnullRefPtr.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestNumberFormat.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestOptional.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestPrint.cpp AK: Allow printing wide characters using %ls modifier 2022-03-30 11:30:43 +04:30
TestQueue.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestQuickSort.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestRedBlackTree.cpp AK: Clear minimum when removing last node of RedBlackTree 2022-02-10 14:09:39 +00:00
TestRefPtr.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestSinglyLinkedList.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestSourceGenerator.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestSourceLocation.cpp Everywhere: Explicitly specify the size in StringView constructors 2022-07-12 23:11:35 +02:00
TestSpan.cpp Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
TestStack.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestStdLibExtras.cpp Everywhere: Update copyrights with my new serenityos.org e-mail :^) 2022-01-31 18:23:22 +00:00
TestString.cpp AK: Introduce the new String, replacement for DeprecatedString 2022-12-06 15:21:26 +01:00
TestStringFloatingPointConversions.cpp AK: Add framework for a unified floating point to string conversion 2022-11-03 20:17:09 -06:00
TestStringUtils.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestStringView.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestTime.cpp AK: Add Time::is_negative() to detect negative time values 2021-08-15 12:20:38 +02:00
TestTrie.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestTuple.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestTypedTransfer.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestTypeTraits.cpp Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
TestUFixedBigInt.cpp AK: Make truncating UFixedBigInts constexpr 2022-10-23 15:48:45 +02:00
TestURL.cpp Everywhere: Rename to_{string => deprecated_string}() where applicable 2022-12-06 08:54:33 +01:00
TestUtf8.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestUtf16.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestVariant.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestVector.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
TestWeakPtr.cpp AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00