diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index fdf1a350d1d..803c1afd7f2 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -875,7 +875,6 @@ D8B0542E2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = D8B0542D2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy */; }; D8B088B629C9E3FF00213258 /* SentryTracerConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */; }; D8B088B729C9E3FF00213258 /* SentryTracerConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */; }; - D8B425122B9A0FD6000BFDF3 /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B425112B9A0FD6000BFDF3 /* StringExtensionTests.swift */; }; D8B665BC2B95F73200BD0E7B /* SentryPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B665BA2B95F54200BD0E7B /* SentryPrivate.h */; }; D8B76B062808066D000A58C4 /* SentryScreenshotIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B76B042808060E000A58C4 /* SentryScreenshotIntegrationTests.swift */; }; D8B76B0828081461000A58C4 /* TestSentryScreenShot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B76B0728081461000A58C4 /* TestSentryScreenShot.swift */; }; @@ -1933,7 +1932,6 @@ D8B0542D2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTracerConfiguration.h; path = include/SentryTracerConfiguration.h; sourceTree = ""; }; D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryTracerConfiguration.m; sourceTree = ""; }; - D8B425112B9A0FD6000BFDF3 /* StringExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtensionTests.swift; sourceTree = ""; }; D8B665BA2B95F54200BD0E7B /* SentryPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryPrivate.h; path = include/SentryPrivate.h; sourceTree = ""; }; D8B665BB2B95F5A100BD0E7B /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = Sources/Sentry/include/module.modulemap; sourceTree = SOURCE_ROOT; }; D8B76B042808060E000A58C4 /* SentryScreenshotIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScreenshotIntegrationTests.swift; sourceTree = ""; }; @@ -3648,7 +3646,6 @@ D84541192A2DC55100E2B11C /* SentryBinaryImageCache+Private.h */, D8292D7C2A39A027009872F7 /* UrlSanitizedTests.swift */, D8F8F5562B835BC600AC5465 /* SentryMsgPackSerializerTests.m */, - D8B425112B9A0FD6000BFDF3 /* StringExtensionTests.swift */, D8AFC0582BDA899A00118BE1 /* RedactRegionTests.swift */, D8F67AEF2BE0D31A00C9197B /* UIImageHelperTests.swift */, D8F67AF22BE10F7600C9197B /* UIRedactBuilderTests.swift */, @@ -4954,7 +4951,6 @@ 8F73BC312B02B87E00C3CEF4 /* SentryInstallationTests.swift in Sources */, 7B569E002590EEF600B653FC /* SentryScope+Equality.m in Sources */, D8BFE37929A76666002E73F3 /* SentryTimeToDisplayTrackerTest.swift in Sources */, - D8B425122B9A0FD6000BFDF3 /* StringExtensionTests.swift in Sources */, D84541182A2DC2CD00E2B11C /* SentryBinaryImageCacheTests.swift in Sources */, 7BF536D424BEF255004FA6A2 /* SentryAssertions.swift in Sources */, 7BC6EC14255C415E0059822A /* SentryExceptionTests.swift in Sources */, diff --git a/Sources/Swift/Extensions/StringExtensions.swift b/Sources/Swift/Extensions/StringExtensions.swift index fa8854e1512..c9a754c6e2a 100644 --- a/Sources/Swift/Extensions/StringExtensions.swift +++ b/Sources/Swift/Extensions/StringExtensions.swift @@ -1,43 +1,6 @@ import Foundation extension String { - /// Retrieve a character at a specific index in the string. - subscript (value: Int) -> Character { - return self[index(startIndex, offsetBy: value)] - } - - /// Retrieve a substring within a countable range of indices. - subscript (range: CountableRange) -> Substring { - let start = index(startIndex, offsetBy: range.lowerBound) - let end = index(startIndex, offsetBy: range.upperBound) - return self[start..) -> Substring { - let start = index(startIndex, offsetBy: range.lowerBound) - let end = index(startIndex, offsetBy: range.upperBound) - return self[start...end] - } - - /// Retrieve a substring up to a specified index. - subscript (range: PartialRangeThrough) -> Substring { - let end = index(startIndex, offsetBy: range.upperBound) - return self[startIndex...end] - } - - /// Retrieve a substring from a specified index to the end of the string. - subscript (range: CountablePartialRangeFrom) -> Substring { - let start = index(startIndex, offsetBy: range.lowerBound) - return self[start..) -> Substring { - let end = index(startIndex, offsetBy: range.upperBound) - return self[startIndex.. String { var result = "" diff --git a/Sources/Swift/Protocol/SentryId.swift b/Sources/Swift/Protocol/SentryId.swift index 3ba459019d2..48ebc2586f0 100644 --- a/Sources/Swift/Protocol/SentryId.swift +++ b/Sources/Swift/Protocol/SentryId.swift @@ -46,8 +46,13 @@ public class SentryId: NSObject { } if uuidString.count == 32 { - let dashedUUID = "\(uuidString[0..<8])-\(uuidString[8..<12])-\(uuidString[12..<16])-\(uuidString[16..<20])-\(uuidString[20...])" - if let id = UUID(uuidString: dashedUUID) { + let dashedUUID = uuidString.enumerated().reduce(into: [Character]()) { partialResult, next in + if next.offset == 8 || next.offset == 12 || next.offset == 16 || next.offset == 20 { + partialResult.append("-") + } + partialResult.append(next.element) + } + if let id = UUID(uuidString: String(dashedUUID)) { self.id = id return } diff --git a/Tests/SentryTests/Protocol/SentryIdTests.swift b/Tests/SentryTests/Protocol/SentryIdTests.swift index 33b0a3be439..72ad75c7c8c 100644 --- a/Tests/SentryTests/Protocol/SentryIdTests.swift +++ b/Tests/SentryTests/Protocol/SentryIdTests.swift @@ -22,6 +22,12 @@ class SentryIdTests: XCTestCase { func testInit() { XCTAssertNotEqual(SentryId(), SentryId()) } + + func testInitFromString() { + let string = "abcdefabcdefabcdefabcdefabcdefab" + let sentryId = SentryId(uuidString: "abcdefabcdefabcdefabcdefabcdefab") + XCTAssertEqual(sentryId.sentryIdString, string) + } func testInitWithUUID_ValidIdString() { let sentryId = SentryId(uuid: fixture.uuid) diff --git a/Tests/SentryTests/StringExtensionTests.swift b/Tests/SentryTests/StringExtensionTests.swift deleted file mode 100644 index 9e47e5845f6..00000000000 --- a/Tests/SentryTests/StringExtensionTests.swift +++ /dev/null @@ -1,44 +0,0 @@ -import Foundation -@testable import Sentry -import XCTest - -class StringExtensionTests: XCTestCase { - - func testSingleCharacterSubscript() { - let testString = "Hello, World!" - XCTAssertEqual(try XCTUnwrap(testString.first), "H") - XCTAssertEqual(testString[7], "W") - XCTAssertEqual(testString[12], "!") - } - - func testRangeOfCharactersSubscript() { - let testString = "Hello, World!" - XCTAssertEqual(testString[1..<5], "ello") - XCTAssertEqual(testString[7...11], "World") - XCTAssertEqual(testString[3...3], "l") - XCTAssertEqual(testString[1...5], "ello,") - XCTAssertEqual(testString[7...11], "World") - XCTAssertEqual(testString[0...0], "H") - } - - func testPartialRangeThroughSubscript() { - let testString = "Hello, World!" - XCTAssertEqual(testString[...5], "Hello,") - XCTAssertEqual(testString[...4], "Hello") - XCTAssertEqual(testString[...0], "H") - } - - func testPartialRangeFromSubscript() { - let testString = "Hello, World!" - XCTAssertEqual(testString[7...], "World!") - XCTAssertEqual(testString[0...], "Hello, World!") - XCTAssertEqual(testString[5...], ", World!") - } - - func testPartialRangeUpToSubscript() { - let testString = "Hello, World!" - XCTAssertEqual(testString[..<5], "Hello") - XCTAssertEqual(testString[..<4], "Hell") - XCTAssertEqual(testString[..<0], "") - } -}