MCPcopy Create free account
hub / github.com/PCGen/pcgen / parseAspectString

Method parseAspectString

code/src/java/pcgen/cdom/helper/Aspect.java:107–179  ·  view source on GitHub ↗

Parse an aspect definition string and populate the Aspect with the contents. This drives the processing to split the description from the parameters and to identify the references to the parameters. @param aString The aspect definition string.

(final String aString)

Source from the content-addressed store, hash-verified

105 * @param aString The aspect definition string.
106 */
107 private void parseAspectString(final String aString)
108 {
109 int currentInd = 0;
110 int percentInd;
111 while ((percentInd = aString.indexOf('%', currentInd)) != -1)
112 {
113 final String preText = aString.substring(currentInd, percentInd);
114 if (!preText.isEmpty())
115 {
116 theComponents.add(preText);
117 }
118 if (percentInd == aString.length() - 1)
119 {
120 theComponents.add("%"); //$NON-NLS-1$
121 return;
122 }
123 if (aString.charAt(percentInd + 1) == '{')
124 {
125 // This is a bracketed placeholder. The replacement parameter
126 // is contained within the {}
127 currentInd = aString.indexOf('}', percentInd + 1) + 1;
128 final String replacement = aString.substring(percentInd + 1, currentInd);
129 // For the time being we will only support numerics here.
130 try
131 {
132 Integer.parseInt(replacement);
133 }
134 catch (NumberFormatException nfe)
135 {
136 Logging.errorPrintLocalised("Errors.Description.InvalidVariableReplacement", //$NON-NLS-1$
137 replacement);
138 }
139 theComponents.add(VAR_MARKER + replacement);
140 }
141 else if (aString.charAt(percentInd + 1) == '%')
142 {
143 // This is an escape sequence so we can actually print a %
144 currentInd = percentInd + 2;
145 theComponents.add("%"); //$NON-NLS-1$
146 }
147 else
148 {
149 // In this case we have an unbracketed placeholder. We will
150 // walk the string until such time as we no longer have a number
151 currentInd = percentInd + 1;
152 while (currentInd < aString.length())
153 {
154 final char val = aString.charAt(currentInd);
155 try
156 {
157 Integer.parseInt(String.valueOf(val));
158 currentInd++;
159 }
160 catch (NumberFormatException nfe)
161 {
162 break;
163 }
164 }

Callers 1

AspectMethod · 0.95

Calls 6

errorPrintLocalisedMethod · 0.95
parseIntMethod · 0.80
indexOfMethod · 0.65
isEmptyMethod · 0.65
addMethod · 0.65
valueOfMethod · 0.45

Tested by

no test coverage detected