Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdeem committed Jul 1, 2018
2 parents 5bf5eda + bcce319 commit 6932279
Show file tree
Hide file tree
Showing 30 changed files with 379 additions and 234 deletions.
17 changes: 17 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
disabled_rules:
- line_length
- function_body_length
- trailing_comma

opt_in_rules:

included:

excluded:

identifier_name:
min_length: 1

cyclomatic_complexity:
warning: 12
error: 20
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

<a name="1.1.1"></a>
# [1.1.1](https://github.com/SwiftScream/URITemplate/compare/1.1.0...1.1.1) (2018-07-01)

- Support back to iOS 9, tvOS 9, watchOS 2, macOS 10.11
- Correct dynamic framework packaging


<a name="1.1.0"></a>
# [1.1.0](https://github.com/SwiftScream/URITemplate/compare/1.0.0...1.1.0) (2018-05-19)

Expand Down
2 changes: 2 additions & 0 deletions Configuration/DynamicLibTarget-tv.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ DYLIB_INSTALL_NAME_BASE = @rpath
OTHER_LDFLAGS = -ObjC -all_load
LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks

CODE_SIGN_IDENTITY =

DEFINES_MODULE = YES
INFOPLIST_FILE = Source/DynamicFrameworkInfo.plist
PRODUCT_BUNDLE_IDENTIFIER = com.swiftscream.URITemplate
Expand Down
2 changes: 2 additions & 0 deletions Configuration/DynamicLibTarget-watch.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ DYLIB_INSTALL_NAME_BASE = @rpath
OTHER_LDFLAGS = -ObjC -all_load
LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks

CODE_SIGN_IDENTITY =

DEFINES_MODULE = YES
INFOPLIST_FILE = Source/DynamicFrameworkInfo.plist
PRODUCT_BUNDLE_IDENTIFIER = com.swiftscream.URITemplate
Expand Down
2 changes: 2 additions & 0 deletions Configuration/Project.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ ENABLE_STRICT_OBJC_MSGSEND = YES
SWIFT_VERSION = 4.1
SWIFT_TREAT_WARNINGS_AS_ERRORS = YES

CURRENT_PROJECT_VERSION = 1.1.1

#include "Warnings.xcconfig"
2 changes: 1 addition & 1 deletion Configuration/StaticLibTarget-ios.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SDKROOT = iphoneos
IPHONEOS_DEPLOYMENT_TARGET = 10.0
IPHONEOS_DEPLOYMENT_TARGET = 9.0
TARGETED_DEVICE_FAMILY = 1,2

SKIP_INSTALL = YES
Expand Down
2 changes: 1 addition & 1 deletion Configuration/StaticLibTarget-mac.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SDKROOT = macosx
MACOSX_DEPLOYMENT_TARGET = 10.12
MACOSX_DEPLOYMENT_TARGET = 10.11

EXECUTABLE_PREFIX = lib
SKIP_INSTALL = YES
Expand Down
2 changes: 1 addition & 1 deletion Configuration/StaticLibTarget-tv.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SDKROOT = appletvos
TVOS_DEPLOYMENT_TARGET = 10.0
TVOS_DEPLOYMENT_TARGET = 9.0
TARGETED_DEVICE_FAMILY = 3

SKIP_INSTALL = YES
Expand Down
2 changes: 1 addition & 1 deletion Configuration/StaticLibTarget-watch.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SDKROOT = watchos
WATCHOS_DEPLOYMENT_TARGET = 3.0
WATCHOS_DEPLOYMENT_TARGET = 2.0
TARGETED_DEVICE_FAMILY = 4

APPLICATION_EXTENSION_API_ONLY = YES
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TestTarget-ios.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SDKROOT = iphoneos
IPHONEOS_DEPLOYMENT_TARGET = 10.0
IPHONEOS_DEPLOYMENT_TARGET = 9.0
TARGETED_DEVICE_FAMILY = 1,2

LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TestTarget-tv.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SDKROOT = appletvos
TVOS_DEPLOYMENT_TARGET = 10.0
TVOS_DEPLOYMENT_TARGET = 9.0
TARGETED_DEVICE_FAMILY = 3

LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks
Expand Down
6 changes: 3 additions & 3 deletions Example-ios/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds);
self.window?.rootViewController = ViewController();
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = ViewController()
self.window?.makeKeyAndVisible()

return true
Expand Down
24 changes: 16 additions & 8 deletions Example-ios/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,24 @@ class ViewController: UIViewController {
let view = UIView(frame: UIScreen.main.bounds)
self.view = view

let template = try! URITemplate(string: "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}")
let variables = ["owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem"]
do {
let template = try URITemplate(string: "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}")
let variables = ["owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem"]

let urlString = try! template.process(variables: variables)
let urlString = try template.process(variables: variables)

let url = URL(string:urlString)!
print("Expanding \(template)\n with \(variables):\n")
print(url.absoluteString)
let url = URL(string: urlString)!
print("Expanding \(template)\n with \(variables):\n")
print(url.absoluteString)
} catch URITemplate.Error.malformedTemplate(let position, let reason) {
print("Failed parsing template (\(reason))")
} catch URITemplate.Error.expansionFailure(let position, let reason) {
print("Failed expanding template (\(reason))")
} catch {
print("Unexpected Failure")
}
}

}
3 changes: 1 addition & 2 deletions Example-mac/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let variables = ["owner": "SwiftScream",

let urlString = try template.process(variables: variables)

let url = URL(string:urlString)!
let url = URL(string: urlString)!
print("Expanding \(template)\n with \(variables):\n")
print(url.absoluteString)

4 changes: 2 additions & 2 deletions Example-tv/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds);
self.window?.rootViewController = ViewController();
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = ViewController()
self.window?.makeKeyAndVisible()

return true
Expand Down
24 changes: 16 additions & 8 deletions Example-tv/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,24 @@ class ViewController: UIViewController {
let view = UIView(frame: UIScreen.main.bounds)
self.view = view

let template = try! URITemplate(string: "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}")
let variables = ["owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem"]
do {
let template = try URITemplate(string: "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}")
let variables = ["owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem"]

let urlString = try! template.process(variables: variables)
let urlString = try template.process(variables: variables)

let url = URL(string:urlString)!
print("Expanding \(template)\n with \(variables):\n")
print(url.absoluteString)
let url = URL(string: urlString)!
print("Expanding \(template)\n with \(variables):\n")
print(url.absoluteString)
} catch URITemplate.Error.malformedTemplate(let position, let reason) {
print("Failed parsing template (\(reason))")
} catch URITemplate.Error.expansionFailure(let position, let reason) {
print("Failed expanding template (\(reason))")
} catch {
print("Unexpected Failure")
}
}

}
24 changes: 16 additions & 8 deletions Example-watch/Extension/InterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ class InterfaceController: WKInterfaceController {
override func awake(withContext context: Any?) {
super.awake(withContext: context)

let template = try! URITemplate(string: "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}")
let variables = ["owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem"]
do {
let template = try URITemplate(string: "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}")
let variables = ["owner": "SwiftScream",
"repo": "URITemplate",
"username": "alexdeem"]

let urlString = try! template.process(variables: variables)
let urlString = try template.process(variables: variables)

let url = URL(string:urlString)!
print("Expanding \(template)\n with \(variables):\n")
print(url.absoluteString)
let url = URL(string: urlString)!
print("Expanding \(template)\n with \(variables):\n")
print(url.absoluteString)
} catch URITemplate.Error.malformedTemplate(let position, let reason) {
print("Failed parsing template (\(reason))")
} catch URITemplate.Error.expansionFailure(let position, let reason) {
print("Failed expanding template (\(reason))")
} catch {
print("Unexpected Failure")
}
}

}
10 changes: 5 additions & 5 deletions ScreamURITemplate.podspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Pod::Spec.new do |s|
s.name = "ScreamURITemplate"
s.version = "1.1.0"
s.version = "1.1.1"
s.summary = "Robust and performant Swift implementation of RFC6570 URI Template"
s.homepage = "https://github.com/SwiftScream/URITemplate"
s.license = { :type => "Apache License, Version 2.0", :file => "LICENSE" }
s.author = { "Alex Deem" => "[email protected]" }
s.source = { :git => "https://github.com/SwiftScream/URITemplate.git", :tag => "#{s.version}" }
s.source_files = "Source/*.swift", "Source/Internal/*.swift"
s.swift_version = "4.1"
s.ios.deployment_target = "10.0"
s.osx.deployment_target = "10.12"
s.watchos.deployment_target = "3.0"
s.tvos.deployment_target = "10.0"
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.11"
s.watchos.deployment_target = "2.0"
s.tvos.deployment_target = "9.0"
end
14 changes: 7 additions & 7 deletions Source/Internal/CharacterSets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

import Foundation

internal let unreservedCharacterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn:"-._~"))
private let genDelimsCharacterSet = CharacterSet(charactersIn:":/?#[]@")
private let subDelimsCharacterSet = CharacterSet(charactersIn:"!$&'()*+,;=")
internal let unreservedCharacterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-._~"))
private let genDelimsCharacterSet = CharacterSet(charactersIn: ":/?#[]@")
private let subDelimsCharacterSet = CharacterSet(charactersIn: "!$&'()*+,;=")
internal let reservedCharacterSet = genDelimsCharacterSet.union(subDelimsCharacterSet)
internal let reservedAndUnreservedCharacterSet = reservedCharacterSet.union(unreservedCharacterSet)
internal let invertedLiteralCharacterSet = CharacterSet.illegalCharacters.union(CharacterSet.controlCharacters).union(CharacterSet(charactersIn:" \"'%<>\\^`{|}"))
internal let invertedLiteralCharacterSet = CharacterSet.illegalCharacters.union(CharacterSet.controlCharacters).union(CharacterSet(charactersIn: " \"'%<>\\^`{|}"))
internal let literalCharacterSet = invertedLiteralCharacterSet.inverted
internal let hexCharacterSet = CharacterSet(charactersIn:"0123456789abcdefABCDEF")
internal let varnameCharacterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn:"_%."))
internal let hexCharacterSet = CharacterSet(charactersIn: "0123456789abcdefABCDEF")
internal let varnameCharacterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "_%."))
internal let invertedVarnameCharacterSet = varnameCharacterSet.inverted
internal let expressionOperatorCharacterSet = CharacterSet(charactersIn:"+#./;?&=,!@|")
internal let expressionOperatorCharacterSet = CharacterSet(charactersIn: "+#./;?&=,!@|")
internal let invertedDecimalDigitsCharacterSet = CharacterSet.decimalDigits.inverted
32 changes: 16 additions & 16 deletions Source/Internal/Components.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,43 @@
import Foundation

internal protocol Component {
func expand(variables: [String:VariableValue]) throws -> String
var variableNames : [String] { get }
func expand(variables: [String: VariableValue]) throws -> String
var variableNames: [String] { get }
}

extension Component {
var variableNames : [String] {
var variableNames: [String] {
return []
}
}

internal struct LiteralComponent : Component {
internal struct LiteralComponent: Component {
let literal: Substring
init (_ string: Substring) {
literal = string
}

func expand(variables _: [String:VariableValue]) throws -> String {
func expand(variables _: [String: VariableValue]) throws -> String {
let expansion = String(literal)
guard let encodedExpansion = expansion.addingPercentEncoding(withAllowedCharacters: reservedAndUnreservedCharacterSet) else {
throw URITemplate.Error.expansionFailure(position: literal.startIndex, reason: "Percent Encoding Failed")
}
return encodedExpansion;
return encodedExpansion
}
}

internal struct LiteralPercentEncodedTripletComponent : Component {
internal struct LiteralPercentEncodedTripletComponent: Component {
let literal: Substring
init (_ string: Substring) {
literal = string
}

func expand(variables _: [String:VariableValue]) throws -> String {
func expand(variables _: [String: VariableValue]) throws -> String {
return String(literal)
}
}

internal struct ExpressionComponent : Component {
internal struct ExpressionComponent: Component {
let expressionOperator: ExpressionOperator
let variableList: [VariableSpec]
let templatePosition: String.Index
Expand All @@ -62,11 +62,11 @@ internal struct ExpressionComponent : Component {
self.templatePosition = templatePosition
}

func expand(variables: [String:VariableValue]) throws -> String {
func expand(variables: [String: VariableValue]) throws -> String {
let configuration = expressionOperator.expansionConfiguration()
let expansions = try variableList.compactMap { variableSpec -> String? in
guard let value = variables[String(variableSpec.name)] else {
return nil;
return nil
}
do {
if let stringValue = value as? String {
Expand All @@ -80,7 +80,7 @@ internal struct ExpressionComponent : Component {
case .none:
return try arrayValue.formatForTemplateExpansion(variableSpec: variableSpec, expansionConfiguration: configuration)
}
} else if let dictionaryValue = value as? [String:String] {
} else if let dictionaryValue = value as? [String: String] {
switch variableSpec.modifier {
case .prefix:
throw FormatError.failure(reason: "Prefix operator can only be applied to string")
Expand All @@ -97,18 +97,18 @@ internal struct ExpressionComponent : Component {
}
}

if (expansions.count == 0) {
if expansions.count == 0 {
return ""
}

let joinedExpansions = expansions.joined(separator:configuration.separator)
let joinedExpansions = expansions.joined(separator: configuration.separator)
if let prefix = configuration.prefix {
return prefix + joinedExpansions
}
return joinedExpansions;
return joinedExpansions
}

var variableNames : [String] {
var variableNames: [String] {
return variableList.map { variableSpec in
return String(variableSpec.name)
}
Expand Down
Loading

0 comments on commit 6932279

Please sign in to comment.