diff --git a/.travis.yml b/.travis.yml index c37fd9a..942f45a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,65 @@ -language: objective-c -osx_image: xcode7.2 env: - global: - - FRAMEWORK_NAME=Regex - - secure: hsSJ4btmCIbNjAPyAOZvCAUUbupx9Obo0YIXkrQ/iteC4oWRv0g4TMh9Ie/zg9Cdn8P6QOlV2waoG4ZdCymW08/MASK5+Z+uRqAuAExF2l0NllbVTymEDKHkzGdId9EN4thj10TXrsq8kfTWg8O1As3r2Nl/H2lBmDK49DHZVU2cNl9EbgmALYS7CoZ2LwM/TnJgSvUB4l0yzPyz4veDNAgRvQ9iMXN1/gHsemZdcxrd9q3ce53+PRap2z9NUGQrpAefXCLjN8M8aKHExgr90aUxGz4DoHm+pRppMqFo9hIjEi0WQc+ikD3ExchxQH6LCCdTF20L5L0Sxj3AzhUsojDtB5zG9Rc8O/1UjzbcuHbdr0PC+0mSFuQzYsG009Zg1i6moeattmQOC/F/QYp/cXdlHT9K9T4dqh62Wp9lU/CeigJ6orKR9NgBuxEDOsObzNVoiRsqBn4fEOE2b+24XB7D8u4Twc7koRB1gG96JUFNWm5pSmM1WDzTJIlHTcxiU4iHMV/19mWnzJhYTLSXhXOhG1lO2FddeRlkKCuklWqcKvWWr6FnFA2uFxp17hM6YfVsvhDQiJ3Xd/byuNIVgkDuL80Jo/v7dkM8tElYeJsRGiRkZLtkOlIiRnWYTeFclNNSzJ14Ub/MT5W6wfEm/nqeY2G0w50Peu362XL2rFs= -before_install: - - brew update - - brew unlink carthage - - brew install carthage - - brew link carthage -before_script: - # bootstrap the dependencies for the project - # you can remove if you don't have dependencies - # - carthage bootstrap -before_deploy: - - carthage build --no-skip-current - - carthage archive $FRAMEWORK_NAME - - pod trunk push CrossroadRegex.podspec -script: -- xcodebuild test -project Regex.xcodeproj -scheme Regex-OSX -- xcodebuild test -project Regex.xcodeproj -scheme Regex-iOS -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' -- xcodebuild test -project Regex.xcodeproj -scheme Regex-tvOS -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV 1080p' -- xcodebuild build -project Regex.xcodeproj -scheme Regex-watchOS -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch - 42mm' + global: + - MODULE_NAME=Regex +matrix: + include: + - script: + - xcodebuild test -project $MODULE_NAME.xcodeproj -scheme $MODULE_NAME-OSX + - xcodebuild test -project $MODULE_NAME.xcodeproj -scheme $MODULE_NAME-iOS -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' + - xcodebuild test -project $MODULE_NAME.xcodeproj -scheme $MODULE_NAME-tvOS -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV 1080p' + - xcodebuild build -project $MODULE_NAME.xcodeproj -scheme $MODULE_NAME-watchOS -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch - 42mm' + os: osx + osx_image: xcode7.2 + language: objective-c + env: + - secure: hsSJ4btmCIbNjAPyAOZvCAUUbupx9Obo0YIXkrQ/iteC4oWRv0g4TMh9Ie/zg9Cdn8P6QOlV2waoG4ZdCymW08/MASK5+Z+uRqAuAExF2l0NllbVTymEDKHkzGdId9EN4thj10TXrsq8kfTWg8O1As3r2Nl/H2lBmDK49DHZVU2cNl9EbgmALYS7CoZ2LwM/TnJgSvUB4l0yzPyz4veDNAgRvQ9iMXN1/gHsemZdcxrd9q3ce53+PRap2z9NUGQrpAefXCLjN8M8aKHExgr90aUxGz4DoHm+pRppMqFo9hIjEi0WQc+ikD3ExchxQH6LCCdTF20L5L0Sxj3AzhUsojDtB5zG9Rc8O/1UjzbcuHbdr0PC+0mSFuQzYsG009Zg1i6moeattmQOC/F/QYp/cXdlHT9K9T4dqh62Wp9lU/CeigJ6orKR9NgBuxEDOsObzNVoiRsqBn4fEOE2b+24XB7D8u4Twc7koRB1gG96JUFNWm5pSmM1WDzTJIlHTcxiU4iHMV/19mWnzJhYTLSXhXOhG1lO2FddeRlkKCuklWqcKvWWr6FnFA2uFxp17hM6YfVsvhDQiJ3Xd/byuNIVgkDuL80Jo/v7dkM8tElYeJsRGiRkZLtkOlIiRnWYTeFclNNSzJ14Ub/MT5W6wfEm/nqeY2G0w50Peu362XL2rFs= + before_install: + - brew update + - brew unlink carthage + - brew install carthage + - brew link carthage + before_script: + # bootstrap the dependencies for the project + # you can remove if you don't have dependencies + # - carthage bootstrap + before_deploy: + - carthage build --no-skip-current + - carthage archive $MODULE_NAME + - pod trunk push CrossroadRegex.podspec + deploy: + provider: releases + api_key: + secure: bln+wxsxX4fV0egcGEnF4VJpQBBos+ZqqnO8j88HVeVqTVKjrcnICalowX8nxwX6KhXqnuZNZWacc4bl4bLbIlAns1EgxhsR/N0qeMnp0SpSasBUSulWSaC8R4G7I6hxtScxZhh3BtZbJq3iYMGNj27LhpKaTpXGWxk4YOWmZEm19v8vUrXBI7qPYLRbnlHXx8DwOC3vjotSlIMyNGBlmC/npZ3A3QH2CLZSW8seXEhSlTUzbQ9gY5nNs7/rjmDhkRnNtEnvEuZdUix5SuCD5WO7VMYY7+Y+O3XyGjeIrd22B04DXyL70XrfTjbFGaQAt7uRYXWbd9M4ONo762Ee5boRNCJKolD6hVzUp0eRY3cLZgGIoZDMqUXEX5N4ZF1PbULKyEWGfavB7kzLx1kw4P6unYJW5gZR3blreij+eaN9HAVGNzf++c7vGhbwiE+zsoRZEiriEtii/hRZZ//czmeiFn7t0TQo/PozEu9lSaRSeGsUXseX12lWg9VCAYADvVV1PIIkb/FfQ76WRtP8BMJgu/yjUSB7ZxDxkB4zPvJNRuD/V7z9HTD9GNEyRuAdpiJy++dVyjRkW/xMfbPTkUCp0AdqdzL4L8orF7Ur9v+o3mlzKMTtmWxFhNo0dhAK4WC/jdNVKxbpV9ObG9Ew4+Hi43a7r4yxneNZWA1SikM= + file: $MODULE_NAME.framework.zip + skip_cleanup: true + on: + repo: crossroadlabs/Regex + tags: true + - script: + # build (yes for now swift-build should be like this) + - export SBCMD=`which swift-build` + - $SBCMD + # test + - swift test + sudo: required + dist: trusty + language: generic + before_install: + # install original swift distribution + - wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - + - cd .. + - export SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a + - wget https://swift.org/builds/development/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz + - tar xzf $SWIFT_VERSION-ubuntu14.04.tar.gz + - export PATH="${PWD}/${SWIFT_VERSION}-ubuntu14.04/usr/bin:${PATH}" + # install latest package manager with `swift-test` + - git clone https://github.com/apple/swift-package-manager + - cd swift-package-manager + - Utilities/bootstrap + - export SWIFT_BUILD_PATH=`pwd` + - export PATH=$SWIFT_BUILD_PATH/.build/debug:$PATH + - cd .. + # get back home + - cd $MODULE_NAME notifications: email: false -deploy: - provider: releases - api_key: - secure: bln+wxsxX4fV0egcGEnF4VJpQBBos+ZqqnO8j88HVeVqTVKjrcnICalowX8nxwX6KhXqnuZNZWacc4bl4bLbIlAns1EgxhsR/N0qeMnp0SpSasBUSulWSaC8R4G7I6hxtScxZhh3BtZbJq3iYMGNj27LhpKaTpXGWxk4YOWmZEm19v8vUrXBI7qPYLRbnlHXx8DwOC3vjotSlIMyNGBlmC/npZ3A3QH2CLZSW8seXEhSlTUzbQ9gY5nNs7/rjmDhkRnNtEnvEuZdUix5SuCD5WO7VMYY7+Y+O3XyGjeIrd22B04DXyL70XrfTjbFGaQAt7uRYXWbd9M4ONo762Ee5boRNCJKolD6hVzUp0eRY3cLZgGIoZDMqUXEX5N4ZF1PbULKyEWGfavB7kzLx1kw4P6unYJW5gZR3blreij+eaN9HAVGNzf++c7vGhbwiE+zsoRZEiriEtii/hRZZ//czmeiFn7t0TQo/PozEu9lSaRSeGsUXseX12lWg9VCAYADvVV1PIIkb/FfQ76WRtP8BMJgu/yjUSB7ZxDxkB4zPvJNRuD/V7z9HTD9GNEyRuAdpiJy++dVyjRkW/xMfbPTkUCp0AdqdzL4L8orF7Ur9v+o3mlzKMTtmWxFhNo0dhAK4WC/jdNVKxbpV9ObG9Ew4+Hi43a7r4yxneNZWA1SikM= - file: $FRAMEWORK_NAME.framework.zip - skip_cleanup: true - on: - repo: crossroadlabs/Regex - tags: true diff --git a/CrossroadRegex.podspec b/CrossroadRegex.podspec index aa68649..55e92f1 100644 --- a/CrossroadRegex.podspec +++ b/CrossroadRegex.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'CrossroadRegex' - s.version = '0.4.1' + s.version = '0.5' s.license = { :type => 'Apache 2.0', :file => 'LICENSE' } s.summary = 'Easy, portable and feature reach Regular Expressions for Swift' s.homepage = 'https://github.com/crossroadlabs/Regex' diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..c4f7303 --- /dev/null +++ b/Package.swift @@ -0,0 +1,26 @@ +//===--- Package.swift ----------------------------------------------------===// +//Copyright (c) 2016 Daniel Leping (dileping) +// +//Licensed under the Apache License, Version 2.0 (the "License"); +//you may not use this file except in compliance with the License. +//You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, software +//distributed under the License is distributed on an "AS IS" BASIS, +//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +//See the License for the specific language governing permissions and +//limitations under the License. +//===----------------------------------------------------------------------===// + +import PackageDescription + +let package = Package( + name: "Regex", + targets: [ + Target( + name: "Regex" + ) + ] +) diff --git a/README.md b/README.md index 38d9e60..afece90 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # Regex +![🐧 linux: ready](https://img.shields.io/badge/%F0%9F%90%A7%20linux-ready-red.svg) [![GitHub license](https://img.shields.io/badge/license-Apache 2.0-lightgrey.svg)](https://raw.githubusercontent.com/crossroadlabs/Regex/master/LICENSE) [![Build Status](https://travis-ci.org/crossroadlabs/Regex.svg?branch=master)](https://travis-ci.org/crossroadlabs/Regex) [![GitHub release](https://img.shields.io/github/release/crossroadlabs/Regex.svg)](https://github.com/crossroadlabs/Regex/releases) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CocoaPods version](https://img.shields.io/cocoapods/v/CrossroadRegex.svg)](https://cocoapods.org/pods/CrossroadRegex) -![Platform OS X | iOS | tvOS | watchOS](https://img.shields.io/badge/platform-OS%20X%20%7C%20iOS%20%7C%20tvOS%20%7C%20watchOS-orange.svg) +![Platform OS X | iOS | tvOS | watchOS | Linux](https://img.shields.io/badge/platform-Linux%20%7C%20OS%20X%20%7C%20iOS%20%7C%20tvOS%20%7C%20watchOS-orange.svg) ## Advanced regular expressions for Swift @@ -13,6 +14,16 @@ ### Installation +#### [Package Manager](https://swift.org/package-manager/) + +Add the following dependency to your [Package.swift](https://github.com/apple/swift-package-manager/blob/master/Documentation/Package.swift.md): + +```swift +.Package(url: "https://github.com/ypopovych/Regex.git", majorVersion: 1) +``` + +Run ```swift build``` and build your app. Package manager is supported on OS X, but it's still recommended to be used on Linux only. + #### [CocoaPods](http://cocoapods.org/) Add the following to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html): @@ -121,10 +132,12 @@ Regex framework was mainly introduced to fulfill the needs of [Swift Express](ht ## Roadmap -* v0.5: alternative PCRE based implementation (OS X, Linux) -* v1.0: full Linux support +* v1.0: stable release (once we will see that no issues are coming) ## Changelog +* v0.5 + * package manager support + * full linux support 🐧 * v0.4.1 * support for optionally present groups * v0.4 diff --git a/Regex.xcodeproj/project.pbxproj b/Regex.xcodeproj/project.pbxproj index c86a585..68783f9 100644 --- a/Regex.xcodeproj/project.pbxproj +++ b/Regex.xcodeproj/project.pbxproj @@ -13,7 +13,7 @@ 651655191C53ABC500B613AB /* String+Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655181C53ABC500B613AB /* String+Regex.swift */; }; 6516551E1C53C05C00B613AB /* Match.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516551D1C53C05C00B613AB /* Match.swift */; }; 651655201C53CCAC00B613AB /* MatchSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516551F1C53CCAC00B613AB /* MatchSequence.swift */; }; - 651655221C53DAD200B613AB /* FoundationUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655211C53DAD200B613AB /* FoundationUtils.swift */; }; + 651655221C53DAD200B613AB /* GroupRangeUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655211C53DAD200B613AB /* GroupRangeUtils.swift */; }; 651655241C53DB1300B613AB /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655231C53DB1300B613AB /* Utils.swift */; }; 65C529911C565EB9002BF559 /* Regex.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65C529871C565EB8002BF559 /* Regex.framework */; }; 65C5299E1C5660D2002BF559 /* RegexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516550B1C53AB2000B613AB /* RegexTests.swift */; }; @@ -21,22 +21,26 @@ 65C529A01C5660E1002BF559 /* Match.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516551D1C53C05C00B613AB /* Match.swift */; }; 65C529A11C5660E4002BF559 /* MatchSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516551F1C53CCAC00B613AB /* MatchSequence.swift */; }; 65C529A21C5660E6002BF559 /* String+Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655181C53ABC500B613AB /* String+Regex.swift */; }; - 65C529A31C5660E9002BF559 /* FoundationUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655211C53DAD200B613AB /* FoundationUtils.swift */; }; + 65C529A31C5660E9002BF559 /* GroupRangeUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655211C53DAD200B613AB /* GroupRangeUtils.swift */; }; 65C529A41C5660EC002BF559 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655231C53DB1300B613AB /* Utils.swift */; }; 65C529C11C5664B0002BF559 /* Regex.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65C529B71C5664B0002BF559 /* Regex.framework */; }; 65C529CE1C56656D002BF559 /* Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655161C53AB3F00B613AB /* Regex.swift */; }; 65C529CF1C566570002BF559 /* Match.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516551D1C53C05C00B613AB /* Match.swift */; }; 65C529D01C566573002BF559 /* MatchSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516551F1C53CCAC00B613AB /* MatchSequence.swift */; }; 65C529D11C566577002BF559 /* String+Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655181C53ABC500B613AB /* String+Regex.swift */; }; - 65C529D21C56657A002BF559 /* FoundationUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655211C53DAD200B613AB /* FoundationUtils.swift */; }; + 65C529D21C56657A002BF559 /* GroupRangeUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655211C53DAD200B613AB /* GroupRangeUtils.swift */; }; 65C529D31C56657D002BF559 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655231C53DB1300B613AB /* Utils.swift */; }; 65C529D41C5665CE002BF559 /* RegexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516550B1C53AB2000B613AB /* RegexTests.swift */; }; 65C529E21C566A25002BF559 /* Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655161C53AB3F00B613AB /* Regex.swift */; }; 65C529E31C566A25002BF559 /* Match.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516551D1C53C05C00B613AB /* Match.swift */; }; 65C529E41C566A25002BF559 /* MatchSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6516551F1C53CCAC00B613AB /* MatchSequence.swift */; }; 65C529E51C566A25002BF559 /* String+Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655181C53ABC500B613AB /* String+Regex.swift */; }; - 65C529E61C566A25002BF559 /* FoundationUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655211C53DAD200B613AB /* FoundationUtils.swift */; }; + 65C529E61C566A25002BF559 /* GroupRangeUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655211C53DAD200B613AB /* GroupRangeUtils.swift */; }; 65C529E71C566A25002BF559 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651655231C53DB1300B613AB /* Utils.swift */; }; + 96D154781C6CE33C00F9A981 /* PlatformTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D154771C6CE33C00F9A981 /* PlatformTypes.swift */; }; + 96D1547F1C6CE42E00F9A981 /* PlatformTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D154771C6CE33C00F9A981 /* PlatformTypes.swift */; }; + 96D154801C6CE42F00F9A981 /* PlatformTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D154771C6CE33C00F9A981 /* PlatformTypes.swift */; }; + 96D154811C6CE43000F9A981 /* PlatformTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D154771C6CE33C00F9A981 /* PlatformTypes.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -73,13 +77,14 @@ 651655181C53ABC500B613AB /* String+Regex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Regex.swift"; sourceTree = ""; }; 6516551D1C53C05C00B613AB /* Match.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Match.swift; sourceTree = ""; }; 6516551F1C53CCAC00B613AB /* MatchSequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MatchSequence.swift; sourceTree = ""; }; - 651655211C53DAD200B613AB /* FoundationUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationUtils.swift; sourceTree = ""; }; + 651655211C53DAD200B613AB /* GroupRangeUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupRangeUtils.swift; sourceTree = ""; }; 651655231C53DB1300B613AB /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 65C529871C565EB8002BF559 /* Regex.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Regex.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65C529901C565EB9002BF559 /* RegexTests-iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "RegexTests-iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 65C529B71C5664B0002BF559 /* Regex.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Regex.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65C529C01C5664B0002BF559 /* RegexTests-tvOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "RegexTests-tvOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 65C529DA1C5669D6002BF559 /* Regex.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Regex.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 96D154771C6CE33C00F9A981 /* PlatformTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlatformTypes.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -169,8 +174,9 @@ 6516551D1C53C05C00B613AB /* Match.swift */, 6516551F1C53CCAC00B613AB /* MatchSequence.swift */, 651655181C53ABC500B613AB /* String+Regex.swift */, - 651655211C53DAD200B613AB /* FoundationUtils.swift */, + 651655211C53DAD200B613AB /* GroupRangeUtils.swift */, 651655231C53DB1300B613AB /* Utils.swift */, + 96D154771C6CE33C00F9A981 /* PlatformTypes.swift */, ); path = Regex; sourceTree = ""; @@ -181,7 +187,8 @@ 6516550B1C53AB2000B613AB /* RegexTests.swift */, 6516550D1C53AB2000B613AB /* Info.plist */, ); - path = RegexTests; + name = RegexTests; + path = Tests/Regex; sourceTree = ""; }; /* End PBXGroup section */ @@ -460,7 +467,8 @@ 651655201C53CCAC00B613AB /* MatchSequence.swift in Sources */, 651655191C53ABC500B613AB /* String+Regex.swift in Sources */, 651655171C53AB3F00B613AB /* Regex.swift in Sources */, - 651655221C53DAD200B613AB /* FoundationUtils.swift in Sources */, + 96D154781C6CE33C00F9A981 /* PlatformTypes.swift in Sources */, + 651655221C53DAD200B613AB /* GroupRangeUtils.swift in Sources */, 6516551E1C53C05C00B613AB /* Match.swift in Sources */, 651655241C53DB1300B613AB /* Utils.swift in Sources */, ); @@ -479,9 +487,10 @@ buildActionMask = 2147483647; files = ( 65C529A11C5660E4002BF559 /* MatchSequence.swift in Sources */, + 96D1547F1C6CE42E00F9A981 /* PlatformTypes.swift in Sources */, 65C5299F1C5660DD002BF559 /* Regex.swift in Sources */, 65C529A21C5660E6002BF559 /* String+Regex.swift in Sources */, - 65C529A31C5660E9002BF559 /* FoundationUtils.swift in Sources */, + 65C529A31C5660E9002BF559 /* GroupRangeUtils.swift in Sources */, 65C529A01C5660E1002BF559 /* Match.swift in Sources */, 65C529A41C5660EC002BF559 /* Utils.swift in Sources */, ); @@ -500,9 +509,10 @@ buildActionMask = 2147483647; files = ( 65C529D01C566573002BF559 /* MatchSequence.swift in Sources */, + 96D154801C6CE42F00F9A981 /* PlatformTypes.swift in Sources */, 65C529CE1C56656D002BF559 /* Regex.swift in Sources */, 65C529D11C566577002BF559 /* String+Regex.swift in Sources */, - 65C529D21C56657A002BF559 /* FoundationUtils.swift in Sources */, + 65C529D21C56657A002BF559 /* GroupRangeUtils.swift in Sources */, 65C529CF1C566570002BF559 /* Match.swift in Sources */, 65C529D31C56657D002BF559 /* Utils.swift in Sources */, ); @@ -521,9 +531,10 @@ buildActionMask = 2147483647; files = ( 65C529E41C566A25002BF559 /* MatchSequence.swift in Sources */, + 96D154811C6CE43000F9A981 /* PlatformTypes.swift in Sources */, 65C529E21C566A25002BF559 /* Regex.swift in Sources */, 65C529E51C566A25002BF559 /* String+Regex.swift in Sources */, - 65C529E61C566A25002BF559 /* FoundationUtils.swift in Sources */, + 65C529E61C566A25002BF559 /* GroupRangeUtils.swift in Sources */, 65C529E31C566A25002BF559 /* Match.swift in Sources */, 65C529E71C566A25002BF559 /* Utils.swift in Sources */, ); @@ -652,6 +663,7 @@ PRODUCT_BUNDLE_IDENTIFIER = xyz.crossroadlabs.Regex; PRODUCT_NAME = "${PROJECT_NAME}"; SKIP_INSTALL = YES; + SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Carthage/Checkouts"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; @@ -672,6 +684,7 @@ PRODUCT_BUNDLE_IDENTIFIER = xyz.crossroadlabs.Regex; PRODUCT_NAME = "${PROJECT_NAME}"; SKIP_INSTALL = YES; + SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Carthage/Checkouts"; }; name = Release; }; @@ -679,8 +692,9 @@ isa = XCBuildConfiguration; buildSettings = { COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = RegexTests/Info.plist; + INFOPLIST_FILE = Tests/Regex/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LIBRARY_SEARCH_PATHS = /usr/local/opt/icu4c/lib; PRODUCT_BUNDLE_IDENTIFIER = xyz.crossroadlabs.RegexTests; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -690,8 +704,9 @@ isa = XCBuildConfiguration; buildSettings = { COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = RegexTests/Info.plist; + INFOPLIST_FILE = Tests/Regex/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LIBRARY_SEARCH_PATHS = /usr/local/opt/icu4c/lib; PRODUCT_BUNDLE_IDENTIFIER = xyz.crossroadlabs.RegexTests; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -742,7 +757,7 @@ isa = XCBuildConfiguration; buildSettings = { "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - INFOPLIST_FILE = RegexTests/Info.plist; + INFOPLIST_FILE = Tests/Regex/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = xyz.crossroadlabs.RegexTests; @@ -755,7 +770,7 @@ isa = XCBuildConfiguration; buildSettings = { "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - INFOPLIST_FILE = RegexTests/Info.plist; + INFOPLIST_FILE = Tests/Regex/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = xyz.crossroadlabs.RegexTests; @@ -807,7 +822,7 @@ 65C529CA1C5664B0002BF559 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - INFOPLIST_FILE = RegexTests/Info.plist; + INFOPLIST_FILE = Tests/Regex/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = xyz.crossroadlabs.RegexTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -819,7 +834,7 @@ 65C529CB1C5664B0002BF559 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - INFOPLIST_FILE = RegexTests/Info.plist; + INFOPLIST_FILE = Tests/Regex/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = xyz.crossroadlabs.RegexTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -925,6 +940,7 @@ 65C529C91C5664B0002BF559 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 65C529CD1C5664B0002BF559 /* Build configuration list for PBXNativeTarget "RegexTests-tvOS" */ = { isa = XCConfigurationList; @@ -933,6 +949,7 @@ 65C529CB1C5664B0002BF559 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 65C529DF1C5669D6002BF559 /* Build configuration list for PBXNativeTarget "Regex-watchOS" */ = { isa = XCConfigurationList; @@ -941,6 +958,7 @@ 65C529E11C5669D6002BF559 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/Regex/FoundationUtils.swift b/Regex/GroupRangeUtils.swift similarity index 52% rename from Regex/FoundationUtils.swift rename to Regex/GroupRangeUtils.swift index fb3a4ca..611302b 100644 --- a/Regex/FoundationUtils.swift +++ b/Regex/GroupRangeUtils.swift @@ -1,4 +1,4 @@ -//===--- FoundationUtils.swift --------------------------------------------===// +//===--- GroupRangeUtils.swift --------------------------------------------===// //Copyright (c) 2016 Daniel Leping (dileping) // //Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +14,19 @@ //limitations under the License. //===----------------------------------------------------------------------===// -#if !os(Linux) - //here we use NSRegularExpression - import Foundation +import Foundation - enum InvalidRangeError : ErrorType { - case Error - } - - extension NSRange { - func toStringRange(source:String) throws -> StringRange { - let len = source.characters.count - if self.location >= len || self.location + self.length > len { - throw InvalidRangeError.Error - } - let start = source.startIndex.advancedBy(self.location) - return StringRange(start: start, end: start.advancedBy(self.length)) +enum InvalidRangeError : ErrorType { + case Error +} + +extension GroupRange { + func toStringRange(source:String) throws -> StringRange { + let len = source.characters.count + if self.location < 0 || self.location >= len || self.location + self.length > len { + throw InvalidRangeError.Error } + let start = source.startIndex.advancedBy(self.location) + return StringRange(start: start, end: start.advancedBy(self.length)) } -#endif \ No newline at end of file +} diff --git a/Regex/Info.plist b/Regex/Info.plist index d645108..12e5e30 100644 --- a/Regex/Info.plist +++ b/Regex/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.4.1 + 0.5 CFBundleSignature ???? CFBundleVersion diff --git a/Regex/Match.swift b/Regex/Match.swift index dd7c926..91c0367 100644 --- a/Regex/Match.swift +++ b/Regex/Match.swift @@ -48,9 +48,6 @@ public class Match : MatchType { return nameMap[group]! + 1 } -#if os(Linux) - //TODO: implement with PCRE -#else public var range:StringRange { get { //here it never throws, because otherwise it will not match @@ -61,7 +58,7 @@ public class Match : MatchType { public var ranges:[StringRange?] { get { var result = Array() - for(var i:Int = 0; i < match.numberOfRanges; i++) { + for i in 0.. + /// A type that represents a subsequence of some of the elements. - public typealias Generator = AnyGenerator - /// A type that represents a subsequence of some of the elements. - public func generate() -> Generator { - var index = context.startIndex + public func generate() -> Generator { + var index = context.startIndex - return anyGenerator { - if self.context.endIndex > index { - let result = Match(source: self.source, match: self.context[index], groupNames: self.groupNames) - index = index.advancedBy(1) - return result - } else { - return nil - } + return anyGenerator { + if self.context.endIndex > index { + let result = Match(source: self.source, match: self.context[index], groupNames: self.groupNames) + index = index.advancedBy(1) + return result + } else { + return nil } } } - -#endif \ No newline at end of file +} diff --git a/Regex/PlatformTypes.swift b/Regex/PlatformTypes.swift new file mode 100644 index 0000000..ee2453b --- /dev/null +++ b/Regex/PlatformTypes.swift @@ -0,0 +1,23 @@ +//===--- PlatformTypes.swift -----------------------------------------------===// +//Copyright (c) 2016 Daniel Leping (dileping) +// +//Licensed under the Apache License, Version 2.0 (the "License"); +//you may not use this file except in compliance with the License. +//You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, software +//distributed under the License is distributed on an "AS IS" BASIS, +//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +//See the License for the specific language governing permissions and +//limitations under the License. +//===----------------------------------------------------------------------===// + +import Foundation + +//here we use NSRegularExpression +typealias CompiledPattern = NSRegularExpression +typealias CompiledMatchContext = [NSTextCheckingResult] +typealias CompiledPatternMatch = NSTextCheckingResult +typealias GroupRange = NSRange diff --git a/Regex/Regex.swift b/Regex/Regex.swift index 8ca6a1e..8c2e0bb 100644 --- a/Regex/Regex.swift +++ b/Regex/Regex.swift @@ -14,8 +14,7 @@ //limitations under the License. //===----------------------------------------------------------------------===// -//TODO: implement with PCRE -//TODO: implement sintactic sugar operators +import Foundation //makes it easier to maintain two implementations public protocol RegexType { @@ -38,22 +37,6 @@ public protocol RegexType { func split(source:String) -> [String] } -// later make OS X to work via pcre as well (should be faster) -#if os(Linux) - - typealias CompiledPattern = Void - typealias CompiledMatchContext = Void - typealias CompiledPatternMatch = Void - -#else - //here we use NSRegularExpression - import Foundation - - typealias CompiledPattern = NSRegularExpression - typealias CompiledMatchContext = [NSTextCheckingResult] - typealias CompiledPatternMatch = NSTextCheckingResult -#endif - public class Regex : RegexType { public let pattern:String public let groupNames:[String] @@ -74,18 +57,6 @@ public class Regex : RegexType { try self.init(pattern:pattern, groupNames:groupNames) } -#if os(Linux) - - private static func compile(pattern:String) throws -> CompiledPattern { - throw NSFoundationNotImplemented - } - - public func findAll(source:String) -> MatchSequence { - throw NSFoundationNotImplemented - } - -#else - private static func compile(pattern:String) throws -> CompiledPattern { //pass options return try NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.CaseInsensitive) @@ -119,8 +90,7 @@ public class Regex : RegexType { self.compiled!.replacementStringForResult(match.match, inString: source, offset: 0, template: replacement) } } - -#endif + private func replaceMatches(source:String, matches:T, replacer:Match -> String?) -> String { var result = "" var lastRange:StringRange = StringRange(start: source.startIndex, end: source.startIndex) @@ -179,4 +149,4 @@ public class Regex : RegexType { result.append(rest) return result } -} \ No newline at end of file +} diff --git a/Regex/Utils.swift b/Regex/Utils.swift index d391762..f1cf5e2 100644 --- a/Regex/Utils.swift +++ b/Regex/Utils.swift @@ -23,7 +23,7 @@ extension SequenceType where Generator.Element : Hashable { var index = 0 for e in self { result[e] = index - index++ + index += 1 } return result } diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..a636917 --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,23 @@ +//===--- LinuxMain.swift ---------------------------------------------------===// +//Copyright (c) 2016 Daniel Leping (dileping) +// +//Licensed under the Apache License, Version 2.0 (the "License"); +//you may not use this file except in compliance with the License. +//You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, software +//distributed under the License is distributed on an "AS IS" BASIS, +//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +//See the License for the specific language governing permissions and +//limitations under the License. +//===----------------------------------------------------------------------===// + +import XCTest + +@testable import Regextest + +XCTMain([ + RegexTests(), +]) diff --git a/RegexTests/Info.plist b/Tests/Regex/Info.plist similarity index 100% rename from RegexTests/Info.plist rename to Tests/Regex/Info.plist diff --git a/RegexTests/RegexTests.swift b/Tests/Regex/RegexTests.swift similarity index 83% rename from RegexTests/RegexTests.swift rename to Tests/Regex/RegexTests.swift index 7d1692b..872acb2 100644 --- a/RegexTests/RegexTests.swift +++ b/Tests/Regex/RegexTests.swift @@ -31,16 +31,6 @@ class RegexTests: XCTestCase { let namesSplitPattern = "\\s*;\\s*"; let splitNames = ["Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand"] - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - func testMatches() { XCTAssert(regex.matches(source)) XCTAssert(source =~ regex) @@ -54,7 +44,7 @@ class RegexTests: XCTestCase { XCTAssertEqual(RegexTests.pattern.r?.findFirst(source)?.group(2), digits) } - func testGroup(group:String, reference:String) { + func _testGroup(group:String, reference:String) { let matches = regex.findAll(source) for match in matches { let value = match.group(group) @@ -63,15 +53,15 @@ class RegexTests: XCTestCase { } func testLetter() { - testGroup("letter", reference: letter) + _testGroup("letter", reference: letter) } func testDigits() { - testGroup("digits", reference: digits) + _testGroup("digits", reference: digits) } func testRest() { - testGroup("rest", reference: rest) + _testGroup("rest", reference: rest) } func testFirstMatch() { @@ -163,17 +153,28 @@ class RegexTests: XCTestCase { XCTAssertNil(match.group(1)) XCTAssertNotNil(match.group(2)) } - - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measureBlock { - // Put the code you want to measure the time of here. - } +} + +#if os(Linux) +extension RegexTests : XCTestCaseProvider { + var allTests : [(String, () throws -> Void)] { + return [ + ("testMatches", testMatches), + ("testSimple", testSimple), + ("testLetter", testLetter), + ("testDigits", testDigits), + ("testRest", testRest), + ("testFirstMatch", testFirstMatch), + ("testReplaceAll", testReplaceAll), + ("testReplaceAllWithReplacer", testReplaceAllWithReplacer), + ("testReplaceFirst", testReplaceFirst), + ("testReplaceFirstWithReplacer", testReplaceFirstWithReplacer), + ("testSplit", testSplit), + ("testSplitOnString", testSplitOnString), + ("testSplitWithSubgroups", testSplitWithSubgroups), + ("testNonExistingGroup", testNonExistingGroup) + ] } - } +#endif +