1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:37:45 +00:00

Ladybird/AppKit: Port the Inspector to the WebView InspectorClient

This commit is contained in:
Timothy Flynn 2023-11-23 20:01:46 -05:00 committed by Andreas Kling
parent 52b5bcdb6d
commit 84c4eef565
8 changed files with 50 additions and 355 deletions

View file

@ -1,15 +0,0 @@
/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#import <System/Cocoa.h>
@interface NSString (Ladybird)
- (NSString*)stringByCollapsingConsecutiveWhitespace;
@end

View file

@ -1,55 +0,0 @@
/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/CharacterTypes.h>
#include <AK/StringView.h>
#include <AK/Utf8View.h>
#include <LibUnicode/CharacterTypes.h>
#import <Utilities/Conversions.h>
#import <Utilities/NSString+Ladybird.h>
static BOOL code_point_is_whitespace(u32 code_point)
{
static auto white_space_category = Unicode::property_from_string("White_Space"sv);
if (!white_space_category.has_value())
return is_ascii_space(code_point);
return Unicode::code_point_has_property(code_point, *white_space_category);
}
@implementation NSString (Ladybird)
- (NSString*)stringByCollapsingConsecutiveWhitespace
{
auto* result = [NSMutableString string];
auto const* string = [self UTF8String];
Utf8View code_points { StringView { string, strlen(string) } };
bool currently_skipping_spaces = false;
for (auto code_point : code_points) {
if (code_point_is_whitespace(code_point)) {
if (!currently_skipping_spaces) {
currently_skipping_spaces = true;
[result appendString:@" "];
}
continue;
}
auto code_point_string = String::from_code_point(code_point);
[result appendString:Ladybird::string_to_ns_string(code_point_string)];
currently_skipping_spaces = false;
}
return result;
}
@end