diff --git a/.gitignore b/.gitignore index 48646f0..c80b1a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,13 @@ -# OS X -.DS_Store - # Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +.build/ build/ +DerivedData/ + +## Various settings *.pbxuser !default.pbxuser *.mode1v3 @@ -11,29 +16,54 @@ build/ !default.mode2v3 *.perspectivev3 !default.perspectivev3 -xcuserdata -*.xccheckout -profile +xcuserdata/ + +## Other *.moved-aside -DerivedData +*.xcuserstate + +## Obj-C/Swift specific *.hmap *.ipa +*.dSYM.zip +*.dSYM -# Bundler -.bundle +## Playgrounds +timeline.xctimeline +playground.xcworkspace -Carthage +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +.build/ + +# CocoaPods +# # We recommend against adding the Pods directory to your .gitignore. However # you should judge for yourself, the pros and cons are mentioned at: -# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control -# -# Note: if you ignore the Pods directory, make sure to uncomment -# `pod install` in .travis.yml +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ + +# Carthage # -Pods/ +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build -Example/Podfile.lock +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md -*.lock +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output -*.lock +Packages/ +docs/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3c50207..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -# references: -# * http://www.objc.io/issue-6/travis-ci.html -# * https://github.com/supermarin/xcpretty#usage - -language: objective-c -osx_image: xcode7.1 -cache: cocoapods -podfile: Example/Podfile -before_install: -- gem install cocoapods # Since Travis is not always on latest version -- pod install --project-directory=Example - -script: -- set -o pipefail && xcodebuild test -workspace Example/SwiftString.xcworkspace -scheme SwiftString-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty -- pod lib lint diff --git a/Example/Podfile b/Example/Podfile deleted file mode 100644 index f013c53..0000000 --- a/Example/Podfile +++ /dev/null @@ -1,11 +0,0 @@ -source 'https://github.com/CocoaPods/Specs.git' -use_frameworks! - -target 'SwiftString_Example', :exclusive => true do - pod 'SwiftString', :path => '../' -end - -target 'SwiftString_Tests', :exclusive => true do - pod 'SwiftString', :path => '../' - pod 'SwiftHamcrest' -end diff --git a/Example/Podfile.lock b/Example/Podfile.lock deleted file mode 100644 index 7b0c421..0000000 --- a/Example/Podfile.lock +++ /dev/null @@ -1,17 +0,0 @@ -PODS: - - SwiftHamcrest (0.3) - - SwiftString (0.1) - -DEPENDENCIES: - - SwiftHamcrest - - SwiftString (from `../`) - -EXTERNAL SOURCES: - SwiftString: - :path: "../" - -SPEC CHECKSUMS: - SwiftHamcrest: 652d2e197df0957b532f1c66a9112bc809030965 - SwiftString: 0a32494e59f63c337ad0b2b5fa8cdba5c536484a - -COCOAPODS: 0.39.0 diff --git a/Example/SwiftString.xcodeproj/project.pbxproj b/Example/SwiftString.xcodeproj/project.pbxproj deleted file mode 100644 index a672999..0000000 --- a/Example/SwiftString.xcodeproj/project.pbxproj +++ /dev/null @@ -1,591 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 589430772C3EC1111068D513 /* Pods_SwiftString_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA0E139958C875325F8154C8 /* Pods_SwiftString_Example.framework */; }; - 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; - 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; - 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; }; - 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; - 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; - 607FACEC1AFB9204008FA782 /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* StringExtensionTests.swift */; }; - C914AF1AC37AD238F5BE89DF /* Pods_SwiftString_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF3B5F0448FBA6B5F3853E10 /* Pods_SwiftString_Tests.framework */; }; - E361734F1C5EC0DA0063AAC7 /* String+HTMLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E361734E1C5EC0DA0063AAC7 /* String+HTMLTests.swift */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 607FACC81AFB9204008FA782 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 607FACCF1AFB9204008FA782; - remoteInfo = SwiftString; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - 019FA1CE0AA97C15E2CE000C /* Pods-SwiftString_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftString_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftString_Example/Pods-SwiftString_Example.debug.xcconfig"; sourceTree = ""; }; - 0426C5BFC54D8C1FBD78C15F /* Pods-SwiftString_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftString_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftString_Example/Pods-SwiftString_Example.release.xcconfig"; sourceTree = ""; }; - 372CCE3674464B433AA934A9 /* SwiftString.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = SwiftString.podspec; path = ../SwiftString.podspec; sourceTree = ""; }; - 43D9619446241F6E12A5D132 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; - 607FACD01AFB9204008FA782 /* SwiftString_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftString_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; - 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; - 607FACE51AFB9204008FA782 /* SwiftString_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftString_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 607FACEB1AFB9204008FA782 /* StringExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtensionTests.swift; sourceTree = ""; }; - 6F2196573BA624D905B98536 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; - AF3B5F0448FBA6B5F3853E10 /* Pods_SwiftString_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SwiftString_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - BA0E139958C875325F8154C8 /* Pods_SwiftString_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SwiftString_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - CAF2F5323C60B18222F42A88 /* Pods-SwiftString_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftString_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftString_Tests/Pods-SwiftString_Tests.release.xcconfig"; sourceTree = ""; }; - DD7662C0FCE9A2A50CCAA5DA /* Pods-SwiftString_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftString_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftString_Tests/Pods-SwiftString_Tests.debug.xcconfig"; sourceTree = ""; }; - E361734E1C5EC0DA0063AAC7 /* String+HTMLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+HTMLTests.swift"; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 607FACCD1AFB9204008FA782 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 589430772C3EC1111068D513 /* Pods_SwiftString_Example.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 607FACE21AFB9204008FA782 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - C914AF1AC37AD238F5BE89DF /* Pods_SwiftString_Tests.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 607FACC71AFB9204008FA782 = { - isa = PBXGroup; - children = ( - 607FACF51AFB993E008FA782 /* Podspec Metadata */, - 607FACD21AFB9204008FA782 /* Example for SwiftString */, - 607FACE81AFB9204008FA782 /* Tests */, - 607FACD11AFB9204008FA782 /* Products */, - 90F499C4F609D8EE4B8866F0 /* Pods */, - 9B5FA3D4893E4286D48E5F75 /* Frameworks */, - ); - sourceTree = ""; - }; - 607FACD11AFB9204008FA782 /* Products */ = { - isa = PBXGroup; - children = ( - 607FACD01AFB9204008FA782 /* SwiftString_Example.app */, - 607FACE51AFB9204008FA782 /* SwiftString_Tests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - 607FACD21AFB9204008FA782 /* Example for SwiftString */ = { - isa = PBXGroup; - children = ( - 607FACD51AFB9204008FA782 /* AppDelegate.swift */, - 607FACD71AFB9204008FA782 /* ViewController.swift */, - 607FACD91AFB9204008FA782 /* Main.storyboard */, - 607FACDC1AFB9204008FA782 /* Images.xcassets */, - 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, - 607FACD31AFB9204008FA782 /* Supporting Files */, - ); - name = "Example for SwiftString"; - path = SwiftString; - sourceTree = ""; - }; - 607FACD31AFB9204008FA782 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 607FACD41AFB9204008FA782 /* Info.plist */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 607FACE81AFB9204008FA782 /* Tests */ = { - isa = PBXGroup; - children = ( - 607FACEB1AFB9204008FA782 /* StringExtensionTests.swift */, - E361734E1C5EC0DA0063AAC7 /* String+HTMLTests.swift */, - 607FACE91AFB9204008FA782 /* Supporting Files */, - ); - path = Tests; - sourceTree = ""; - }; - 607FACE91AFB9204008FA782 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 607FACEA1AFB9204008FA782 /* Info.plist */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 607FACF51AFB993E008FA782 /* Podspec Metadata */ = { - isa = PBXGroup; - children = ( - 372CCE3674464B433AA934A9 /* SwiftString.podspec */, - 43D9619446241F6E12A5D132 /* README.md */, - 6F2196573BA624D905B98536 /* LICENSE */, - ); - name = "Podspec Metadata"; - sourceTree = ""; - }; - 90F499C4F609D8EE4B8866F0 /* Pods */ = { - isa = PBXGroup; - children = ( - 019FA1CE0AA97C15E2CE000C /* Pods-SwiftString_Example.debug.xcconfig */, - 0426C5BFC54D8C1FBD78C15F /* Pods-SwiftString_Example.release.xcconfig */, - DD7662C0FCE9A2A50CCAA5DA /* Pods-SwiftString_Tests.debug.xcconfig */, - CAF2F5323C60B18222F42A88 /* Pods-SwiftString_Tests.release.xcconfig */, - ); - name = Pods; - sourceTree = ""; - }; - 9B5FA3D4893E4286D48E5F75 /* Frameworks */ = { - isa = PBXGroup; - children = ( - BA0E139958C875325F8154C8 /* Pods_SwiftString_Example.framework */, - AF3B5F0448FBA6B5F3853E10 /* Pods_SwiftString_Tests.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 607FACCF1AFB9204008FA782 /* SwiftString_Example */ = { - isa = PBXNativeTarget; - buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "SwiftString_Example" */; - buildPhases = ( - 1EED4C78D4534C0B6CCEACEF /* Check Pods Manifest.lock */, - 607FACCC1AFB9204008FA782 /* Sources */, - 607FACCD1AFB9204008FA782 /* Frameworks */, - 607FACCE1AFB9204008FA782 /* Resources */, - 669AE38B7A12FD629F57750E /* Embed Pods Frameworks */, - 2FB142E00953020DAFCDEA76 /* Copy Pods Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = SwiftString_Example; - productName = SwiftString; - productReference = 607FACD01AFB9204008FA782 /* SwiftString_Example.app */; - productType = "com.apple.product-type.application"; - }; - 607FACE41AFB9204008FA782 /* SwiftString_Tests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "SwiftString_Tests" */; - buildPhases = ( - DD43306B24A8C58478E69FA2 /* Check Pods Manifest.lock */, - 607FACE11AFB9204008FA782 /* Sources */, - 607FACE21AFB9204008FA782 /* Frameworks */, - 607FACE31AFB9204008FA782 /* Resources */, - F82078855395DF8B82837C90 /* Embed Pods Frameworks */, - 98E0193430A08EF1190A7DC0 /* Copy Pods Resources */, - ); - buildRules = ( - ); - dependencies = ( - 607FACE71AFB9204008FA782 /* PBXTargetDependency */, - ); - name = SwiftString_Tests; - productName = Tests; - productReference = 607FACE51AFB9204008FA782 /* SwiftString_Tests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 607FACC81AFB9204008FA782 /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; - ORGANIZATIONNAME = CocoaPods; - TargetAttributes = { - 607FACCF1AFB9204008FA782 = { - CreatedOnToolsVersion = 6.3.1; - DevelopmentTeam = T6UGWQ58CZ; - }; - 607FACE41AFB9204008FA782 = { - CreatedOnToolsVersion = 6.3.1; - TestTargetID = 607FACCF1AFB9204008FA782; - }; - }; - }; - buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "SwiftString" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 607FACC71AFB9204008FA782; - productRefGroup = 607FACD11AFB9204008FA782 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 607FACCF1AFB9204008FA782 /* SwiftString_Example */, - 607FACE41AFB9204008FA782 /* SwiftString_Tests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 607FACCE1AFB9204008FA782 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, - 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, - 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 607FACE31AFB9204008FA782 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - 1EED4C78D4534C0B6CCEACEF /* Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Check Pods Manifest.lock"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - 2FB142E00953020DAFCDEA76 /* Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SwiftString_Example/Pods-SwiftString_Example-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - 669AE38B7A12FD629F57750E /* Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SwiftString_Example/Pods-SwiftString_Example-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - 98E0193430A08EF1190A7DC0 /* Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SwiftString_Tests/Pods-SwiftString_Tests-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - DD43306B24A8C58478E69FA2 /* Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Check Pods Manifest.lock"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - F82078855395DF8B82837C90 /* Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SwiftString_Tests/Pods-SwiftString_Tests-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 607FACCC1AFB9204008FA782 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */, - 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 607FACE11AFB9204008FA782 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 607FACEC1AFB9204008FA782 /* StringExtensionTests.swift in Sources */, - E361734F1C5EC0DA0063AAC7 /* String+HTMLTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 607FACE71AFB9204008FA782 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 607FACCF1AFB9204008FA782 /* SwiftString_Example */; - targetProxy = 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin PBXVariantGroup section */ - 607FACD91AFB9204008FA782 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 607FACDA1AFB9204008FA782 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; - 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */ = { - isa = PBXVariantGroup; - children = ( - 607FACDF1AFB9204008FA782 /* Base */, - ); - name = LaunchScreen.xib; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 607FACED1AFB9204008FA782 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.3; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 607FACEE1AFB9204008FA782 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.3; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 607FACF01AFB9204008FA782 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 019FA1CE0AA97C15E2CE000C /* Pods-SwiftString_Example.debug.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "iPhone Developer"; - INFOPLIST_FILE = SwiftString/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MODULE_NAME = ExampleApp; - PRODUCT_BUNDLE_IDENTIFIER = "com.redbricklabs.SwiftString-Example"; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 607FACF11AFB9204008FA782 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 0426C5BFC54D8C1FBD78C15F /* Pods-SwiftString_Example.release.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "iPhone Developer"; - INFOPLIST_FILE = SwiftString/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MODULE_NAME = ExampleApp; - PRODUCT_BUNDLE_IDENTIFIER = "com.redbricklabs.SwiftString-Example"; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; - 607FACF31AFB9204008FA782 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = DD7662C0FCE9A2A50CCAA5DA /* Pods-SwiftString_Tests.debug.xcconfig */; - buildSettings = { - BUNDLE_LOADER = "$(TEST_HOST)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftString_Example.app/SwiftString_Example"; - }; - name = Debug; - }; - 607FACF41AFB9204008FA782 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = CAF2F5323C60B18222F42A88 /* Pods-SwiftString_Tests.release.xcconfig */; - buildSettings = { - BUNDLE_LOADER = "$(TEST_HOST)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftString_Example.app/SwiftString_Example"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "SwiftString" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 607FACED1AFB9204008FA782 /* Debug */, - 607FACEE1AFB9204008FA782 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "SwiftString_Example" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 607FACF01AFB9204008FA782 /* Debug */, - 607FACF11AFB9204008FA782 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "SwiftString_Tests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 607FACF31AFB9204008FA782 /* Debug */, - 607FACF41AFB9204008FA782 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 607FACC81AFB9204008FA782 /* Project object */; -} diff --git a/Example/SwiftString.xcworkspace/contents.xcworkspacedata b/Example/SwiftString.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 2846d4e..0000000 --- a/Example/SwiftString.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/Example/SwiftString/AppDelegate.swift b/Example/SwiftString/AppDelegate.swift deleted file mode 100644 index 080e283..0000000 --- a/Example/SwiftString/AppDelegate.swift +++ /dev/null @@ -1,46 +0,0 @@ -// -// AppDelegate.swift -// SwiftString -// -// Created by Andrew Mayne on 01/31/2016. -// Copyright (c) 2016 Andrew Mayne. All rights reserved. -// - -import UIKit - -@UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate { - - var window: UIWindow? - - - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - // Override point for customization after application launch. - return true - } - - func applicationWillResignActive(application: UIApplication) { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - } - - func applicationDidEnterBackground(application: UIApplication) { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - } - - func applicationWillEnterForeground(application: UIApplication) { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. - } - - func applicationDidBecomeActive(application: UIApplication) { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - } - - func applicationWillTerminate(application: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } - - -} - diff --git a/Example/SwiftString/Base.lproj/LaunchScreen.xib b/Example/SwiftString/Base.lproj/LaunchScreen.xib deleted file mode 100644 index f98581d..0000000 --- a/Example/SwiftString/Base.lproj/LaunchScreen.xib +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Example/SwiftString/Base.lproj/Main.storyboard b/Example/SwiftString/Base.lproj/Main.storyboard deleted file mode 100644 index 52ea29e..0000000 --- a/Example/SwiftString/Base.lproj/Main.storyboard +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Example/SwiftString/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/SwiftString/Images.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index d3942e9..0000000 --- a/Example/SwiftString/Images.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "images" : [ - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} diff --git a/Example/SwiftString/Info.plist b/Example/SwiftString/Info.plist deleted file mode 100644 index eb18faa..0000000 --- a/Example/SwiftString/Info.plist +++ /dev/null @@ -1,39 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - - - diff --git a/Example/SwiftString/ViewController.swift b/Example/SwiftString/ViewController.swift deleted file mode 100644 index c94d6a5..0000000 --- a/Example/SwiftString/ViewController.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// ViewController.swift -// SwiftString -// -// Created by Andrew Mayne on 01/31/2016. -// Copyright (c) 2016 Andrew Mayne. All rights reserved. -// - -import UIKit - -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. - } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - -} - diff --git a/Example/Tests/Info.plist b/Example/Tests/Info.plist deleted file mode 100644 index ba72822..0000000 --- a/Example/Tests/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/Example/Tests/String+HTMLTests.swift b/Example/Tests/String+HTMLTests.swift deleted file mode 100644 index a93c677..0000000 --- a/Example/Tests/String+HTMLTests.swift +++ /dev/null @@ -1,13 +0,0 @@ -import XCTest -import Hamcrest -import SwiftString - -class StringHTMLTests: XCTestCase { - - func testDecodeHTML() { - assertThat("The Weekend ‘King Of The Fall’".decodeHTML(), presentAnd(equalTo("The Weekend ‘King Of The Fall’"))) - assertThat(" 4 < 5 & 3 > 2 . Price: 12 €. @ ".decodeHTML(), presentAnd(equalTo(" 4 < 5 & 3 > 2 . Price: 12 €. @ "))) - assertThat("this is so "good"".decodeHTML(), presentAnd(equalTo("this is so \"good\""))) - } - -} diff --git a/Example/Tests/StringExtensionTests.swift b/Example/Tests/StringExtensionTests.swift deleted file mode 100644 index 2c26d19..0000000 --- a/Example/Tests/StringExtensionTests.swift +++ /dev/null @@ -1,259 +0,0 @@ -import XCTest -import Hamcrest -import SwiftString - -class SwiftStringTests: XCTestCase { - - func testBetween() { - assertThat("foo".between("", ""), presentAnd(equalTo("foo"))) - assertThat("foo".between("", ""), presentAnd(equalTo("foo"))) - assertThat("foo".between("", ""), nilValue()) - assertThat("Some strings } are very {weird}, dont you think?".between("{", "}"), presentAnd(equalTo("weird"))) - assertThat("".between("", ""), nilValue()) - assertThat("foo".between("", ""), nilValue()) - } - - func testCamelize() { - assertThat("os version".camelize() == "osVersion") - assertThat("HelloWorld".camelize() == "helloWorld") - assertThat("someword With Characters".camelize() == "somewordWithCharacters") - assertThat("data_rate".camelize() == "dataRate") - assertThat("background-color".camelize() == "backgroundColor") - } - - func testCapitalize() { - assertThat("hello world".capitalize() == "Hello World") - } - - func testChompLeft() { - assertThat("foobar".chompLeft("foo") == "bar") - assertThat("foobar".chompLeft("bar") == "foo") - } - - func testChompRight() { - assertThat("foobar".chompRight("bar") == "foo") - assertThat("foobar".chompRight("foo") == "bar") - } - - func testClean() { - assertThat("thisoneistwoathreetest".clean(with: " ", allOf: "one", "two", "three") == "this is a test") - } - - func testCollapseWhitespace() { - assertThat(" String \t libraries are \n\n\t fun\n! ".collapseWhitespace() == "String libraries are fun !") - } - - func testContains() { - assertThat("foobar".contains("foo") == true) - assertThat("foobar".contains("ba") == true) - assertThat("foobar".contains("something") == false) - } - - func testCount() { - assertThat("hi hi ho hey hihey".count("hi") == 3) - } - - func testEndsWith() { - assertThat("hello world".endsWith("world") == true) - assertThat("hello world".endsWith("foo") == false) - } - - func testEnsureLeft() { - assertThat("/subdir".ensureLeft("/") == "/subdir") - assertThat("subdir".ensureLeft("/") == "/subdir") - } - - func testEnsureRight() { - assertThat("subdir/".ensureRight("/") == "subdir/") - assertThat("subdir".ensureRight("/") == "subdir/") - } - - func testIndexOf() { - assertThat("hello".indexOf("hell"), presentAnd(equalTo(0))) - assertThat("hello".indexOf("lo"), presentAnd(equalTo(3))) - assertThat("hello".indexOf("world"), nilValue()) - } - - func testInitials() { - assertThat("First".initials() == "F") - assertThat("First Last".initials() == "FL") - assertThat("First Middle1 Middle2 Middle3 Last".initials() == "FMMML") - } - - func testInitialsFirstAndLast() { - assertThat("First Last".initialsFirstAndLast() == "FL") - assertThat("First Middle1 Middle2 Middle3 Last".initialsFirstAndLast() == "FL") - } - - func testIsAlpha() { - assertThat("fdafaf3".isAlpha() == false) - assertThat("afaf".isAlpha() == true) - assertThat("dfdf--dfd".isAlpha() == false) - } - - func testIsAlphaNumeric() { - assertThat("afaf35353afaf".isAlphaNumeric() == true) - assertThat("FFFF99fff".isAlphaNumeric() == true) - assertThat("99".isAlphaNumeric() == true) - assertThat("afff".isAlphaNumeric() == true) - assertThat("-33".isAlphaNumeric() == false) - assertThat("aaff..".isAlphaNumeric() == false) - } - - func testIsEmpty() { - assertThat("".isEmpty() == true) - assertThat(" ".isEmpty() == true) - assertThat("\t\t\t ".isEmpty() == true) - assertThat("\n\n".isEmpty() == true) - assertThat("helo".isEmpty() == false) - } - - func testIsNumeric() { - assertThat("abc".isNumeric() == false) - assertThat("123a".isNumeric() == false) - assertThat("1".isNumeric() == true) - assertThat("22".isNumeric() == true) - assertThat("33.0".isNumeric() == true) - assertThat("-63.0".isNumeric() == true) - } - - func testJoin() { - assertThat(",".join([1,2,3]) == "1,2,3") - assertThat(",".join([]) == "") - assertThat(",".join(["a","b","c"]) == "a,b,c") - assertThat("! ".join(["hey","who are you?"]) == "hey! who are you?") - } - - func testLatinize() { - assertThat("šÜįéïöç".latinize() == "sUieioc") - assertThat("crème brûlée".latinize() == "creme brulee") - } - - func testLines() { - assertThat("test".lines() == ["test"]) - assertThat("test\nsentence".lines() == ["test", "sentence"]) - assertThat("test \nsentence".lines() == ["test ", "sentence"]) - //Test Carriage return instead of just newlines - assertThat("test\rsentence".lines() == ["test", "sentence"]) - } - - func testPad() { - assertThat("hello".pad(2) == " hello ") - assertThat("hello".pad(1, "\t") == "\thello\t") - } - - func testPadLeft() { - assertThat("hello".padLeft(10) == " hello") - assertThat("what?".padLeft(2, "!") == "!!what?") - } - - func testPadRight() { - assertThat("hello".padRight(10) == "hello ") - assertThat("hello".padRight(2, "!") == "hello!!") - } - - func testStartsWith() { - assertThat("hello world".startsWith("hello") == true) - assertThat("hello world".startsWith("foo") == false) - } - - func testSplit() { - assertThat("hello world".split(" ")[0] == "hello") - assertThat("hello world".split(" ")[1] == "world") - assertThat("helloworld".split(" ")[0] == "helloworld") - } - - func testTimes() { - assertThat("hi".times(3) == "hihihi") - assertThat(" ".times(10) == " ") - } - - func testTrimmedLeft() { - assertThat(" How are you? ".trimmedLeft() == "How are you? ") - } - - func testTrimmedRight() { - assertThat(" How are you? ".trimmedRight() == " How are you?") - } - - func testTrimmed() { - assertThat(" How are you? ".trimmed() == "How are you?") - //Added per Issue #9 - https://github.com/amayne/SwiftString/issues/9 - assertThat(" ".trimmed().characters.count == 0) - assertThat(" ".trimmed().characters.count == 0) - assertThat(" ".trimmed().characters.count == 0) - } - - func testToBool() { - assertThat("asdwads".toBool(), nilValue()) - assertThat("true".toBool(), presentAnd(equalTo(true))) - assertThat("false".toBool(), presentAnd(equalTo(false))) - } - - func testToFloat() { - assertThat("asdwads".toFloat(), nilValue()) - assertThat("2.00".toFloat(), presentAnd(equalTo(2.0))) - assertThat("2".toFloat(), presentAnd(equalTo(2.0))) - } - - func testToInt() { - assertThat("asdwads".toInt(), nilValue()) - assertThat("2.00".toInt(), presentAnd(equalTo(2))) - assertThat("2".toInt(), presentAnd(equalTo(2))) - } - - func testToDate() { - assertThat("asdwads".toDate(), nilValue()) - - let calendar = NSCalendar.currentCalendar() - let components = calendar.components([.Day , .Month , .Year], fromDate: "2014-06-03".toDate()!) - - assertThat(components.year == 2014) - assertThat(components.month == 6) - assertThat(components.day == 3) - } - - func testToDateTime() { - assertThat("asdwads".toDateTime(), nilValue()) - let calendar = NSCalendar.currentCalendar() - let components = calendar.components([.Day , .Month , .Year, .Hour, .Minute, .Second], fromDate: "2014-06-03 13:15:01".toDateTime()!) - - assertThat(components.year == 2014) - assertThat(components.month == 6) - assertThat(components.day == 3) - assertThat(components.hour == 13) - assertThat(components.minute == 15) - assertThat(components.second == 1) - } - - func testToDouble() { - assertThat("asdwads".toDouble(), nilValue()) - assertThat("2.00".toDouble(), presentAnd(equalTo(2.0))) - assertThat("2".toDouble(), presentAnd(equalTo(2.0))) - } - - func testSlugify() { - assertThat("Global Thermonuclear Warfare".slugify() == "global-thermonuclear-warfare") - assertThat("Global Thermonuclear Warfare".slugify(withSeparator: "_") == "global_thermonuclear_warfare") - assertThat("Crème brûlée".slugify() == "creme-brulee") - } - - func testStripPunctuation() { - assertThat("My, st[ring] *full* of %punct)".stripPunctuation() == "My string full of punct") - } - - func testSubstring() { - let subject = "hello world" - assertThat(subject.substring(0, length: 1) == "h") - assertThat(subject.substring(0, length: 11) == "hello world") - } - - func testSubscripts() { - let subject = "hello world" - assertThat(subject[0...1] == "he") - assertThat(subject[0..<1] == "h") - assertThat(subject[0] == "h") - assertThat(subject[0...10] == "hello world") - } - -} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..d89cc77 --- /dev/null +++ b/Package.swift @@ -0,0 +1,9 @@ +// Generated automatically by Perfect Assistant Application +// Date: 2016-09-17 01:35:49 +0000 +import PackageDescription +let package = Package( + name: "SwiftString", + targets: [], + dependencies: [], + exclude: [] +) diff --git a/Pod/Assets/.gitkeep b/Pod/Assets/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Pod/Classes/.gitkeep b/Pod/Classes/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Pod/Classes/StringExtensions.swift b/Pod/Classes/StringExtensions.swift deleted file mode 100644 index 218d426..0000000 --- a/Pod/Classes/StringExtensions.swift +++ /dev/null @@ -1,337 +0,0 @@ -// -// SwiftString.swift -// SwiftString -// -// Created by Andrew Mayne on 30/01/2016. -// Copyright © 2016 Red Brick Labs. All rights reserved. -// - -public extension String { - - /// Finds the string between two bookend strings if it can be found. - /// - /// - parameter left: The left bookend - /// - parameter right: The right bookend - /// - /// - returns: The string between the two bookends, or nil if the bookends cannot be found, the bookends are the same or appear contiguously. - func between(left: String, _ right: String) -> String? { - guard - let leftRange = rangeOfString(left), rightRange = rangeOfString(right, options: .BackwardsSearch) - where left != right && leftRange.endIndex != rightRange.startIndex - else { return nil } - - return self[leftRange.endIndex...rightRange.startIndex.predecessor()] - - } - - // https://gist.github.com/stevenschobert/540dd33e828461916c11 - func camelize() -> String { - let source = clean(with: " ", allOf: "-", "_") - if source.characters.contains(" ") { - let first = source.substringToIndex(source.startIndex.advancedBy(1)) - let cammel = NSString(format: "%@", (source as NSString).capitalizedString.stringByReplacingOccurrencesOfString(" ", withString: "", options: [], range: nil)) as String - let rest = String(cammel.characters.dropFirst()) - return "\(first)\(rest)" - } else { - let first = (source as NSString).lowercaseString.substringToIndex(source.startIndex.advancedBy(1)) - let rest = String(source.characters.dropFirst()) - return "\(first)\(rest)" - } - } - - func capitalize() -> String { - return capitalizedString - } - - func contains(substring: String) -> Bool { - return rangeOfString(substring) != nil - } - - func chompLeft(prefix: String) -> String { - if let prefixRange = rangeOfString(prefix) { - if prefixRange.endIndex >= endIndex { - return self[startIndex.. String { - if let suffixRange = rangeOfString(suffix, options: .BackwardsSearch) { - if suffixRange.endIndex >= endIndex { - return self[startIndex.. String { - let components = componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).filter { !$0.isEmpty } - return components.joinWithSeparator(" ") - } - - func clean(with with: String, allOf: String...) -> String { - var string = self - for target in allOf { - string = string.stringByReplacingOccurrencesOfString(target, withString: with) - } - return string - } - - func count(substring: String) -> Int { - return componentsSeparatedByString(substring).count-1 - } - - func endsWith(suffix: String) -> Bool { - return hasSuffix(suffix) - } - - func ensureLeft(prefix: String) -> String { - if startsWith(prefix) { - return self - } else { - return "\(prefix)\(self)" - } - } - - func ensureRight(suffix: String) -> String { - if endsWith(suffix) { - return self - } else { - return "\(self)\(suffix)" - } - } - - func indexOf(substring: String) -> Int? { - if let range = rangeOfString(substring) { - return startIndex.distanceTo(range.startIndex) - } - return nil - } - - func initials() -> String { - let words = self.componentsSeparatedByString(" ") - return words.reduce(""){$0 + $1[0...0]} - } - - func initialsFirstAndLast() -> String { - let words = self.componentsSeparatedByString(" ") - return words.reduce("") { ($0 == "" ? "" : $0[0...0]) + $1[0...0]} - } - - func isAlpha() -> Bool { - for chr in characters { - if (!(chr >= "a" && chr <= "z") && !(chr >= "A" && chr <= "Z") ) { - return false - } - } - return true - } - - func isAlphaNumeric() -> Bool { - let alphaNumeric = NSCharacterSet.alphanumericCharacterSet() - return componentsSeparatedByCharactersInSet(alphaNumeric).joinWithSeparator("").length == 0 - } - - func isEmpty() -> Bool { - return self.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).length == 0 - } - - func isNumeric() -> Bool { - if let _ = defaultNumberFormatter().numberFromString(self) { - return true - } - return false - } - - func join(elements: S) -> String { - return elements.map{String($0)}.joinWithSeparator(self) - } - - func latinize() -> String { - return self.stringByFoldingWithOptions(.DiacriticInsensitiveSearch, locale: NSLocale.currentLocale()) - } - - func lines() -> [String] { - return self.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet()) - } - - var length: Int { - get { - return self.characters.count - } - } - - func pad(n: Int, _ string: String = " ") -> String { - return "".join([string.times(n), self, string.times(n)]) - } - - func padLeft(n: Int, _ string: String = " ") -> String { - return "".join([string.times(n), self]) - } - - func padRight(n: Int, _ string: String = " ") -> String { - return "".join([self, string.times(n)]) - } - - func slugify(withSeparator separator: Character = "-") -> String { - let slugCharacterSet = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\(separator)") - return latinize() - .lowercaseString - .componentsSeparatedByCharactersInSet(slugCharacterSet.invertedSet) - .filter { $0 != "" } - .joinWithSeparator(String(separator)) - } - - func split(separator: Character) -> [String] { - return characters.split{$0 == separator}.map(String.init) - } - - func startsWith(prefix: String) -> Bool { - return hasPrefix(prefix) - } - - func stripPunctuation() -> String { - return componentsSeparatedByCharactersInSet(.punctuationCharacterSet()) - .joinWithSeparator("") - .componentsSeparatedByString(" ") - .filter { $0 != "" } - .joinWithSeparator(" ") - } - - func times(n: Int) -> String { - return (0.. Float? { - if let number = defaultNumberFormatter().numberFromString(self) { - return number.floatValue - } - return nil - } - - func toInt() -> Int? { - if let number = defaultNumberFormatter().numberFromString(self) { - return number.integerValue - } - return nil - } - - func toDouble(locale: NSLocale = NSLocale.systemLocale()) -> Double? { - let nf = localeNumberFormatter(locale) - - if let number = nf.numberFromString(self) { - return number.doubleValue - } - return nil - } - - func toBool() -> Bool? { - let trimmed = self.trimmed().lowercaseString - if trimmed == "true" || trimmed == "false" { - return (trimmed as NSString).boolValue - } - return nil - } - - func toDate(format: String = "yyyy-MM-dd") -> NSDate? { - return dateFormatter(format).dateFromString(self) - } - - func toDateTime(format: String = "yyyy-MM-dd HH:mm:ss") -> NSDate? { - return toDate(format) - } - - func trimmedLeft() -> String { - if let range = rangeOfCharacterFromSet(NSCharacterSet.whitespaceAndNewlineCharacterSet().invertedSet) { - return self[range.startIndex.. String { - if let range = rangeOfCharacterFromSet(NSCharacterSet.whitespaceAndNewlineCharacterSet().invertedSet, options: NSStringCompareOptions.BackwardsSearch) { - return self[startIndex.. String { - return self.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) - } - - subscript(r: Range) -> String { - get { - let startIndex = self.startIndex.advancedBy(r.startIndex) - let endIndex = self.startIndex.advancedBy(r.endIndex - r.startIndex) - return self[startIndex.. String { - let start = self.startIndex.advancedBy(startIndex) - let end = self.startIndex.advancedBy(startIndex + length) - return self[start.. Character { - get { - let index = self.startIndex.advancedBy(i) - return self[index] - } - } -} - -private enum ThreadLocalIdentifier { - case DateFormatter(String) - - case DefaultNumberFormatter - case LocaleNumberFormatter(NSLocale) - - var objcDictKey: String { - switch self { - case .DateFormatter(let format): - return "SS\(self)\(format)" - case .LocaleNumberFormatter(let l): - return "SS\(self)\(l.localeIdentifier)" - default: - return "SS\(self)" - } - } -} - -private func threadLocalInstance(identifier: ThreadLocalIdentifier, @autoclosure initialValue: () -> T) -> T { - let storage = NSThread.currentThread().threadDictionary - let k = identifier.objcDictKey - - let instance: T = storage[k] as? T ?? initialValue() - if storage[k] == nil { - storage[k] = instance - } - - return instance -} - -private func dateFormatter(format: String) -> NSDateFormatter { - return threadLocalInstance(.DateFormatter(format), initialValue: { - let df = NSDateFormatter() - df.dateFormat = format - return df - }()) -} - -private func defaultNumberFormatter() -> NSNumberFormatter { - return threadLocalInstance(.DefaultNumberFormatter, initialValue: NSNumberFormatter()) -} - -private func localeNumberFormatter(locale: NSLocale) -> NSNumberFormatter { - return threadLocalInstance(.LocaleNumberFormatter(locale), initialValue: { - let nf = NSNumberFormatter() - nf.locale = locale - return nf - }()) -} diff --git a/README.md b/README.md index 61981d4..f4d2e00 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,20 @@ # SwiftString -[![CI Status](http://img.shields.io/travis/amayne/SwiftString.svg?style=flat)](https://travis-ci.org/amayne/SwiftString) -[![Version](https://img.shields.io/cocoapods/v/SwiftString.svg?style=flat)](http://cocoapods.org/pods/SwiftString) -[![License](https://img.shields.io/cocoapods/l/SwiftString.svg?style=flat)](http://cocoapods.org/pods/SwiftString) -[![Platform](https://img.shields.io/cocoapods/p/SwiftString.svg?style=flat)](http://cocoapods.org/pods/SwiftString) -[![Swift-2.1](http://img.shields.io/badge/Swift-2.1-blue.svg)]() - -SwiftString is a lightweight string extension for Swift. +SwiftString is a lightweight string extension for Swift 3. This library was motivated by having to search StackOverflow for common string operations, and wanting them to be in one place with test coverage. -## Installation +Note the original client side Swift 2 repo can be found here: +[https://github.com/amayne/SwiftString](https://github.com/amayne/SwiftString) -SwiftString is available through [CocoaPods](http://cocoapods.org). To install -it, simply add the following line to your Podfile: -```ruby -pod "SwiftString" -``` +## This Fork + +This fork is intended as a server side utility. + +* It is Swift 3.0 and Swift Package Manager (SPM) ready. +* Added sigificant test coverage + ## Usage @@ -28,7 +25,8 @@ import SwiftString ## Methods **between(left, right)** -```swift + +``` swift "foo".between("", "") // "foo" "foo".between("", "") // "foo" "foo".between("", "") // nil @@ -38,6 +36,7 @@ import SwiftString ``` **camelize()** + ```swift "os version".camelize() // "osVersion" "HelloWorld".camelize() // "helloWorld" @@ -48,40 +47,39 @@ import SwiftString **capitalize()** + ```swift "hello world".capitalize() // "Hello World" ``` **chompLeft(string)** + ```swift "foobar".chompLeft("foo") // "bar" "foobar".chompLeft("bar") // "foo" ``` **chompRight(string)** + ```swift "foobar".chompRight("bar") // "foo" "foobar".chompRight("foo") // "bar" ``` **collapseWhitespace()** -```swift -" String \t libraries are \n\n\t fun\n! ".collapseWhitespace() // "String libraries are fun !") -``` -**contains(substring)** ```swift -"foobar".contains("foo") // true -"foobar".contains("bar") // true -"foobar".contains("something") // false +" String \t libraries are \n\n\t fun\n! ".collapseWhitespace() // "String libraries are fun !") ``` **count(string)** + ```swift "hi hi ho hey hihey".count("hi") // 3 ``` **decodeHTML()** + ```swift "The Weekend ‘King Of The Fall’".decodeHTML() // "The Weekend ‘King Of The Fall’" " 4 < 5 & 3 > 2 . Price: 12 €. @ ".decodeHTML() // " 4 < 5 & 3 > 2 . Price: 12 €. @ " @@ -89,24 +87,28 @@ import SwiftString ``` **endsWith(suffix)** + ```swift "hello world".endsWith("world") // true "hello world".endsWith("foo") // false ``` **ensureLeft(prefix)** + ```swift "/subdir".ensureLeft("/") // "/subdir" "subdir".ensureLeft("/") // "/subdir" ``` **ensureRight(suffix)** + ```swift "subdir/".ensureRight("/") // "subdir/" "subdir".ensureRight("/") // "subdir/" ``` **indexOf(substring)** + ```swift "hello".indexOf("hell"), // 0 "hello".indexOf("lo"), // 3 @@ -114,6 +116,7 @@ import SwiftString ``` **initials()** + ```swift "First".initials(), // "F" "First Last".initials(), // "FL" @@ -121,12 +124,14 @@ import SwiftString ``` **initialsFirstAndLast()** + ```swift "First Last".initialsFirstAndLast(), // "FL" "First Middle1 Middle2 Middle3 Last".initialsFirstAndLast() // "FL" ``` **isAlpha()** + ```swift "fdafaf3".isAlpha() // false "afaf".isAlpha() // true @@ -134,6 +139,7 @@ import SwiftString ``` **isAlphaNumeric()** + ```swift "afaf35353afaf".isAlphaNumeric() // true "FFFF99fff".isAlphaNumeric() // true @@ -144,6 +150,7 @@ import SwiftString ``` **isEmpty()** + ```swift " ".isEmpty() // true "\t\t\t ".isEmpty() // true @@ -152,6 +159,7 @@ import SwiftString ``` **isNumeric()** + ```swift "abc".isNumeric() // false "123a".isNumeric() // false @@ -161,21 +169,15 @@ import SwiftString "-63.0".isNumeric() // true ``` -**join(sequence)** -```swift -",".join([1,2,3]) // "1,2,3" -",".join([]) // "" -",".join(["a","b","c"]) // "a,b,c" -"! ".join(["hey","who are you?"]) // "hey! who are you?" -``` - **latinize()** + ```swift "šÜįéïöç".latinize() // "sUieioc" "crème brûlée".latinize() // "creme brulee" ``` **lines()** + ```swift "test".lines() // ["test"] "test\nsentence".lines() // ["test", "sentence"] @@ -183,30 +185,35 @@ import SwiftString ``` **pad(n, string)** + ```swift "hello".pad(2) // " hello " "hello".pad(1, "\t") // "\thello\t" ``` **padLeft(n, string)** + ```swift "hello".padLeft(10) // " hello" "what?".padLeft(2, "!") // "!!what?" ``` **padRight(n, string)** + ```swift "hello".padRight(10) // "hello " "hello".padRight(2, "!") // "hello!!" ``` **startsWith(prefix)** + ```swift "hello world".startsWith("hello") // true "hello world".startsWith("foo") // false ``` **split(separator)** + ```swift "hello world".split(" ")[0] // "hello" "hello world".split(" ")[1] // "world" @@ -214,12 +221,14 @@ import SwiftString ``` **times(n)** + ```swift "hi".times(3) // "hihihi" " ".times(10) // " " ``` **toBool()** + ```swift "asdwads".toBool() // nil "true".toBool() // true @@ -227,6 +236,7 @@ import SwiftString ``` **toFloat()** + ```swift "asdwads".toFloat() // nil "2.00".toFloat() // 2.0 @@ -234,6 +244,7 @@ import SwiftString ``` **toInt()** + ```swift "asdwads".toInt() // nil "2.00".toInt() // 2 @@ -241,18 +252,21 @@ import SwiftString ``` **toDate()** + ```swift "asdwads".toDate() // nil "2014-06-03".toDate() // NSDate ``` **toDateTime()** + ```swift "asdwads".toDateTime() // nil "2014-06-03 13:15:01".toDateTime() // NSDate ``` **toDouble()** + ```swift "asdwads".toDouble() // nil "2.00".toDouble() // 2.0 @@ -260,38 +274,45 @@ import SwiftString ``` **trimmedLeft()** + ```swift " How are you? ".trimmedLeft() // "How are you? " ``` **trimmedRight()** + ```swift " How are you? ".trimmedRight() // " How are you?" ``` **trimmed()** + ```swift " How are you? ".trimmed() // "How are you?" ``` **slugify()** + ```swift "Global Thermonuclear Warfare".slugify() // "global-thermonuclear-warfare" "Crème brûlée".slugify() // "creme-brulee" ``` **stripPunctuation()** + ```swift "My, st[ring] *full* of %punct)".stripPunctuation() // "My string full of punct" ``` **substring(startIndex, length)** + ```swift "hello world".substring(0, length: 1) // "h" "hello world".substring(0, length: 11) // "hello world" ``` **[subscript]** + ```swift "hello world"[0...1] // "he" "hello world"[0..<1] // "h" @@ -299,10 +320,36 @@ import SwiftString "hello world"[0...10] // "hello world" ``` +## Requirements + +- Swift version 3.0 + +## Installation + +### Install via Swift Package Manager + +* Add the following to your `Package.swift` file: + +``` swift +.Package( + url: "https://github.com/iamjono/SwiftString.git", + majorVersion: 1, minor: 0 + ), +``` + +Then, regenerate your Xcode project: + +``` +swift package generate-xcodeproj +``` + + ## Author Andrew Mayne, andrew@redbricklab.com +Swift 3 SPM module, Jonathan Guthrie, jono@guthrie.net.nz + ## License SwiftString is available under the MIT license. See the LICENSE file for more info. diff --git a/Sources/StringExtensions.swift b/Sources/StringExtensions.swift new file mode 100644 index 0000000..a4bc400 --- /dev/null +++ b/Sources/StringExtensions.swift @@ -0,0 +1,377 @@ +// +// SwiftString.swift +// SwiftString +// +// Created by Andrew Mayne on 30/01/2016. +// Copyright © 2016 Red Brick Labs. All rights reserved. +// +import Foundation + +public extension String { + + /// Finds the string between two bookend strings if it can be found. + /// + /// - parameter left: The left bookend + /// - parameter right: The right bookend + /// + /// - returns: The string between the two bookends, or nil if the bookends cannot be found, the bookends are the same or appear contiguously. + func between(_ left: String, _ right: String) -> String? { + guard + let leftRange = range(of:left), let rightRange = range(of: right, options: .backwards), + left != right && leftRange.upperBound != rightRange.lowerBound + else { return nil } + + return self[leftRange.upperBound...index(before: rightRange.lowerBound)] + + } + + // https://gist.github.com/stevenschobert/540dd33e828461916c11 + func camelize() -> String { + let source = clean(with: " ", allOf: "-", "_") + if source.characters.contains(" ") { + let first = self[self.startIndex...self.index(after: startIndex)] //source.substringToIndex(source.index(after: startIndex)) + let cammel = source.capitalized.replacingOccurrences(of: " ", with: "") +// let cammel = String(format: "%@", strip) + let rest = String(cammel.characters.dropFirst()) + return "\(first)\(rest)" + } else { + let first = source[self.startIndex...self.index(after: startIndex)].lowercased() + let rest = String(source.characters.dropFirst()) + return "\(first)\(rest)" + } + } + + func capitalize() -> String { + return capitalized + } + +// func contains(_ substring: String) -> Bool { +// return range(of: substring) != nil +// } + + func chompLeft(_ prefix: String) -> String { + if let prefixRange = range(of: prefix) { + if prefixRange.upperBound >= endIndex { + return self[startIndex.. String { + if let suffixRange = range(of: suffix, options: .backwards) { + if suffixRange.upperBound >= endIndex { + return self[startIndex.. String { + let thecomponents = components(separatedBy: NSCharacterSet.whitespacesAndNewlines).filter { !$0.isEmpty } + return thecomponents.joined(separator: " ") + } + + func clean(with: String, allOf: String...) -> String { + var string = self + for target in allOf { + string = string.replacingOccurrences(of: target, with: with) + } + return string + } + + func count(_ substring: String) -> Int { + return components(separatedBy: substring).count-1 + } + + func endsWith(_ suffix: String) -> Bool { + return hasSuffix(suffix) + } + + func ensureLeft(_ prefix: String) -> String { + if startsWith(prefix) { + return self + } else { + return "\(prefix)\(self)" + } + } + + func ensureRight(_ suffix: String) -> String { + if endsWith(suffix) { + return self + } else { + return "\(self)\(suffix)" + } + } + + func indexOf(_ substring: String) -> Int? { + if let range = range(of: substring) { + return self.distance(from: startIndex, to: range.lowerBound) +// return startIndex.distanceTo(range.lowerBound) + } + return nil + } + + func initials() -> String { + let words = self.components(separatedBy: " ") + return words.reduce(""){$0 + $1[startIndex...startIndex]} +// return words.reduce(""){$0 + $1[0...0]} + } + + func initialsFirstAndLast() -> String { + let words = self.components(separatedBy: " ") + return words.reduce("") { ($0 == "" ? "" : $0[startIndex...startIndex]) + $1[startIndex...startIndex]} + } + + func isAlpha() -> Bool { + for chr in characters { + if (!(chr >= "a" && chr <= "z") && !(chr >= "A" && chr <= "Z") ) { + return false + } + } + return true + } + + func isAlphaNumeric() -> Bool { + let alphaNumeric = NSCharacterSet.alphanumerics + let output = self.unicodeScalars.split { !alphaNumeric.contains($0)}.map(String.init) + if output.count == 1 { + if output[0] != self { + return false + } + } + return output.count == 1 +// return componentsSeparatedByCharactersInSet(alphaNumeric).joinWithSeparator("").length == 0 + } + + func isEmpty() -> Bool { + return self.trimmingCharacters(in: .whitespacesAndNewlines).length == 0 + } + + func isNumeric() -> Bool { + if let _ = defaultNumberFormatter().number(from: self) { + return true + } + return false + } + + private func join(_ elements: S) -> String { + return elements.map{String(describing: $0)}.joined(separator: self) + } + + func latinize() -> String { + return self.folding(options: .diacriticInsensitive, locale: .current) +// stringByFoldingWithOptions(.DiacriticInsensitiveSearch, locale: NSLocale.currentLocale()) + } + + func lines() -> [String] { + return self.components(separatedBy: NSCharacterSet.newlines) + } + + var length: Int { + get { + return self.characters.count + } + } + + func pad(_ n: Int, _ string: String = " ") -> String { + return "".join([string.times(n), self, string.times(n)]) + } + + func padLeft(_ n: Int, _ string: String = " ") -> String { + return "".join([string.times(n), self]) + } + + func padRight(_ n: Int, _ string: String = " ") -> String { + return "".join([self, string.times(n)]) + } + + func slugify(withSeparator separator: Character = "-") -> String { + let slugCharacterSet = NSCharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\(separator)") + return latinize() + .lowercased() + .components(separatedBy: slugCharacterSet.inverted) + .filter { $0 != "" } + .joined(separator: String(separator)) + } + + /// split the string into a string array by white spaces + func tokenize() -> [String] { + return self.components(separatedBy: .whitespaces) + } + + func split(_ separator: Character = " ") -> [String] { + return characters.split{$0 == separator}.map(String.init) + } + + func startsWith(_ prefix: String) -> Bool { + return hasPrefix(prefix) + } + + func stripPunctuation() -> String { + return components(separatedBy: .punctuationCharacters) + .joined(separator: "") + .components(separatedBy: " ") + .filter { $0 != "" } + .joined(separator: " ") + } + + func times(_ n: Int) -> String { + return (0.. Float? { + if let number = defaultNumberFormatter().number(from: self) { + return number.floatValue + } + return nil + } + + func toInt() -> Int? { + if let number = defaultNumberFormatter().number(from: self) { + return number.intValue + } + return nil + } + + func toBool() -> Bool? { + let trimmed = self.trimmed().lowercased() + if Int(trimmed) != 0 { + return true + } + switch trimmed { + case "true", "yes", "1": + return true + case "false", "no", "0": + return false + default: + return false + } + } + + func toDate(_ format: String = "yyyy-MM-dd") -> Date? { + return dateFormatter(format).date(from: self) as Date? + } + + func toDateTime(_ format: String = "yyyy-MM-dd HH:mm:ss") -> Date? { + return toDate(format) + } + + func trimmedLeft() -> String { + if let range = rangeOfCharacter(from: NSCharacterSet.whitespacesAndNewlines.inverted) { + return self[range.lowerBound.. String { + if let range = rangeOfCharacter(from: NSCharacterSet.whitespacesAndNewlines.inverted, options: NSString.CompareOptions.backwards) { + return self[startIndex.. String { + return self.trimmingCharacters(in: .whitespacesAndNewlines) + } + + subscript(r: Range) -> String { + get { + let startIndex = self.characters.index(self.startIndex, offsetBy: r.lowerBound) + let endIndex = self.characters.index(self.startIndex, offsetBy: r.upperBound - r.lowerBound) + return self[startIndex.. String { + let start = self.characters.index(self.startIndex, offsetBy: startIndex) + let end = self.characters.index(self.startIndex, offsetBy: startIndex + length) + return self[start.. Character { + get { + let index = self.characters.index(self.startIndex, offsetBy: i) + return self[index] + } + } + +// /// get the left part of the string before the index +// func left(_ range:Range?) -> String { +// return self.substring(to: (range?.lowerBound)!) +// } +// /// get the right part of the string after the index +// func right(_ range:Range?) -> String { +// return self.substring(from: self.index((range?.lowerBound)!, offsetBy:1)) +// } + +} + +private enum ThreadLocalIdentifier { + case dateFormatter(String) + + case defaultNumberFormatter + case localeNumberFormatter(Locale) + + var objcDictKey: String { + switch self { + case .dateFormatter(let format): + return "SS\(self)\(format)" + case .localeNumberFormatter(let l): + return "SS\(self)\(l.identifier)" + default: + return "SS\(self)" + } + } +} + +private func threadLocalInstance(_ identifier: ThreadLocalIdentifier, initialValue: @autoclosure () -> T) -> T { + #if os(Linux) + var storage = Thread.current.threadDictionary + #else + let storage = Thread.current.threadDictionary + #endif + let k = identifier.objcDictKey + + let instance: T = storage[k] as? T ?? initialValue() + if storage[k] == nil { + storage[k] = instance + } + + return instance +} + +private func dateFormatter(_ format: String) -> DateFormatter { + return threadLocalInstance(.dateFormatter(format), initialValue: { + let df = DateFormatter() + df.dateFormat = format + return df + }()) +} + +private func defaultNumberFormatter() -> NumberFormatter { + return threadLocalInstance(.defaultNumberFormatter, initialValue: NumberFormatter()) +} + +private func localeNumberFormatter(_ locale: Locale) -> NumberFormatter { + return threadLocalInstance(.localeNumberFormatter(locale), initialValue: { + let nf = NumberFormatter() + nf.locale = locale + return nf + }()) +} + +public extension String { + func isValidEmail() -> Bool { + #if os(Linux) + let regex = try? RegularExpression(pattern: "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$", options: .caseInsensitive) + #else + let regex = try? NSRegularExpression(pattern: "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$", options: .caseInsensitive) + #endif + return regex?.firstMatch(in: self, options: [], range: NSMakeRange(0, self.characters.count)) != nil + } +} diff --git a/Pod/Classes/String+HTML.swift b/Sources/StringHTML.swift similarity index 92% rename from Pod/Classes/String+HTML.swift rename to Sources/StringHTML.swift index 1895b55..cef0ac4 100644 --- a/Pod/Classes/String+HTML.swift +++ b/Sources/StringHTML.swift @@ -1,8 +1,10 @@ // adapted from https://gist.github.com/mwaterfall/25b4a6a06dc3309d9555 +import Foundation + public extension String { - private struct HTMLEntities { + fileprivate struct HTMLEntities { static let characterEntities : [String: Character] = [ // XML predefined entities: @@ -268,9 +270,9 @@ public extension String { // Unicode character, e.g. // decodeNumeric("64", 10) --> "@" // decodeNumeric("20ac", 16) --> "€" - private func decodeNumeric(string : String, base : Int32) -> Character? { + fileprivate func decodeNumeric(_ string : String, base : Int32) -> Character? { let code = UInt32(strtoul(string, nil, base)) - return Character(UnicodeScalar(code)) + return Character(UnicodeScalar(code)!) } // Decode the HTML character entity to the corresponding @@ -279,11 +281,11 @@ public extension String { // decode("€") --> "€" // decode("<") --> "<" // decode("&foo;") --> nil - private func decode(entity : String) -> Character? { + fileprivate func decode(_ entity : String) -> Character? { if entity.hasPrefix("&#x") || entity.hasPrefix("&#X"){ - return decodeNumeric(entity.substringFromIndex(entity.startIndex.advancedBy(3)), base: 16) + return decodeNumeric(entity.substring(from: entity.index(entity.startIndex, offsetBy: 3)), base: 16) } else if entity.hasPrefix("&#") { - return decodeNumeric(entity.substringFromIndex(entity.startIndex.advancedBy(2)), base: 10) + return decodeNumeric(entity.substring(from: entity.index(entity.startIndex, offsetBy: 2)), base: 10) } else { return HTMLEntities.characterEntities[entity] } @@ -298,21 +300,21 @@ public extension String { var position = startIndex // Find the next '&' and copy the characters preceding it to `result`: - while let ampRange = self.rangeOfString("&", range: position ..< endIndex) { - result.appendContentsOf(self[position ..< ampRange.startIndex]) - position = ampRange.startIndex + while let ampRange = self.range(of: "&", range: position ..< endIndex) { + result.append(self[position ..< ampRange.lowerBound]) + position = ampRange.lowerBound // Find the next ';' and copy everything from '&' to ';' into `entity` - if let semiRange = self.rangeOfString(";", range: position ..< endIndex) { - let entity = self[position ..< semiRange.endIndex] - position = semiRange.endIndex + if let semiRange = self.range(of: ";", range: position ..< endIndex) { + let entity = self[position ..< semiRange.upperBound] + position = semiRange.upperBound if let decoded = decode(entity) { // Replace by decoded character: result.append(decoded) } else { // Invalid entity, copy verbatim: - result.appendContentsOf(entity) + result.append(entity) } } else { // No matching ';'. @@ -320,7 +322,7 @@ public extension String { } } // Copy remaining characters to `result`: - result.appendContentsOf(self[position ..< endIndex]) + result.append(self[position ..< endIndex]) return result } -} \ No newline at end of file +} diff --git a/SwiftString.podspec b/SwiftString.podspec index 789a96d..e4a6d9d 100644 --- a/SwiftString.podspec +++ b/SwiftString.podspec @@ -1,20 +1,19 @@ Pod::Spec.new do |s| s.name = "SwiftString" - s.version = "0.5.1" - s.summary = "A lightweight string extension for Swift" + s.version = "1.0.9" + s.summary = "A comprehensive, lightweight string extension for Swift 3" s.description = <<-DESC Common methods and String operations for Swift DESC - s.homepage = "https://github.com/amayne/SwiftString" + s.homepage = "https://github.com/iamjono/SwiftString" s.license = 'MIT' s.author = { "Andrew Mayne" => "andrew@redbricklab.com" } - s.source = { :git => "https://github.com/amayne/SwiftString.git", :tag => s.version.to_s } - s.social_media_url = 'https://twitter.com/amayne' + s.source = { :git => "https://github.com/iamjono/SwiftString.git", :tag => s.version.to_s } s.platform = :ios, '8.0' s.requires_arc = true - s.source_files = 'Pod/Classes/**/*' + s.source_files = 'Sources/*' end diff --git a/SwiftString.xcodeproj/Configs/Debug.xcconfig b/SwiftString.xcodeproj/Configs/Debug.xcconfig new file mode 100644 index 0000000..8b48456 --- /dev/null +++ b/SwiftString.xcodeproj/Configs/Debug.xcconfig @@ -0,0 +1,7 @@ +#include "Project.xcconfig" +COPY_PHASE_STRIP = NO +DEBUG_INFORMATION_FORMAT = dwarf +ENABLE_NS_ASSERTIONS = YES +GCC_OPTIMIZATION_LEVEL = 0 +ONLY_ACTIVE_ARCH = YES +SWIFT_OPTIMIZATION_LEVEL = -Onone diff --git a/SwiftString.xcodeproj/Configs/Project.xcconfig b/SwiftString.xcodeproj/Configs/Project.xcconfig new file mode 100644 index 0000000..5f63024 --- /dev/null +++ b/SwiftString.xcodeproj/Configs/Project.xcconfig @@ -0,0 +1,7 @@ +PRODUCT_NAME = $(TARGET_NAME) +SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator +MACOSX_DEPLOYMENT_TARGET = 10.10 +DYLIB_INSTALL_NAME_BASE = @rpath +OTHER_SWIFT_FLAGS = -DXcode +COMBINE_HIDPI_IMAGES = YES +USE_HEADERMAP = NO diff --git a/SwiftString.xcodeproj/Configs/Release.xcconfig b/SwiftString.xcodeproj/Configs/Release.xcconfig new file mode 100644 index 0000000..93f7c3d --- /dev/null +++ b/SwiftString.xcodeproj/Configs/Release.xcconfig @@ -0,0 +1,5 @@ +#include "Project.xcconfig" +DEBUG_INFORMATION_FORMAT = dwarf-with-dsym +GCC_OPTIMIZATION_LEVEL = s +SWIFT_OPTIMIZATION_LEVEL = -O +COPY_PHASE_STRIP = YES diff --git a/SwiftString.xcodeproj/SwiftStringTests_Info.plist b/SwiftString.xcodeproj/SwiftStringTests_Info.plist new file mode 100644 index 0000000..7c23420 --- /dev/null +++ b/SwiftString.xcodeproj/SwiftStringTests_Info.plist @@ -0,0 +1,25 @@ + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/SwiftString.xcodeproj/SwiftString_Info.plist b/SwiftString.xcodeproj/SwiftString_Info.plist new file mode 100644 index 0000000..57ada9f --- /dev/null +++ b/SwiftString.xcodeproj/SwiftString_Info.plist @@ -0,0 +1,25 @@ + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/SwiftString.xcodeproj/project.pbxproj b/SwiftString.xcodeproj/project.pbxproj new file mode 100644 index 0000000..c46d183 --- /dev/null +++ b/SwiftString.xcodeproj/project.pbxproj @@ -0,0 +1,340 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + _LinkFileRef_SwiftString_via_SwiftStringTests /* SwiftString.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "_____Product_SwiftString" /* SwiftString.framework */; }; + "__src_cc_ref_Sources/String+HTML.swift" /* StringHTML.swift in Sources */ = {isa = PBXBuildFile; fileRef = "__PBXFileRef_Sources/String+HTML.swift" /* StringHTML.swift */; }; + __src_cc_ref_Sources/StringExtensions.swift /* StringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/StringExtensions.swift /* StringExtensions.swift */; }; + __src_cc_ref_Tests/SwiftStringTests/SwiftStringTests.swift /* SwiftStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Tests/SwiftStringTests/SwiftStringTests.swift /* SwiftStringTests.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + E0AD59D81D91B4DD00DC93F0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = __RootObject_ /* Project object */; + proxyType = 1; + remoteGlobalIDString = "______Target_SwiftString"; + remoteInfo = SwiftString; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + __PBXFileRef_Package.swift /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; + "__PBXFileRef_Sources/String+HTML.swift" /* StringHTML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = StringHTML.swift; path = Sources/StringHTML.swift; sourceTree = ""; }; + __PBXFileRef_Sources/StringExtensions.swift /* StringExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = StringExtensions.swift; path = Sources/StringExtensions.swift; sourceTree = ""; }; + __PBXFileRef_SwiftString.xcodeproj/Configs/Debug.xcconfig /* SwiftString.xcodeproj/Configs/Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = SwiftString.xcodeproj/Configs/Debug.xcconfig; sourceTree = ""; }; + __PBXFileRef_SwiftString.xcodeproj/Configs/Project.xcconfig /* SwiftString.xcodeproj/Configs/Project.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = SwiftString.xcodeproj/Configs/Project.xcconfig; sourceTree = ""; }; + __PBXFileRef_SwiftString.xcodeproj/Configs/Release.xcconfig /* SwiftString.xcodeproj/Configs/Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = SwiftString.xcodeproj/Configs/Release.xcconfig; sourceTree = ""; }; + __PBXFileRef_Tests/SwiftStringTests/SwiftStringTests.swift /* SwiftStringTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SwiftStringTests.swift; path = Tests/SwiftStringTests/SwiftStringTests.swift; sourceTree = ""; }; + "_____Product_SwiftString" /* SwiftString.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftString.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + "_____Product_SwiftStringTests" /* SwiftStringTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = SwiftStringTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + "___LinkPhase_SwiftString" /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + "___LinkPhase_SwiftStringTests" /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 0; + files = ( + _LinkFileRef_SwiftString_via_SwiftStringTests /* SwiftString.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + TestProducts_ /* Tests */ = { + isa = PBXGroup; + children = ( + "_____Product_SwiftStringTests" /* SwiftStringTests.xctest */, + ); + name = Tests; + sourceTree = ""; + }; + "___RootGroup_" = { + isa = PBXGroup; + children = ( + __PBXFileRef_Package.swift /* Package.swift */, + "_____Configs_" /* Configs */, + "_____Sources_" /* Sources */, + "_______Tests_" /* Tests */, + "____Products_" /* Products */, + ); + sourceTree = ""; + }; + "____Products_" /* Products */ = { + isa = PBXGroup; + children = ( + TestProducts_ /* Tests */, + "_____Product_SwiftString" /* SwiftString.framework */, + ); + name = Products; + sourceTree = ""; + }; + "_____Configs_" /* Configs */ = { + isa = PBXGroup; + children = ( + __PBXFileRef_SwiftString.xcodeproj/Configs/Project.xcconfig /* SwiftString.xcodeproj/Configs/Project.xcconfig */, + __PBXFileRef_SwiftString.xcodeproj/Configs/Debug.xcconfig /* SwiftString.xcodeproj/Configs/Debug.xcconfig */, + __PBXFileRef_SwiftString.xcodeproj/Configs/Release.xcconfig /* SwiftString.xcodeproj/Configs/Release.xcconfig */, + ); + name = Configs; + sourceTree = ""; + }; + "_____Sources_" /* Sources */ = { + isa = PBXGroup; + children = ( + "_______Group_SwiftString" /* SwiftString */, + ); + name = Sources; + sourceTree = ""; + }; + "_______Group_SwiftString" /* SwiftString */ = { + isa = PBXGroup; + children = ( + "__PBXFileRef_Sources/String+HTML.swift" /* StringHTML.swift */, + __PBXFileRef_Sources/StringExtensions.swift /* StringExtensions.swift */, + ); + name = SwiftString; + sourceTree = ""; + }; + "_______Group_SwiftStringTests" /* SwiftStringTests */ = { + isa = PBXGroup; + children = ( + __PBXFileRef_Tests/SwiftStringTests/SwiftStringTests.swift /* SwiftStringTests.swift */, + ); + name = SwiftStringTests; + sourceTree = ""; + }; + "_______Tests_" /* Tests */ = { + isa = PBXGroup; + children = ( + "_______Group_SwiftStringTests" /* SwiftStringTests */, + ); + name = Tests; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + "______Target_SwiftString" /* SwiftString */ = { + isa = PBXNativeTarget; + buildConfigurationList = "_______Confs_SwiftString" /* Build configuration list for PBXNativeTarget "SwiftString" */; + buildPhases = ( + CompilePhase_SwiftString /* Sources */, + "___LinkPhase_SwiftString" /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SwiftString; + productName = SwiftString; + productReference = "_____Product_SwiftString" /* SwiftString.framework */; + productType = "com.apple.product-type.framework"; + }; + "______Target_SwiftStringTests" /* SwiftStringTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = "_______Confs_SwiftStringTests" /* Build configuration list for PBXNativeTarget "SwiftStringTests" */; + buildPhases = ( + CompilePhase_SwiftStringTests /* Sources */, + "___LinkPhase_SwiftStringTests" /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + __Dependency_SwiftString /* PBXTargetDependency */, + ); + name = SwiftStringTests; + productName = SwiftStringTests; + productReference = "_____Product_SwiftStringTests" /* SwiftStringTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + __RootObject_ /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 9999; + TargetAttributes = { + "______Target_SwiftString" = { + LastSwiftMigration = 0800; + }; + "______Target_SwiftStringTests" = { + LastSwiftMigration = 0800; + }; + }; + }; + buildConfigurationList = "___RootConfs_" /* Build configuration list for PBXProject "SwiftString" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = "___RootGroup_"; + productRefGroup = "____Products_" /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + "______Target_SwiftString" /* SwiftString */, + "______Target_SwiftStringTests" /* SwiftStringTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + CompilePhase_SwiftString /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 0; + files = ( + "__src_cc_ref_Sources/String+HTML.swift" /* StringHTML.swift in Sources */, + __src_cc_ref_Sources/StringExtensions.swift /* StringExtensions.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + CompilePhase_SwiftStringTests /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 0; + files = ( + __src_cc_ref_Tests/SwiftStringTests/SwiftStringTests.swift /* SwiftStringTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + __Dependency_SwiftString /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = "______Target_SwiftString" /* SwiftString */; + targetProxy = E0AD59D81D91B4DD00DC93F0 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + _ReleaseConf_SwiftString /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ENABLE_TESTABILITY = YES; + FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks"; + INFOPLIST_FILE = SwiftString.xcodeproj/SwiftString_Info.plist; + LD_RUNPATH_SEARCH_PATHS = "\"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx\""; + LIBRARY_SEARCH_PATHS = "\"$(PROJECT_TEMP_DIR)/SymlinkLibs/\""; + OTHER_LDFLAGS = "\"$(inherited)\""; + OTHER_SWIFT_FLAGS = "\"$(inherited)\""; + PRODUCT_BUNDLE_IDENTIFIER = SwiftString; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; + _ReleaseConf_SwiftStringTests /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; + FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks"; + INFOPLIST_FILE = SwiftString.xcodeproj/SwiftStringTests_Info.plist; + LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; + LIBRARY_SEARCH_PATHS = "\"$(PROJECT_TEMP_DIR)/SymlinkLibs/\""; + OTHER_LDFLAGS = "\"$(inherited)\""; + OTHER_SWIFT_FLAGS = "\"$(inherited)\""; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; + "___DebugConf_SwiftString" /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ENABLE_TESTABILITY = YES; + FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks"; + INFOPLIST_FILE = SwiftString.xcodeproj/SwiftString_Info.plist; + LD_RUNPATH_SEARCH_PATHS = "\"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx\""; + LIBRARY_SEARCH_PATHS = "\"$(PROJECT_TEMP_DIR)/SymlinkLibs/\""; + OTHER_LDFLAGS = "\"$(inherited)\""; + OTHER_SWIFT_FLAGS = "\"$(inherited)\""; + PRODUCT_BUNDLE_IDENTIFIER = SwiftString; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + "___DebugConf_SwiftStringTests" /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; + FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks"; + INFOPLIST_FILE = SwiftString.xcodeproj/SwiftStringTests_Info.plist; + LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; + LIBRARY_SEARCH_PATHS = "\"$(PROJECT_TEMP_DIR)/SymlinkLibs/\""; + OTHER_LDFLAGS = "\"$(inherited)\""; + OTHER_SWIFT_FLAGS = "\"$(inherited)\""; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + "_____Release_" /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = __PBXFileRef_SwiftString.xcodeproj/Configs/Release.xcconfig /* SwiftString.xcodeproj/Configs/Release.xcconfig */; + buildSettings = { + }; + name = Release; + }; + "_______Debug_" /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = __PBXFileRef_SwiftString.xcodeproj/Configs/Debug.xcconfig /* SwiftString.xcodeproj/Configs/Debug.xcconfig */; + buildSettings = { + }; + name = Debug; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + "___RootConfs_" /* Build configuration list for PBXProject "SwiftString" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + "_______Debug_" /* Debug */, + "_____Release_" /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; + }; + "_______Confs_SwiftString" /* Build configuration list for PBXNativeTarget "SwiftString" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + "___DebugConf_SwiftString" /* Debug */, + _ReleaseConf_SwiftString /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; + }; + "_______Confs_SwiftStringTests" /* Build configuration list for PBXNativeTarget "SwiftStringTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + "___DebugConf_SwiftStringTests" /* Debug */, + _ReleaseConf_SwiftStringTests /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; + }; +/* End XCConfigurationList section */ + }; + rootObject = __RootObject_ /* Project object */; +} diff --git a/Example/SwiftString.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/SwiftString.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 69% rename from Example/SwiftString.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to SwiftString.xcodeproj/project.xcworkspace/contents.xcworkspacedata index b2b993e..919434a 100644 --- a/Example/SwiftString.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/SwiftString.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/Example/SwiftString.xcodeproj/xcshareddata/xcschemes/SwiftString-Example.xcscheme b/SwiftString.xcodeproj/xcshareddata/xcschemes/SwiftString.xcscheme similarity index 54% rename from Example/SwiftString.xcodeproj/xcshareddata/xcschemes/SwiftString-Example.xcscheme rename to SwiftString.xcodeproj/xcshareddata/xcschemes/SwiftString.xcscheme index aa24f9c..bbb84fa 100644 --- a/Example/SwiftString.xcodeproj/xcshareddata/xcschemes/SwiftString-Example.xcscheme +++ b/SwiftString.xcodeproj/xcshareddata/xcschemes/SwiftString.xcscheme @@ -1,6 +1,6 @@ - - - - @@ -46,22 +32,13 @@ skipped = "NO"> - - - - @@ -75,16 +52,15 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - + - + @@ -94,16 +70,6 @@ savedToolIdentifier = "" useCustomWorkingDirectory = "NO" debugDocumentVersioning = "YES"> - - - - diff --git a/SwiftString.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist b/SwiftString.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..2ee5ba0 --- /dev/null +++ b/SwiftString.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist @@ -0,0 +1,12 @@ + + + + SchemeUserState + + SwiftString.xcscheme + + + SuppressBuildableAutocreation + + + diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..3bcdbbc --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,6 @@ +import XCTest +@testable import SwiftStringTests + +XCTMain([ + testCase(SwiftStringTests.allTests), + ]) diff --git a/Tests/SwiftStringTests/SwiftStringTests.swift b/Tests/SwiftStringTests/SwiftStringTests.swift new file mode 100644 index 0000000..e500c0c --- /dev/null +++ b/Tests/SwiftStringTests/SwiftStringTests.swift @@ -0,0 +1,286 @@ +import XCTest +#if os(Linux) + import SwiftGlibc +#else + import Darwin +#endif +@testable import SwiftString + +class SwiftStringTests: XCTestCase { + override func setUp() { + super.setUp() + } + override func tearDown() { + super.tearDown() + } + + func testBetween() { + let s = "The stupid brown fox" + XCTAssert(((s.between("stupid", "fox")?.characters.count) != nil), "Between is invalid") + } + func testCamelize() { + let s = "The stupid brown fox" + XCTAssert((s.camelize() != "The Stupid Brown Fox"), "Camelize is invalid") + } + func testCapitalize() { + let s = "the Fox" + XCTAssert((s.capitalize() != "THE FOX"), "Capitalize is invalid") + } + func testChompLeft() { + let s = "The stupid brown Fox" + XCTAssertEqual(s.chompLeft("The "), "stupid brown Fox", "ChompLeft is invalid") + } + + func testChompRight() { + let s = "The stupid brown Fox" + XCTAssertEqual(s.chompLeft(" Fox"), "The stupid brown", "ChompRight is invalid") + } + + //collapseWhitespace + func testcollapseWhitespace() { + let s = "The stupid brown fox" + XCTAssertEqual(s.collapseWhitespace(), "The stupid brown fox", "collapseWhitespace is invalid") + } + + //clean + func testclean() { + let s = "The stupid brøwn føx" + XCTAssertEqual(s.clean(with: "o",allOf: "ø"), "The stupid brown fox", "clean is invalid") + } + //count + func testcount() { + let s = "The stupid brown fox" + XCTAssertEqual(s.count("o"), 2, "count is invalid") + } + //endsWith + func testendsWith() { + let s = "The stupid brown fox" + XCTAssertEqual(s.endsWith("foc"), false, "endsWith is invalid") + XCTAssertEqual(s.endsWith("fox"), true, "endsWith is invalid") + } + //ensureLeft + func testensureLeft() { + let s = "The stupid brown fox" + XCTAssertNotEqual(s.ensureLeft("Tha"), s, "ensureLeft is invalid") + XCTAssertEqual(s.ensureLeft("The"), "The stupid brown fox", "ensureLeft is invalid") + XCTAssertEqual(s.ensureLeft("And "), "And The stupid brown fox", "ensureLeft is invalid") + } + //ensureRight + func testensureRight() { + let s = "The stupid brown fox" + XCTAssertNotEqual(s.ensureRight("fax"), s, "ensureRight is invalid") + XCTAssertEqual(s.ensureRight("fox"), "The stupid brown fox", "ensureRight is invalid") + XCTAssertEqual(s.ensureRight(" died."), "The stupid brown fox died.", "ensureRight is invalid") + } + //indexOf + func testindexOf() { + let s = "The stupid brøwn føx" + XCTAssertEqual(s.indexOf("s"), 4, "indexOf is invalid") + XCTAssertNotEqual(s.indexOf("s"), 7, "indexOf is invalid") + } + //initials + func testinitials() { + let s = "brown Fox" + XCTAssertEqual(s.initials(), "bF", "initials is invalid") + XCTAssertNotEqual(s.initials(), "BS", "initials is invalid") + } + //initialsFirstAndLast + func testinitialsFirstAndLast() { + let s = "stupid brown Fox" + XCTAssertEqual(s.initialsFirstAndLast(), "sF", "initialsFirstAndLast is invalid") + XCTAssertNotEqual(s.initialsFirstAndLast(), "bF", "initialsFirstAndLast is invalid") + } + //isAlpha + func testisAlpha() { + let s = "stupid brown Fox" + XCTAssertEqual(s.isAlpha(), false, "isAlpha is invalid") + + let sn = "stupid2Fox" + XCTAssertEqual(sn.isAlpha(), false, "isAlpha is invalid") + + let ss = "stupidbrownFox" + XCTAssertEqual(ss.isAlpha(), true, "isAlpha is invalid") + } + //isAlphaNumeric + func testisAlphaNumeric() { + let s = "stupid brown Fox!" + XCTAssertEqual(s.isAlphaNumeric(), false, "isAlphaNumeric is invalid") + + let snx = "stupid2Fox!" + XCTAssertEqual(snx.isAlphaNumeric(), false, "isAlphaNumeric is invalid") + + let sn = "stupid2Fox" + XCTAssertEqual(sn.isAlphaNumeric(), true, "isAlphaNumeric is invalid") + + let ss = "stupidbrownFox" + XCTAssertEqual(ss.isAlphaNumeric(), true, "isAlphaNumeric is invalid") + } + //isEmpty + func testisEmpty() { + let s = "stupid brown Fox!" + XCTAssertEqual(s.isEmpty(), false, "isEmpty is invalid") + + let snx = "" + XCTAssertEqual(snx.isEmpty(), true, "isEmpty is invalid") + } + //isNumeric + func testisNumeric() { + let s = "stupid brown Fox!" + XCTAssertEqual(s.isNumeric(), false, "isNumeric is invalid") + + let snx = "12" + XCTAssertEqual(snx.isNumeric(), true, "isNumeric is invalid") + } + //latinize + func testlatinize() { + let s = "The stüpid brown Fox" + XCTAssertEqual(s.latinize(), "The stupid brown Fox", "latinize is invalid") + } + //lines + func testlines() { + let s = "The stupid brown Fox\nis dead." + XCTAssertEqual(s.lines(), ["The stupid brown Fox","is dead."], "lines is invalid") + } + //length + func testlength() { + let s = "The stupid brown Fox" + XCTAssertEqual(s.length, 20, "length is invalid") + } + //pad + func testpad() { + let s = "The stupid brown Fox" + XCTAssertEqual(s.pad(3,"x"), "xxxThe stupid brown Foxxxx", "pad is invalid") + } + //padLeft + func testpadLeft() { + let s = "The stupid brown Fox" + XCTAssertEqual(s.padLeft(3,"x"), "xxxThe stupid brown Fox", "padLeft is invalid") + } + //padRight + func testpadRight() { + let s = "The stupid brown Fox" + XCTAssertEqual(s.padRight(3,"x"), "The stupid brown Foxxxx", "padRight is invalid") + } + //slugify + func testslugify() { + let s = "The stupid brown Fox" + XCTAssertEqual(s.slugify(), "the-stupid-brown-fox", "slugify is invalid") + } + //split + func testsplit() { + let s = "The stupid brown Fox - is dead" + XCTAssertEqual(s.split(), ["The","stupid","brown","Fox","-","is","dead"], "split is invalid") + XCTAssertEqual(s.split("-"), ["The stupid brown Fox "," is dead"], "split is invalid") + } + //startsWith + func teststartsWith() { + let s = "The stupid brown Fox" + XCTAssertEqual(s.startsWith("The stupid"), true, "startsWith is invalid") + XCTAssertEqual(s.startsWith("The nice"), false, "startsWith is invalid") + } + //stripPunctuation + func teststripPunctuation() { + let s = "The stupid! brown Fox" + XCTAssertEqual(s.stripPunctuation(), "The stupid brown Fox", "stripPunctuation is invalid") + } + //toFloat + func testtoFloat() { + let s = "2.0" + XCTAssertEqual(s.toFloat(), 2.0, "toFloat is invalid") + } + //toInt + func testtoInt() { + let s = "2" + XCTAssertEqual(s.toInt(), 2, "toInt is invalid") + } + //toBool + func testtoBool() { + let s = "0" + XCTAssertEqual(s.toBool(), false, "toBool is invalid") + let s1 = "-1" + XCTAssertEqual(s1.toBool(), true, "toBool is invalid") + let s2 = "1" + XCTAssertEqual(s2.toBool(), true, "toBool is invalid") + let s3 = "2" + XCTAssertEqual(s3.toBool(), true, "toBool is invalid") + } + #if !os(Linux) + //toDate + func testtoDate() { + let s = "2016-03-01" + let formatter = DateFormatter() + formatter.dateFormat = "yyyy/MM/dd" + let someDateTime = formatter.date(from: "2016-03-01") + XCTAssertEqual(s.toDate(),someDateTime, "toDate is invalid") + } + //toDateTime + func testtoDateTime() { + let s = "2016-03-01 18:31:00" + let formatter = DateFormatter() + formatter.dateFormat = "yyyy/MM/dd HH:mm:SS" + let someDateTime = formatter.date(from: "2016-03-01 18:31:00") + XCTAssertEqual(s.toDateTime(),someDateTime, "toDateTime is invalid") + } + #endif + //trimmedLeft + func testtrimmedLeft() { + let s = " The stupid brown fox " + XCTAssertEqual(s.trimmedLeft(), "The stupid brown fox ", "trimmedLeft is invalid") + } + //trimmedRight + func testtrimmedRight() { + let s = " The stupid brown fox " + XCTAssertEqual(s.trimmedRight(), " The stupid brown fox", "trimmedRight is invalid") + } + //trimmed + func testtrimmed() { + let s = " The stupid brown fox " + XCTAssertEqual(s.trimmed(), "The stupid brown fox", "trimmed is invalid") + } + //substring + func testsubstring() { + let s = "The stupid brown fox" + XCTAssertEqual(s.substring(4,length: 9), "stupid br", "trimmed is invalid") + } + + static var allTests : [(String, (SwiftStringTests) -> () throws -> Void)] { + return [ + ("testBetween", testBetween), + ("testCamelize", testCamelize), + ("testCapitalize", testCapitalize), + ("testChompLeft", testChompLeft), + ("testChompRight", testChompRight), + ("testcollapseWhitespace", testcollapseWhitespace), + ("testclean", testclean), + ("testcount", testcount), + ("testendsWith", testendsWith), + ("testensureLeft", testensureLeft), + ("testensureRight", testensureRight), + ("testindexOf", testindexOf), + ("testinitials", testinitials), + ("testinitialsFirstAndLast", testinitialsFirstAndLast), + ("testisAlpha", testisAlpha), + ("testisAlphaNumeric", testisAlphaNumeric), + ("testisEmpty", testisEmpty), + ("testisNumeric", testisNumeric), + ("testlatinize", testlatinize), + ("testlines", testlines), + ("testlength", testlength), + ("testpad", testpad), + ("testpadLeft", testpadLeft), + ("testpadRight", testpadRight), + ("testslugify", testslugify), + ("testsplit", testsplit), + ("teststartsWith", teststartsWith), + ("teststripPunctuation", teststripPunctuation), + ("testtoFloat", testtoFloat), + ("testtoInt", testtoInt), + ("testtoBool", testtoBool), + ("testtrimmedLeft", testtrimmedLeft), + ("testtrimmedRight", testtrimmedRight), + ("testtrimmed", testtrimmed), + ("testsubstring", testsubstring) + ] + } + +} diff --git a/_Pods.xcodeproj b/_Pods.xcodeproj deleted file mode 120000 index 3c5a8e7..0000000 --- a/_Pods.xcodeproj +++ /dev/null @@ -1 +0,0 @@ -Example/Pods/Pods.xcodeproj \ No newline at end of file