Latest 1.0.1
Homepage https://github.com/mtynior/PathSlicer
License MIT
Platforms ios 8.0, osx 10.10, tvos 9.0, watchos 2.0, requires ARC
Authors

Build Status Swift 2.2 License CocoaPods Carthage

Returns information about Nancy style path strings such as /rebels/{name}/{action}/.

Features

  • [x] Turns Nancy style path into regular expression
  • [x] Returns arguments for capture components
  • [x] Allows to add custom path component types
  • [ ] Support for case sensitivity
  • [ ] Support for optional compoments
  • [ ] Support for RegEx named capture groups

Integration

Requirements

  • iOS 9.0+ / Mac OS X 10.9+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 7.3+

CocoaPods

You can use CocoaPods to install PathSlicer by adding it to your Podfile:

platform :ios, '9.0'
use_frameworks!

target 'MyApp' do
    pod 'PathSlicer'
end

Run pods install to intagrate pods with your project.

Carthage

You can use Carthage to install PathSlicer by adding it to your Cartfile:

github "mtynior/PathSlicer"

Run carthage update to build the framework and drag the built PathSlicer.framework into your Xcode project.

Manually

You can also manually add PathSlicer to you project:

  1. Download repository,
  2. Drag Sources folder into you project’s tree.

Usage

let slicer = PathSlicer()

let path = "/rebels/{name}/{action}"
let pathDescription = slicer.getPathDescription(path)

The pathDescription variable contains following values:

pathDescription = {
    regex = "rebels\/([^\\/]+?)\/([^\\/]+?)(?:\/(?=$))?$",
    arguments = [ "name", "action" ]
}

Suported segment patterns

Literal segments

Literal segments don’t contain any arguments and are matched as they are.

let slicer = PathSlicer()

let path = "/empire/darth_vader/choke"
let pathDescription = slicer.getPathDescription(path)

The pathDescription variable contains following values:

pathDescription = {
    regex = "/empire/darth_vader/choke(?:\/(?=$))?$",
    arguments = [ ]
}

Capture segments

Capture segments allow to add parameters to the paths. Each capture segment is surrounded by { and }. Capture segments are returned in argument property of path description.

let slicer = PathSlicer()

let path = "/empire/{name}/{action}"
let pathDescription = slicer.getPathDescription(path)

The pathDescription variable contains following values:

pathDescription = {
    regex = "empire\/([^\\/]+?)\/([^\\/]+?)(?:\/(?=$))?$",
    arguments = [ "name", "action" ]
}

RegEx segments

RegEx segments allows to define custom component machers. Right now named caupture groups of regular expression are not returned as arguments of path description.

let slicer = PathSlicer()

let path = "/can_be_jedi/(?<age>[\d]{1,2})"
let pathDescription = slicer.getPathDescription(path)

The pathDescription variable contains following values:

pathDescription = {
    regex = "can_be_jedi/(?<age>[\d]{1,2})(?:\/(?=$))?$",
    arguments = [ ]
}

License

PathSlicer is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "PathSlicer",
    "version": "1.0.1",
    "summary": "Returns information about Nancy style path strings",
    "homepage": "https://github.com/mtynior/PathSlicer",
    "license": "MIT",
    "authors": {
        "Michau0142 Tynior": "[email protected]"
    },
    "social_media_url": "http://twitter.com/mtynior",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "source": {
        "git": "https://github.com/mtynior/PathSlicer.git",
        "tag": "1.0.1"
    },
    "source_files": "Source/**/*.swift",
    "requires_arc": true
}

Pin It on Pinterest

Share This