diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-03-14 14:41:20 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-03-14 14:41:20 -0400 |
| commit | 3086c3ec5019e8a3c74366d057518c7dbd4aea6e (patch) | |
| tree | ad942cad9929a13164579eb7760a96ac80733831 /BJC-Utils2/src/main/java | |
| parent | 504ca816530efdff06bc202e0432ebd354aec304 (diff) | |
Start on delimiter grouper
Diffstat (limited to 'BJC-Utils2/src/main/java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcutils/DelimRemover.java | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/DelimRemover.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/DelimRemover.java new file mode 100644 index 0000000..f00db05 --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/DelimRemover.java @@ -0,0 +1,103 @@ +package bjc.utils.funcutils; + +import bjc.utils.esodata.Stack; +import bjc.utils.esodata.SimpleStack; + +import java.util.List; +import java.util.ArrayList; + +/** + * Group delimited sequences of any kind together properly. + * + * @author Ben Culkin + */ +public class DelimRemover { + /** + * Represents a string or possibly a delimited group of strings. + * + * @author Ben Culkin + */ + public static class Result { + /** + * Whether this result is a delimited group, or just a string. + */ + public final boolean isGroup; + + /** + * The string value of this result, or null if it's a group. + */ + public final String stringVal; + + /* + * The info necessary for handling a delimited group. + * + * Only used when it is a group. + */ + /** + * The delimiter that opened this group. + */ + public final String opener; + + /** + * The tokens inside this group. + */ + public final Result[] contents; + + /** + * The delimiter that closed this group. + */ + public final String closer; + } + + /** + * Represents a failure of some sort during delimiter grouping. + * + * @author Ben Culkin + */ + public static class DelimException extends RuntimeException { + } + + /** + * Create a new delimiter remover. + */ + public DelimRemover() { + + } + + /** + * Groups delimited sequences in an array of string tokens together. + * + * @param tokens + * The tokens to group sequences in. + * + * @return The tokens with sequences grouped together. + * + * @throws DelimException Thrown if something went wrong during delimiter grouping. + */ + public Result[] delimitTokens(String[] tokens) { + /* + * @TODO implement me. + */ + List<Result> res = new ArrayList<>(tokens.length); + + return res.toArray(new Result[0]); + } + + /** + * Check if a string is properly delimited. + * + * It is guaranteed that delimitTokens will not throw a DelimException for tokens this + * method returns true for. + * + * @param tokens + * The sequence of tokens to check. + * + * @return Whether or not the tokens are properly delimited. + */ + public boolean isProperlyDelimited(String[] tokens) { + /* + * @TODO implement me. + */ + return false; + } +} |
