Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' of https://github.com/Ranchero-Software/RSWeb int…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
vincode-io committed Jul 29, 2020
2 parents cb76e7c + 9c49209 commit aed4ec0
Show file tree
Hide file tree
Showing 7 changed files with 1,077 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "RSWeb",
dependencies: []),
dependencies: [],
resources: [.copy("UTS46/uts46")]),
.testTarget(
name: "RSWebTests",
dependencies: ["RSWeb"]),
Expand Down
21 changes: 21 additions & 0 deletions Sources/RSWeb/UTS46/Data+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Data+Extensions.swift
// PunyCocoa Swift
//
// Created by Nate Weaver on 2020-04-12.
//

import Foundation
import zlib

extension Data {

var crc32: UInt32 {
return self.withUnsafeBytes {
let buffer = $0.bindMemory(to: UInt8.self)
let initial = zlib.crc32(0, nil, 0)
return UInt32(zlib.crc32(initial, buffer.baseAddress, numericCast(buffer.count)))
}
}

}
54 changes: 54 additions & 0 deletions Sources/RSWeb/UTS46/Scanner+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Scanner+Extensions.swift
// PunyCocoa Swift
//
// Created by Nate Weaver on 2020-04-20.
//

import Foundation

// Wrapper functions for < 10.15 compatibility
// TODO: Remove when support for < 10.15 is dropped.
extension Scanner {

func shimScanUpToCharacters(from set: CharacterSet) -> String? {
if #available(macOS 10.15, iOS 13.0, *) {
return self.scanUpToCharacters(from: set)
} else {
var str: NSString?
self.scanUpToCharacters(from: set, into: &str)
return str as String?
}
}

func shimScanCharacters(from set: CharacterSet) -> String? {
if #available(macOS 10.15, iOS 13.0, *) {
return self.scanCharacters(from: set)
} else {
var str: NSString?
self.scanCharacters(from: set, into: &str)
return str as String?
}
}

func shimScanUpToString(_ substring: String) -> String? {
if #available(macOS 10.15, iOS 13.0, *) {
return self.scanUpToString(substring)
} else {
var str: NSString?
self.scanUpTo(substring, into: &str)
return str as String?
}
}

func shimScanString(_ searchString: String) -> String? {
if #available(macOS 10.15, iOS 13.0, *) {
return self.scanString(searchString)
} else {
var str: NSString?
self.scanString(searchString, into: &str)
return str as String?
}
}

}
Loading

0 comments on commit aed4ec0

Please sign in to comment.