You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/HandySwift/Extensions/StringExt.swift
+39Lines changed: 39 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -183,6 +183,45 @@ extension String {
183
183
184
184
return plainString
185
185
}
186
+
187
+
/// Splits the String into word tokens that are folded for case-insensitive, diacritics-insensitive, and width-insensitive operations such as search.
188
+
/// This is particularly useful for string normalization in search queries, where the goal is to match strings regardless of their case, diacritics, or full-width/half-width characters.
189
+
///
190
+
/// - Parameter locale: Optional. The locale to use for the folding operation. If `nil`, the system's current locale is used. This affects the folding behavior, especially for diacritics.
191
+
/// - Returns: An array of normalized, tokenized strings.
/// Splits both the current string and the search text into word tokens and performs a case-insensitive, diacritics-insensitive search.
206
+
/// It matches the start of each token in the search text with the tokens in the current string, making it suitable for prefix-based search queries.
207
+
///
208
+
/// - Parameters:
209
+
/// - searchText: The text to search for within this String.
210
+
/// - locale: Optional. The locale to use for the insensitivity folding operation. If `nil`, the system's current locale is used. This can impact how characters are folded for comparison.
211
+
/// - Returns: `true` if all tokens from the search text are prefixes of any token in this String; otherwise, `false`.
212
+
///
213
+
/// ## Example:
214
+
/// ```
215
+
/// let text = "Terms and Conditions"
216
+
/// let searchResult = text.matchesTokenizedPrefixes(in: "ter con")
0 commit comments