Skip to content

Commit e34490b

Browse files
committed
refactor: remove Foundation dependency from W3C CSSOM
Remove Foundation import from all CSSOM source files and replace Foundation-specific functionality with native Swift equivalents: - Replace String(format: "\\%x ", value) with String(_:radix:16) in escapeAsCodePoint() functions - Remove unused Foundation imports from identifier and serialization files All 134 tests pass with these changes. The package now uses only native Swift functionality for string formatting and manipulation. Modified files: - Serialization/StringSerialization.swift - Serialization/IdentifierSerialization.swift - Serialization/Url.swift - Serialization/String.swift - Identifiers/DashedIdent.swift - Identifiers/Ident.swift - Identifiers/CustomIdent.swift
1 parent 9549306 commit e34490b

File tree

7 files changed

+2
-16
lines changed

7 files changed

+2
-16
lines changed

Sources/W3C CSSOM/Identifiers/CustomIdent.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
/// Represents a CSS custom identifier for user-defined values.
42
///
53
/// The `CustomIdent` data type denotes arbitrary user-defined strings used as identifiers

Sources/W3C CSSOM/Identifiers/DashedIdent.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
/// Represents a CSS dashed identifier for user-defined custom properties and values.
42
///
53
/// The `DashedIdent` data type denotes arbitrary user-defined strings that start with two dashes

Sources/W3C CSSOM/Identifiers/Ident.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
/// Represents a CSS identifier string.
42
///
53
/// The `Ident` type represents an arbitrary string used as an identifier in CSS.

Sources/W3C CSSOM/Serialization/IdentifierSerialization.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
/// Serializes an identifier according to the CSSOM specification.
42
///
53
/// This function implements the identifier serialization algorithm defined in
@@ -118,5 +116,5 @@ private func isValidIdentifierCharacter(_ scalar: Unicode.Scalar) -> Bool {
118116
/// - U+001F → `\1f `
119117
/// - U+007F → `\7f `
120118
private func escapeAsCodePoint(_ scalar: Unicode.Scalar) -> String {
121-
return String(format: "\\%x ", scalar.value)
119+
return "\\\(String(scalar.value, radix: 16)) "
122120
}

Sources/W3C CSSOM/Serialization/String.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
/// Represents a CSS string value.
42
///
53
/// The `CSSString` type represents a sequence of characters used in CSS properties

Sources/W3C CSSOM/Serialization/StringSerialization.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
/// Serializes a string according to the CSSOM specification.
42
///
53
/// This function implements the string serialization algorithm defined in
@@ -81,5 +79,5 @@ func serializeString(_ string: String) -> String {
8179
/// - U+001F → `\1f `
8280
/// - U+007F → `\7f `
8381
private func escapeAsCodePoint(_ scalar: Unicode.Scalar) -> String {
84-
return String(format: "\\%x ", scalar.value)
82+
return "\\\(String(scalar.value, radix: 16)) "
8583
}

Sources/W3C CSSOM/Serialization/Url.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
/// Represents a CSS URL value.
42
///
53
/// The `Url` type is a pointer to a resource such as an image, video, CSS file, font file, or SVG.

0 commit comments

Comments
 (0)