Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Periphery
on:
push:
branches: [main]
pull_request:
jobs:
periphery:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install Periphery
run: brew install peripheryapp/periphery/periphery
- name: Run Periphery
run: periphery scan
1 change: 1 addition & 0 deletions .periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
retain_public: true
16 changes: 0 additions & 16 deletions Sources/SwiftMETAR/Common/Parsers/DateParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,6 @@ class HourMinutePeriodParser {
class HourMinuteParser {
private let dateRef = Reference<(UInt8?, UInt8)>()

lazy var hourRequiredRx = Regex {
Capture(as: dateRef) {
Repeat(.digit, count: 4)
} transform: { string in
let hourRange = string.startIndex...string.index(string.startIndex, offsetBy: 1)
let minuteRange =
string.index(string.startIndex, offsetBy: 2)...string.index(string.startIndex, offsetBy: 3)

guard let hour = UInt8(string[hourRange]),
var minute = UInt8(string[minuteRange])
else { throw Error.invalidDate(String(string)) }

return (hour, minute)
}
}

lazy var hourOptionalRx = Regex {
Capture(as: dateRef) {
Optionally { Repeat(.digit, count: 2) }
Expand Down
23 changes: 0 additions & 23 deletions Sources/SwiftMETAR/Common/Parsers/VisibilityParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import NumberKit
class VisibilityParser {
private let integerParser = IntegerDistanceParser()
private let fractionParser = FractionalDistanceParser()
private let visibilityRef = Reference<Substring>()

private lazy var integerRx = Regex {
Anchor.startOfSubject
Expand All @@ -29,20 +28,6 @@ class VisibilityParser {
Anchor.endOfSubject
}

lazy var rx = Regex {
Capture(as: visibilityRef) {
ChoiceOf {
ChoiceOf {
"10SM"
"9999"
}
notRecordedRx
fractionRx
integerRx
}
}
}

func parse(_ parts: inout [String.SubSequence]) throws -> Visibility? {
guard !parts.isEmpty else { return nil }

Expand All @@ -61,14 +46,6 @@ class VisibilityParser {
return nil
}

func parse<T>(_ match: Regex<T>.Match) throws -> Visibility? {
let visStr = match[visibilityRef]
guard let visibility = try parse(String(visStr)) else {
preconditionFailure("Visibility rx should have captured parseable substring")
}
return visibility
}

private func parse(_ vizStr: String) throws -> Visibility? {
if vizStr == "CAVOK" {
return .greaterThan(.meters(9999))
Expand Down
5 changes: 0 additions & 5 deletions Sources/SwiftMETAR/METAR/Parsers/METARXMLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ actor METARXMLParser {
var entries = [Entry]()

private var currentEntry: Entry?
private var currentElement: String?
private var characterBuffer = ""
private var inQualityControlFlags = false

Expand All @@ -131,8 +130,6 @@ actor METARXMLParser {
qualifiedName _: String?,
attributes attributeDict: [String: String] = [:]
) {
currentElement = elementName

if elementName == "METAR" {
currentEntry = Entry()
} else if elementName == "quality_control_flags" {
Expand Down Expand Up @@ -205,8 +202,6 @@ actor METARXMLParser {
}
}
}

currentElement = nil
}

func parser(_: XMLParser, foundCharacters string: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Foundation
@preconcurrency import RegexBuilder

private let nocapWeatherCenterRx = Remark.NavalWeatherCenter.allCases.map(\.rawValue).joined(
separator: "|"
)

final class NavalForecasterParser: RemarkParser {
var urgency = Remark.Urgency.routine

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Foundation
@preconcurrency import RegexBuilder

private let nocapExtremesRegex = Remark.Extreme.allCases.map(\.rawValue).joined(separator: "|")

final class WindChangeParser: RemarkParser {
var urgency = Remark.Urgency.routine

Expand Down
13 changes: 0 additions & 13 deletions Sources/SwiftMETAR/Support/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ extension Date {
func next(_ components: DateComponents) -> Date? {
return zuluCal.nextDate(after: self, matching: components, matchingPolicy: .nextTime)
}

func next(
year: Int? = nil,
month: Int? = nil,
day: Int? = nil,
hour: Int? = nil,
minute: Int? = nil,
second: Int? = nil
) -> Date? {
return next(
.init(year: year, month: month, day: day, hour: hour, minute: minute, second: second)
)
}
}

func applyComponents(
Expand Down
6 changes: 0 additions & 6 deletions Sources/SwiftMETAR/Support/Ratio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import NumberKit
/// A ratio of two integers.
public typealias Ratio = Rational<Int>

extension Float {
init(_ ratio: Ratio) {
self = ratio.floatValue
}
}

extension Ratio {
init(_ whole: Int, numerator: Int, denominator: Int) {
self.init(denominator * whole + numerator, denominator)
Expand Down
11 changes: 0 additions & 11 deletions Sources/SwiftMETAR/Support/String+SwiftMETAR.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Foundation

extension String {
var nsRange: NSRange { return NSRange(location: 0, length: count) }

func partitionSlices(by length: Int) -> [Substring] {
var startIndex = self.startIndex
var results = [Substring]()
Expand Down Expand Up @@ -46,13 +44,4 @@ extension String {
substrings.append(self[rangeStart...])
return substrings
}

func substring(with nsRange: NSRange) -> SubSequence {
let range =
index(
startIndex,
offsetBy: nsRange.location
)..<index(startIndex, offsetBy: nsRange.location + nsRange.length)
return self[range]
}
}
31 changes: 0 additions & 31 deletions Sources/SwiftMETAR/Support/XMLParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,6 @@ enum XMLParsing {
return zuluCal.dateComponents(in: zulu, from: date)
}

static func parseRatio(_ string: String) -> Ratio? {
if let intVal = Int(string) {
return Ratio(intVal)
}

// Handle decimal like "1.75"
if string.contains(".") {
let parts = string.split(separator: ".")
guard parts.count == 2,
let whole = Int(parts[0]),
let fracStr = parts.last
else { return nil }

let denominator = Int(pow(10.0, Double(fracStr.count)))
guard let numerator = Int(fracStr) else { return nil }
return Ratio(whole * denominator + numerator, denominator)
}

// Handle fraction like "3/4"
if string.contains("/") {
let parts = string.split(separator: "/")
guard parts.count == 2,
let num = Int(parts[0]),
let den = Int(parts[1])
else { return nil }
return Ratio(num, den)
}

return nil
}

static func buildWind(dirDegrees: String?, speedKt: String?, gustKt: String?) throws -> Wind? {
guard let speedStr = speedKt else { return nil }
guard let speed = UInt16(speedStr) else {
Expand Down
5 changes: 0 additions & 5 deletions Sources/SwiftMETAR/TAF/Parsers/TAFXMLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ actor TAFXMLParser {

private var currentEntry: Entry?
private var currentForecast: ForecastEntry?
private var currentElement: String?
private var characterBuffer = ""
private var inForecast = false

Expand All @@ -292,8 +291,6 @@ actor TAFXMLParser {
qualifiedName _: String?,
attributes attributeDict: [String: String] = [:]
) {
currentElement = elementName

if elementName == "TAF" {
currentEntry = Entry()
} else if elementName == "forecast" {
Expand Down Expand Up @@ -393,8 +390,6 @@ actor TAFXMLParser {
}
}
}

currentElement = nil
}

func parser(_: XMLParser, foundCharacters string: String) {
Expand Down
Loading