Skip to content

Commit

Permalink
ref: reimplement uuid init without string subscript extensions (#4133)
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Jul 8, 2024
1 parent 1f8446c commit a0601b7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 87 deletions.
4 changes: 0 additions & 4 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -1933,7 +1932,6 @@
D8B0542D2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTracerConfiguration.h; path = include/SentryTracerConfiguration.h; sourceTree = "<group>"; };
D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryTracerConfiguration.m; sourceTree = "<group>"; };
D8B425112B9A0FD6000BFDF3 /* StringExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtensionTests.swift; sourceTree = "<group>"; };
D8B665BA2B95F54200BD0E7B /* SentryPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryPrivate.h; path = include/SentryPrivate.h; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
37 changes: 0 additions & 37 deletions Sources/Swift/Extensions/StringExtensions.swift
Original file line number Diff line number Diff line change
@@ -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<Int>) -> Substring {
let start = index(startIndex, offsetBy: range.lowerBound)
let end = index(startIndex, offsetBy: range.upperBound)
return self[start..<end]
}

/// Retrieve a substring within a closed countable range of indices.
subscript (range: CountableClosedRange<Int>) -> 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<Int>) -> 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<Int>) -> Substring {
let start = index(startIndex, offsetBy: range.lowerBound)
return self[start..<endIndex]
}

/// Retrieve a substring up to a specified index, excluding that index.
subscript (range: PartialRangeUpTo<Int>) -> Substring {
let end = index(startIndex, offsetBy: range.upperBound)
return self[startIndex..<end]
}

func snakeToCamelCase() -> String {
var result = ""

Expand Down
9 changes: 7 additions & 2 deletions Sources/Swift/Protocol/SentryId.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/SentryTests/Protocol/SentryIdTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 0 additions & 44 deletions Tests/SentryTests/StringExtensionTests.swift

This file was deleted.

0 comments on commit a0601b7

Please sign in to comment.