File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -241,12 +241,13 @@ extension Trie {
241
241
/// - Returns: the words in the subtrie that start with prefix
242
242
func findWordsWithPrefix( prefix: String ) -> [ String ] {
243
243
var words = [ String] ( )
244
- if let lastNode = findLastNodeOf ( word: prefix) {
244
+ let prefixLowerCased = prefix. lowercased ( )
245
+ if let lastNode = findLastNodeOf ( word: prefixLowerCased) {
245
246
if lastNode. isTerminating {
246
- words. append ( prefix )
247
+ words. append ( prefixLowerCased )
247
248
}
248
249
for childNode in lastNode. children. values {
249
- let childWords = wordsInSubtrie ( rootNode: childNode, partialWord: prefix )
250
+ let childWords = wordsInSubtrie ( rootNode: childNode, partialWord: prefixLowerCased )
250
251
words += childWords
251
252
}
252
253
}
Original file line number Diff line number Diff line change @@ -183,5 +183,13 @@ class TrieTests: XCTestCase {
183
183
XCTAssertEqual ( words2, [ " exam " , " examination " ] ) ;
184
184
let noWords = trie. findWordsWithPrefix ( prefix: " tee " )
185
185
XCTAssertEqual ( noWords, [ ] ) ;
186
+ let unicodeWord = " 😬😎 "
187
+ trie. insert ( word: unicodeWord)
188
+ let wordsUnicode = trie. findWordsWithPrefix ( prefix: " 😬 " )
189
+ XCTAssertEqual ( wordsUnicode, [ unicodeWord] ) ;
190
+ trie. insert ( word: " Team " )
191
+ let wordsUpperCase = trie. findWordsWithPrefix ( prefix: " Te " )
192
+ XCTAssertEqual ( wordsUpperCase. sorted ( ) , [ " team " , " test " ] ) ;
193
+
186
194
}
187
195
}
You can’t perform that action at this time.
0 commit comments