-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for case-insensitive parsing to ConfigurableDoubleParser.
1 parent
227fe15
commit e692134
Showing
12 changed files
with
382 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...delshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/CharTrieOfManyIgnoreCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* @(#)CharTrieOfMany.java | ||
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License. | ||
*/ | ||
package ch.randelshofer.fastdoubleparser; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* A trie for testing if a String is contained in a set of Strings. | ||
*/ | ||
class CharTrieOfManyIgnoreCase implements CharTrie { | ||
private TrieNode root = new TrieNode(); | ||
|
||
public CharTrieOfManyIgnoreCase(Set<String> set) { | ||
for (String str : set) { | ||
if (!str.isEmpty()) { | ||
add(str); | ||
} | ||
} | ||
} | ||
|
||
private void add(String str) { | ||
TrieNode node = root; | ||
for (int i = 0; i < str.length(); i++) { | ||
node = node.insert(convert(str.charAt(i))); | ||
} | ||
node.setEnd(); | ||
} | ||
|
||
private char convert(char c) { | ||
return Character.toLowerCase(Character.toUpperCase(c)); | ||
} | ||
|
||
@Override | ||
public int match(CharSequence str, int startIndex, int endIndex) { | ||
TrieNode node = root; | ||
int longestMatch = startIndex; | ||
for (int i = startIndex; i < endIndex; i++) { | ||
node = node.get(convert(str.charAt(i))); | ||
longestMatch = node.isEnd() ? i + 1 : longestMatch; | ||
} | ||
return longestMatch - startIndex; | ||
} | ||
|
||
@Override | ||
public int match(char[] str, int startIndex, int endIndex) { | ||
TrieNode node = root; | ||
int longestMatch = startIndex; | ||
for (int i = startIndex; i < endIndex; i++) { | ||
node = node.get(convert(str[i])); | ||
longestMatch = node.isEnd() ? i + 1 : longestMatch; | ||
} | ||
return longestMatch - startIndex; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ndelshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/CharTrieOfOneIgnoreCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* @(#)CharTrieOfOne.java | ||
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License. | ||
*/ | ||
package ch.randelshofer.fastdoubleparser; | ||
|
||
import java.util.Set; | ||
|
||
class CharTrieOfOneIgnoreCase implements CharTrie { | ||
private final char[] chars; | ||
|
||
public CharTrieOfOneIgnoreCase(Set<String> set) { | ||
this(set.iterator().next().toCharArray()); | ||
if (set.size() != 1) throw new IllegalArgumentException("set size must be 1, size=" + set.size()); | ||
} | ||
|
||
public CharTrieOfOneIgnoreCase(char[] chars) { | ||
this.chars = chars; | ||
for (int i = 0; i < chars.length; i++) { | ||
chars[i] = convert(chars[i]); | ||
} | ||
} | ||
|
||
@Override | ||
public int match(CharSequence str) { | ||
return match(str, 0, str.length()); | ||
} | ||
|
||
@Override | ||
public int match(CharSequence str, int startIndex, int endIndex) { | ||
int i = 0; | ||
int limit = Math.min(endIndex - startIndex, chars.length); | ||
while (i < limit && convert(str.charAt(i + startIndex)) == chars[i]) { | ||
i++; | ||
} | ||
return i == chars.length ? chars.length : 0; | ||
} | ||
|
||
private char convert(char c) { | ||
return Character.toLowerCase(Character.toUpperCase(c)); | ||
} | ||
|
||
@Override | ||
public int match(char[] str) { | ||
return match(str, 0, str.length); | ||
} | ||
|
||
@Override | ||
public int match(char[] str, int startIndex, int endIndex) { | ||
int i = 0; | ||
int limit = Math.min(endIndex - startIndex, chars.length); | ||
while (i < limit && convert(str[i + startIndex]) == chars[i]) { | ||
i++; | ||
} | ||
return i == chars.length ? chars.length : 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters