mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
LibGfx: Use new AK+Swift extensions to simplify parseHexString
This commit is contained in:
parent
c1c7e5ff3e
commit
e15dd3c22a
Notes:
github-actions[bot]
2024-08-25 01:15:17 +00:00
Author: https://github.com/ADKaster
Commit: e15dd3c22a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1175
Reviewed-by: https://github.com/AtkinsSJ
3 changed files with 9 additions and 8 deletions
|
@ -123,6 +123,7 @@ if (ENABLE_SWIFT)
|
|||
Color.swift
|
||||
)
|
||||
target_compile_definitions(LibGfx PRIVATE LIBGFX_USE_SWIFT)
|
||||
target_link_libraries(LibGfx PRIVATE AK)
|
||||
set_target_properties(LibGfx PROPERTIES Swift_MODULE_NAME "SwiftLibGfx")
|
||||
|
||||
# FIXME: These should be pulled automatically from interface compile options for the target
|
||||
|
@ -131,6 +132,7 @@ if (ENABLE_SWIFT)
|
|||
-Xcc -ivfsoverlay${Lagom_BINARY_DIR}/AK/vfs_overlay.yaml
|
||||
)
|
||||
get_target_property(LIBGFX_NATIVE_DIRS LibGfx INCLUDE_DIRECTORIES)
|
||||
list(APPEND LIBGFX_NATIVE_DIRS ${CMAKE_Swift_MODULE_DIRECTORY})
|
||||
_swift_generate_cxx_header(LibGfx "LibGfx-Swift.h"
|
||||
SEARCH_PATHS ${LIBGFX_NATIVE_DIRS}
|
||||
COMPILE_OPTIONS ${VFS_OVERLAY_OPTIONS}
|
||||
|
|
|
@ -268,14 +268,9 @@ Optional<Color> Color::from_named_css_color_string(StringView string)
|
|||
}
|
||||
|
||||
#if defined(LIBGFX_USE_SWIFT)
|
||||
static swift::String to_swift_string(StringView string)
|
||||
{
|
||||
return swift::String(std::string(string.characters_without_null_termination(), string.length()));
|
||||
}
|
||||
|
||||
static Optional<Color> hex_string_to_color(StringView string)
|
||||
{
|
||||
auto color = SwiftLibGfx::parseHexString(to_swift_string(string));
|
||||
auto color = SwiftLibGfx::parseHexString(string);
|
||||
if (color.getCount() == 0)
|
||||
return {};
|
||||
return color[0];
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
import AK
|
||||
import SwiftAK
|
||||
import LibGfx
|
||||
|
||||
// FIXME: Do this without extending String with an index operation that was explicitly deleted :^)
|
||||
|
@ -32,7 +32,11 @@ private func hexNibblesToUInt8(_ nib1: Character, _ nib2: Character) -> UInt8? {
|
|||
}
|
||||
|
||||
// FIXME: Return Gfx.Color? When swift ABI bug is fixed
|
||||
public func parseHexString(_ string: Swift.String) -> [Gfx.Color] {
|
||||
public func parseHexString(_ rawString: AK.StringView) -> [Gfx.Color] {
|
||||
guard let string = Swift.String(rawString) else {
|
||||
return []
|
||||
}
|
||||
|
||||
assert(string.hasPrefix("#"))
|
||||
|
||||
switch string.count {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue