From a1bb277e9b1d11ee2024cb7bec59c0b19c608a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=CD=ACe=CD=A5b=CD=ADa=CD=ADs=CD=A4t=CD=ACian?= Date: Fri, 13 Sep 2024 14:01:39 +0200 Subject: [PATCH] add lastIndexOf with return of Int to String --- Sources/JavApi/lang/String+Java.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/JavApi/lang/String+Java.swift b/Sources/JavApi/lang/String+Java.swift index 3ee93508..170a4b08 100644 --- a/Sources/JavApi/lang/String+Java.swift +++ b/Sources/JavApi/lang/String+Java.swift @@ -104,6 +104,20 @@ extension String { return toCharArray()[index] } + public func lastIndexOf (_ char : Character) -> Int { + guard self.contains(char) else { + return -1 + } + return distance(from: startIndex, to: self.lastIndex(of: char)!) + } + + func lastIndexOf(_ substring: String) -> Int { + guard let range = range(of: substring, options: .backwards) else { + return -1 + } + return distance(from: startIndex, to: range.lowerBound) + } + /// The count of String elements @inlinable public func lenght () -> Int {