From 1e6202467bf0d96246403773a9c55e0c6a5d6667 Mon Sep 17 00:00:00 2001 From: flangel Date: Sat, 28 Jul 2018 12:26:29 +0200 Subject: [PATCH 1/8] Upgraded to Swift 4.1 - marked times() method as deprecated --- Sources/StringExtensions.swift | 29 ++++++++++--------- Sources/StringHTML.swift | 8 ++--- SwiftString.xcodeproj/project.pbxproj | 18 +++++++++++- Tests/SwiftStringTests/SwiftStringTests.swift | 7 +++++ 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/Sources/StringExtensions.swift b/Sources/StringExtensions.swift index 8a0b65a..81836a6 100644 --- a/Sources/StringExtensions.swift +++ b/Sources/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/StringHTML.swift index cef0ac4..64dce32 100644 --- a/Sources/StringHTML.swift +++ b/Sources/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/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) ] } From 3b71057d32467ca2dedd6e15f87cd562862c062e Mon Sep 17 00:00:00 2001 From: flangel Date: Sat, 28 Jul 2018 12:32:16 +0200 Subject: [PATCH 2/8] Added Swift Language requirement --- Package.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 6ba9c0f..262f5fa 100644 --- a/Package.swift +++ b/Package.swift @@ -5,5 +5,6 @@ let package = Package( name: "SwiftString", targets: [], dependencies: [ - ] + ], + swiftLanguageVersions: [4.1] ) From ab049db1031a7981872c7526d1e26a65287f8def Mon Sep 17 00:00:00 2001 From: Frank Langel Date: Sat, 28 Jul 2018 13:35:42 +0200 Subject: [PATCH 3/8] Update Package.swift --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 262f5fa..2efbbda 100644 --- a/Package.swift +++ b/Package.swift @@ -6,5 +6,5 @@ let package = Package( targets: [], dependencies: [ ], - swiftLanguageVersions: [4.1] + swiftLanguageVersions: [4] ) From f61c2767c0f44c09bf88a1350c9f4401f9456507 Mon Sep 17 00:00:00 2001 From: Frank Langel Date: Sun, 5 Aug 2018 17:24:41 +0200 Subject: [PATCH 4/8] Update .swift-version --- .swift-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.swift-version b/.swift-version index 9f55b2c..5186d07 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +4.0 From 8f61cb9fd413b36fcd21dc3073bdb6e1b971e42f Mon Sep 17 00:00:00 2001 From: Frank Langel Date: Sun, 5 Aug 2018 17:28:44 +0200 Subject: [PATCH 5/8] Update Package.swift added swift-tools-version:4.0 --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 2efbbda..2c664d9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,5 +1,5 @@ -// 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", From fcde7b30b174b236a1d1e0ae50a30ebca8b2cab3 Mon Sep 17 00:00:00 2001 From: Frank Langel Date: Sun, 5 Aug 2018 20:32:55 +0200 Subject: [PATCH 6/8] Update Package.swift Changed sequence of declarations --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 2c664d9..2750112 100644 --- a/Package.swift +++ b/Package.swift @@ -3,8 +3,8 @@ import PackageDescription let package = Package( name: "SwiftString", - targets: [], dependencies: [ ], + targets: [], swiftLanguageVersions: [4] ) From f9c035d60b29283db81e184fe68f0e0f4fdbbef5 Mon Sep 17 00:00:00 2001 From: flangel Date: Mon, 6 Aug 2018 06:41:38 +0200 Subject: [PATCH 7/8] Updated package --- Package.swift | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index 2750112..7510a98 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,29 @@ // swift-tools-version:4.0 import PackageDescription + let package = Package( - name: "SwiftString", - dependencies: [ - ], - targets: [], + 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] ) From 61a133da088633650de69f3db5d7206d5dbd469e Mon Sep 17 00:00:00 2001 From: flangel Date: Mon, 6 Aug 2018 12:40:07 +0200 Subject: [PATCH 8/8] Changed to V4 package structure --- Sources/{ => SwiftString}/StringExtensions.swift | 0 Sources/{ => SwiftString}/StringHTML.swift | 0 Sources/{ => SwiftString}/StringURL.swift | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename Sources/{ => SwiftString}/StringExtensions.swift (100%) rename Sources/{ => SwiftString}/StringHTML.swift (100%) rename Sources/{ => SwiftString}/StringURL.swift (100%) diff --git a/Sources/StringExtensions.swift b/Sources/SwiftString/StringExtensions.swift similarity index 100% rename from Sources/StringExtensions.swift rename to Sources/SwiftString/StringExtensions.swift diff --git a/Sources/StringHTML.swift b/Sources/SwiftString/StringHTML.swift similarity index 100% rename from Sources/StringHTML.swift rename to Sources/SwiftString/StringHTML.swift 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