summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcutils/DelimRemover.java
blob: f00db05d4b409ccc4301e529e5ffcb2a37b86fc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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;
	}
}