Skip to content

Commit cc42506

Browse files
committed
Merge pull request #275 from ddunbar/use-UInt8-ascii
[Utility] Use `UInt8(ascii:)` where appropriate.
2 parents 9485d18 + 604459a commit cc42506

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Sources/Utility/File.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public struct File {
3838
In the event of read-error we do not feed a partially generated
3939
line before ending iteration.
4040
*/
41-
public func enumerate(_ separator: Character = "\n") throws -> FileLineGenerator {
41+
public func enumerate(_ separator: UnicodeScalar = "\n") throws -> FileLineGenerator {
4242
return try FileLineGenerator(path: path, separator: separator)
4343
}
4444
}
@@ -50,8 +50,8 @@ public class FileLineGenerator: IteratorProtocol, Sequence {
5050
private let fp: UnsafeMutablePointer<FILE>
5151
private let separator: Int32
5252

53-
init(path: String, separator c: Character) throws {
54-
separator = Int32(String(c).utf8.first!)
53+
init(path: String, separator c: UnicodeScalar) throws {
54+
separator = Int32(UInt8(ascii: c))
5555
fp = try fopen(path)
5656
}
5757

Sources/Utility/Path.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ extension String {
289289
var idx = utf8.startIndex
290290
let end = utf8.endIndex
291291
while idx != end {
292-
if utf8[idx] == "/".utf8.first! {
292+
if utf8[idx] == UInt8(ascii: "/") {
293293
idx = idx.successor()
294-
if idx == end || utf8[idx] == "/".utf8.first! {
294+
if idx == end || utf8[idx] == UInt8(ascii: "/") {
295295
return false
296296
}
297297
}

0 commit comments

Comments
 (0)