diff --git a/.swift-version b/.swift-version index 9f55b2c..5186d07 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +4.0 diff --git a/Package.swift b/Package.swift index 6ba9c0f..7510a98 100644 --- a/Package.swift +++ b/Package.swift @@ -1,9 +1,29 @@ -// Generated automatically by Perfect Assistant Application -// Date: 2017-11-11 21:12:58 +0000 +// swift-tools-version:4.0 + import PackageDescription + let package = Package( - name: "SwiftString", - targets: [], - dependencies: [ - ] + name: "SwiftString", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "SwiftString", + targets: ["SwiftString"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "SwiftString", + dependencies: []), + .testTarget( + name: "SwiftStringTests", + dependencies: ["SwiftString"]), + ], + + swiftLanguageVersions: [4] ) diff --git a/Sources/StringExtensions.swift b/Sources/SwiftString/StringExtensions.swift similarity index 93% rename from Sources/StringExtensions.swift rename to Sources/SwiftString/StringExtensions.swift index 8a0b65a..81836a6 100644 --- a/Sources/StringExtensions.swift +++ b/Sources/SwiftString/StringExtensions.swift @@ -21,7 +21,7 @@ public extension String { left != right && leftRange.upperBound != rightRange.lowerBound else { return nil } - return self[leftRange.upperBound...index(before: rightRange.lowerBound)] + return String(self[leftRange.upperBound...index(before: rightRange.lowerBound)]) } @@ -52,9 +52,9 @@ public extension String { 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 words = self.components(separatedBy: " ") - return words.reduce("") { ($0 == "" ? "" : $0[startIndex...startIndex]) + $1[startIndex...startIndex]} + return words.reduce("") { ($0 == "" ? "" : String($0[startIndex...startIndex])) + $1[startIndex...startIndex]} } func isAlpha() -> Bool { @@ -221,8 +221,11 @@ public extension String { .joined(separator: " ") } + @available(*, deprecated:7.0,message: "Use String(repeating,count)") func times(_ n: Int) -> String { - return (0.. Float? { @@ -264,14 +267,14 @@ public extension String { 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 { let start = self.index(self.startIndex, offsetBy: startIndex) let end = self.index(self.startIndex, offsetBy: startIndex + length) - return self[start.. Character { diff --git a/Sources/StringHTML.swift b/Sources/SwiftString/StringHTML.swift similarity index 98% rename from Sources/StringHTML.swift rename to Sources/SwiftString/StringHTML.swift index cef0ac4..64dce32 100644 --- a/Sources/StringHTML.swift +++ b/Sources/SwiftString/StringHTML.swift @@ -301,7 +301,7 @@ public extension String { // Find the next '&' and copy the characters preceding it to `result`: while let ampRange = self.range(of: "&", range: position ..< endIndex) { - result.append(self[position ..< ampRange.lowerBound]) + result.append(String(self[position ..< ampRange.lowerBound])) position = ampRange.lowerBound // Find the next ';' and copy everything from '&' to ';' into `entity` @@ -309,12 +309,12 @@ public extension String { let entity = self[position ..< semiRange.upperBound] position = semiRange.upperBound - if let decoded = decode(entity) { + if let decoded = decode(String(entity)) { // Replace by decoded character: result.append(decoded) } else { // Invalid entity, copy verbatim: - result.append(entity) + result.append(String(entity)) } } else { // No matching ';'. @@ -322,7 +322,7 @@ public extension String { } } // Copy remaining characters to `result`: - result.append(self[position ..< endIndex]) + result.append(String(self[position ..< endIndex])) return result } } diff --git a/Sources/StringURL.swift b/Sources/SwiftString/StringURL.swift similarity index 100% rename from Sources/StringURL.swift rename to Sources/SwiftString/StringURL.swift diff --git a/SwiftString.xcodeproj/project.pbxproj b/SwiftString.xcodeproj/project.pbxproj index 519313d..856c9cb 100644 --- a/SwiftString.xcodeproj/project.pbxproj +++ b/SwiftString.xcodeproj/project.pbxproj @@ -31,7 +31,7 @@ OBJ_10 /* StringHTML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringHTML.swift; sourceTree = ""; }; OBJ_13 /* SwiftStringTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftStringTests.swift; sourceTree = ""; }; OBJ_15 /* SwiftString.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftString.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - OBJ_16 /* SwiftStringTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = SwiftStringTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + OBJ_16 /* SwiftStringTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = SwiftStringTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; OBJ_9 /* StringExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtensions.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -154,6 +154,14 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 9999; + TargetAttributes = { + OBJ_17 = { + LastSwiftMigration = 0940; + }; + OBJ_25 = { + LastSwiftMigration = 0940; + }; + }; }; buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "SwiftString" */; compatibilityVersion = "Xcode 3.2"; @@ -220,6 +228,8 @@ PRODUCT_BUNDLE_IDENTIFIER = SwiftString; PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGET_NAME = SwiftString; }; name = Debug; @@ -240,6 +250,8 @@ PRODUCT_BUNDLE_IDENTIFIER = SwiftString; PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGET_NAME = SwiftString; }; name = Release; @@ -257,6 +269,8 @@ LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGET_NAME = SwiftStringTests; }; name = Debug; @@ -274,6 +288,8 @@ LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGET_NAME = SwiftStringTests; }; name = Release; diff --git a/Tests/SwiftStringTests/SwiftStringTests.swift b/Tests/SwiftStringTests/SwiftStringTests.swift index df0d1a5..d397829 100644 --- a/Tests/SwiftStringTests/SwiftStringTests.swift +++ b/Tests/SwiftStringTests/SwiftStringTests.swift @@ -273,6 +273,12 @@ class SwiftStringTests: XCTestCase { let decoded = encoded.fromBase64() XCTAssertEqual(str, decoded, "Base64 does not match") } + + func testtimes() { + let fivetimesc = "ccccc" + let fivetimescComputed = "c".times(5) + XCTAssertEqual(fivetimesc, fivetimescComputed, "times doesnt work properly") + } static var allTests : [(String, (SwiftStringTests) -> () throws -> Void)] { return [ @@ -313,6 +319,7 @@ class SwiftStringTests: XCTestCase { ("testsubstring", testsubstring), ("testsubscript", testsubscript), ("testsafesubscript", testsafesubscript), + ("testtimes", testtimes) ] }