CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

PathSlicer 1.0.1

PathSlicer 1.0.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2016
SPMSupports SPM

Maintained by Michał Tynior.



PathSlicer

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+

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.