2024-07-15 13:24:18 -04:00
|
|
|
set(SOURCES
|
2022-10-13 16:00:59 -04:00
|
|
|
Assertions.cpp
|
2024-07-17 13:09:07 -04:00
|
|
|
Base64.cpp
|
2022-12-08 16:44:46 -05:00
|
|
|
CircularBuffer.cpp
|
2023-03-10 10:37:52 -05:00
|
|
|
ConstrainedStream.cpp
|
2023-03-16 05:23:24 -04:00
|
|
|
CountingStream.cpp
|
2023-02-21 06:44:41 -05:00
|
|
|
DOSPackedTime.cpp
|
2023-01-08 19:23:00 -05:00
|
|
|
DeprecatedFlyString.cpp
|
2023-12-16 09:19:34 -05:00
|
|
|
ByteString.cpp
|
2023-02-05 05:27:38 -05:00
|
|
|
Error.cpp
|
2022-10-12 20:18:56 -04:00
|
|
|
FloatingPointStringConversions.cpp
|
2023-01-11 08:26:49 -05:00
|
|
|
FlyString.cpp
|
2022-10-13 16:00:59 -04:00
|
|
|
Format.cpp
|
|
|
|
GenericLexer.cpp
|
|
|
|
Hex.cpp
|
2023-01-04 12:38:01 -05:00
|
|
|
JsonObject.cpp
|
2022-10-13 16:00:59 -04:00
|
|
|
JsonParser.cpp
|
|
|
|
JsonValue.cpp
|
|
|
|
LexicalPath.cpp
|
2023-01-25 14:19:05 -05:00
|
|
|
MemoryStream.cpp
|
2022-12-10 03:52:46 -05:00
|
|
|
NumberFormat.cpp
|
2023-02-21 06:44:41 -05:00
|
|
|
OptionParser.cpp
|
2022-10-13 16:00:59 -04:00
|
|
|
Random.cpp
|
2023-09-20 18:14:35 -04:00
|
|
|
SipHash.cpp
|
2022-10-13 16:00:59 -04:00
|
|
|
StackInfo.cpp
|
2023-01-21 23:09:11 -05:00
|
|
|
Stream.cpp
|
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-01 07:27:43 -05:00
|
|
|
String.cpp
|
2023-10-28 15:17:06 -04:00
|
|
|
StringBase.cpp
|
2022-10-13 16:00:59 -04:00
|
|
|
StringBuilder.cpp
|
2022-10-25 14:00:49 -04:00
|
|
|
StringFloatingPointConversions.cpp
|
2022-10-13 16:00:59 -04:00
|
|
|
StringImpl.cpp
|
|
|
|
StringUtils.cpp
|
|
|
|
StringView.cpp
|
|
|
|
Time.cpp
|
|
|
|
Utf16View.cpp
|
2023-02-20 08:08:40 -05:00
|
|
|
Utf32View.cpp
|
2022-10-13 16:00:59 -04:00
|
|
|
Utf8View.cpp
|
2023-02-21 06:44:41 -05:00
|
|
|
kmalloc.cpp
|
2022-10-13 16:00:59 -04:00
|
|
|
)
|
|
|
|
|
2024-07-15 13:24:18 -04:00
|
|
|
serenity_lib(AK ak)
|
2022-10-13 16:00:59 -04:00
|
|
|
|
2020-05-26 14:20:24 -04:00
|
|
|
serenity_install_headers(AK)
|
2020-08-15 08:11:10 -04:00
|
|
|
serenity_install_sources(AK)
|
2024-07-15 13:24:18 -04:00
|
|
|
|
|
|
|
find_package(Backtrace)
|
|
|
|
configure_file(Backtrace.h.in Backtrace.h @ONLY)
|
|
|
|
|
|
|
|
if (Backtrace_FOUND)
|
|
|
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.30)
|
|
|
|
target_link_libraries(AK PRIVATE Backtrace::Backtrace)
|
|
|
|
else()
|
|
|
|
target_include_directories(AK PRIVATE ${Backtrace_INCLUDE_DIRS})
|
|
|
|
target_link_libraries(AK PRIVATE ${Backtrace_LIBRARIES})
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(WARNING "Backtrace not found, stack traces will be unavailable")
|
|
|
|
endif()
|
2024-07-15 15:25:08 -04:00
|
|
|
|
2024-07-17 13:09:07 -04:00
|
|
|
find_package(simdutf REQUIRED)
|
2024-08-17 14:51:34 -04:00
|
|
|
swizzle_target_properties_for_swift(simdutf::simdutf)
|
2024-07-17 13:09:07 -04:00
|
|
|
target_link_libraries(AK PRIVATE simdutf::simdutf)
|
2024-08-05 22:46:12 -04:00
|
|
|
|
2024-08-07 02:33:55 -04:00
|
|
|
if (ENABLE_SWIFT)
|
2024-08-26 21:04:05 -04:00
|
|
|
generate_clang_module_map(AK
|
2024-08-07 02:33:55 -04:00
|
|
|
GENERATED_FILES
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/Backtrace.h"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/Debug.h"
|
|
|
|
)
|
2024-08-23 14:22:26 -04:00
|
|
|
target_sources(AK PRIVATE AK+Swift.swift)
|
2024-08-26 21:04:05 -04:00
|
|
|
add_swift_target_properties(AK)
|
2024-08-07 02:33:55 -04:00
|
|
|
endif()
|
2024-10-12 12:48:48 -04:00
|
|
|
|
|
|
|
if (WIN32)
|
|
|
|
# FIXME: Windows on ARM
|
|
|
|
target_link_libraries(AK PRIVATE clang_rt.builtins-x86_64.lib)
|
|
|
|
endif()
|