diff --git a/Sources/SkipFoundation/String.swift b/Sources/SkipFoundation/String.swift index e74830f..45910eb 100644 --- a/Sources/SkipFoundation/String.swift +++ b/Sources/SkipFoundation/String.swift @@ -88,6 +88,11 @@ extension String { return UrlEncoderUtil.decode(self, plusToSpace: true) } + public func range(of searchString: String) -> Range? { + let startIndex = indexOf(searchString) + return startIndex != -1 ? startIndex..<(startIndex + searchString.count) : nil + } + public typealias Encoding = StringEncoding public var utf8Data: Data { diff --git a/Tests/SkipFoundationTests/CoreLibs/TestString.swift b/Tests/SkipFoundationTests/CoreLibs/TestString.swift new file mode 100644 index 0000000..a7f1066 --- /dev/null +++ b/Tests/SkipFoundationTests/CoreLibs/TestString.swift @@ -0,0 +1,14 @@ +// Copyright 2023–2025 Skip +// SPDX-License-Identifier: LGPL-3.0-only WITH LGPL-3.0-linking-exception +import Foundation +import XCTest + +class TestString : XCTestCase { + func test_rangeof() { + let str = "Hello, Skip!" + let rangeAll = str.range(of: str) + XCTAssertEqual(rangeAll, str.startIndex..