Skip to content

Commit 1bd5844

Browse files
committed
Add String extensions and remove Scripts directory
- Added String.swift with String extension utilities - Updated code formatting and implementation - Removed Scripts/setup-rfc.sh - Updated Package.swift and gitignore - Added .spi.yml configuration
1 parent db0ff72 commit 1bd5844

File tree

8 files changed

+51
-122
lines changed

8 files changed

+51
-122
lines changed

.gitignore

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
1-
# Swift Package Manager
2-
.build/
3-
.swiftpm/
4-
Package.resolved
1+
*~
52

6-
# Xcode
7-
*.xcodeproj/
8-
*.xcworkspace/
9-
xcuserdata/
3+
Package.resolved
104
DerivedData/
11-
*.hmap
12-
*.ipa
13-
*.dSYM.zip
14-
*.dSYM
15-
16-
# macOS
17-
.DS_Store
18-
19-
# AI tools
20-
CLAUDE.md
21-
.claude
22-
.cursor/
23-
.aider*
5+
Thumbs.db
246

25-
# IDE
26-
.vscode/
27-
.idea/
7+
# Dot files/directories (opt-in only)
8+
/.*
9+
!/.github
10+
!/.gitignore
11+
!/.spi.yml
12+
!/.swift-format
13+
!/.swiftformat
14+
!/.swiftlint.yml
2815

29-
# Temporary files
30-
*.tmp
31-
*.swp
32-
*~
16+
# Documentation (opt-in for top-level .md files only)
17+
/*.md
18+
!README.md
19+
!LICENSE.md
20+
!CHANGELOG.md
21+
!CONTRIBUTING.md
22+
!CODE_OF_CONDUCT.md
23+
!SECURITY.md

.spi.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: 1
2+
builder:
3+
configs:
4+
- documentation_targets:
5+
- MemoryAllocation

Package.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// swift-tools-version:6.0
22

3-
import Foundation
43
import PackageDescription
54

65
extension String {
@@ -14,15 +13,16 @@ extension Target.Dependency {
1413
let package = Package(
1514
name: "swift-rfc-1035",
1615
platforms: [
17-
.macOS(.v13),
18-
.iOS(.v16)
16+
.macOS(.v15),
17+
.iOS(.v18),
18+
.tvOS(.v18),
19+
.watchOS(.v11)
1920
],
2021
products: [
2122
.library(name: .rfc1035, targets: [.rfc1035]),
2223
],
2324
dependencies: [
24-
// Add RFC dependencies here as needed
25-
// .package(url: "https://github.com/swift-standards/swift-rfc-1123.git", branch: "main"),
25+
// .package(url: "https://github.com/swift-standards/swift-standards.git", from: "0.1.0")
2626
],
2727
targets: [
2828
.target(
@@ -41,4 +41,4 @@ let package = Package(
4141
swiftLanguageModes: [.v6]
4242
)
4343

44-
extension String { var tests: Self { self + " Tests" } }
44+
extension String { var tests: Self { self + " Tests" } }

Scripts/setup-rfc.sh

Lines changed: 0 additions & 62 deletions
This file was deleted.

Sources/RFC_1035/RFC 1035.swift

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Created by Coen ten Thije Boonkkamp on 28/12/2024.
66
//
77

8-
import Foundation
9-
108
/// RFC 1035 compliant domain name
119
public struct Domain: Hashable, Sendable {
1210
/// The labels that make up the domain name, from least significant to most significant
@@ -43,7 +41,7 @@ public struct Domain: Hashable, Sendable {
4341
extension Domain {
4442
/// A type-safe domain label that enforces RFC 1035 rules
4543
public struct Label: Hashable, Sendable {
46-
private let value: String
44+
public let value: String
4745

4846
/// Initialize a label, validating RFC 1035 rules
4947
internal init(_ string: String) throws {
@@ -57,15 +55,13 @@ extension Domain {
5755

5856
self.value = string
5957
}
60-
61-
public var stringValue: String { value }
6258
}
6359
}
6460

6561
extension Domain {
6662
/// The complete domain name as a string
6763
public var name: String {
68-
labels.map(\.stringValue).joined(separator: ".")
64+
labels.map(String.init).joined(separator: ".")
6965
}
7066

7167
/// The top-level domain (rightmost label)
@@ -86,7 +82,7 @@ extension Domain {
8682

8783
/// Creates a subdomain by prepending new labels
8884
public func addingSubdomain(_ components: [String]) throws -> Domain {
89-
try Domain(labels: components + labels.map(\.stringValue))
85+
try Domain(labels: components + labels.map(String.init))
9086
}
9187

9288
public func addingSubdomain(_ components: String...) throws -> Domain {
@@ -96,13 +92,13 @@ extension Domain {
9692
/// Returns the parent domain by removing the leftmost label
9793
public func parent() throws -> Domain? {
9894
guard labels.count > 1 else { return nil }
99-
return try Domain(labels: labels.dropFirst().map(\.stringValue))
95+
return try Domain(labels: labels.dropFirst().map(String.init))
10096
}
10197

10298
/// Returns the root domain (tld + sld)
10399
public func root() throws -> Domain? {
104100
guard labels.count >= 2 else { return nil }
105-
return try Domain(labels: labels.suffix(2).map(\.stringValue))
101+
return try Domain(labels: labels.suffix(2).map(String.init))
106102
}
107103
}
108104

@@ -123,25 +119,11 @@ extension Domain {
123119

124120
// MARK: - Errors
125121
extension Domain {
126-
public enum ValidationError: Error, LocalizedError, Equatable {
122+
public enum ValidationError: Error, Equatable {
127123
case empty
128124
case tooLong(_ length: Int)
129125
case tooManyLabels
130126
case invalidLabel(_ label: String)
131-
132-
public var errorDescription: String? {
133-
switch self {
134-
case .empty:
135-
return "Domain name cannot be empty"
136-
case .tooLong(let length):
137-
return "Domain name length \(length) exceeds maximum of \(Limits.maxLength)"
138-
case .tooManyLabels:
139-
return "Domain name has too many labels (maximum \(Limits.maxLabels))"
140-
case .invalidLabel(let label):
141-
return
142-
"Invalid label '\(label)'. Must start with letter, end with letter/digit, and contain only letters/digits/hyphens"
143-
}
144-
}
145127
}
146128
}
147129

Sources/RFC_1035/String.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// File.swift
3+
// swift-rfc-1035
4+
//
5+
// Created by Coen ten Thije Boonkkamp on 19/11/2025.
6+
//
7+
8+
extension String {
9+
public init(
10+
_ label: RFC_1035.Domain.Label
11+
) {
12+
self = label.value
13+
}
14+
}

Tests/RFC_1035 Tests/RFC 1035 Tests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Created by Coen ten Thije Boonkkamp on 28/12/2024.
66
//
77

8-
import Foundation
98
import RFC_1035
109
import Testing
1110

Tests/RFC_1035 Tests/ReadmeVerificationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// Verifies that README code examples actually work
66
//
77

8-
import Foundation
98
import RFC_1035
109
import Testing
10+
import Foundation
1111

1212
@Suite("README Verification")
1313
struct ReadmeVerificationTests {

0 commit comments

Comments
 (0)