LibGfx: Use new AK+Swift extensions to simplify parseHexString

This commit is contained in:
Andrew Kaster 2024-08-23 17:02:55 -06:00 committed by Andrew Kaster
commit e15dd3c22a
Notes: github-actions[bot] 2024-08-25 01:15:17 +00:00
3 changed files with 9 additions and 8 deletions

View file

@ -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}

View file

@ -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];

View file

@ -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 {