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

Method Description

code/src/java/pcgen/core/Description.java:64–141  ·  view source on GitHub ↗

Default constructor. @param aString The description string.

(final String aString)

Source from the content-addressed store, hash-verified

62 * @param aString The description string.
63 */
64 public Description(final String aString)
65 {
66 int currentInd = 0;
67 int percentInd;
68 while ((percentInd = aString.indexOf('%', currentInd)) != -1)
69 {
70 final String preText = aString.substring(currentInd, percentInd);
71 if (!preText.isEmpty())
72 {
73 theComponents.add(preText);
74 }
75 if (percentInd == aString.length() - 1)
76 {
77 theComponents.add("%"); //$NON-NLS-1$
78 return;
79 }
80 if (aString.charAt(percentInd + 1) == '{')
81 {
82 // This is a bracketed placeholder. The replacement parameter
83 // is contained within the {}
84 currentInd = aString.indexOf('}', percentInd + 1) + 1;
85 final String replacement = aString.substring(percentInd + 1, currentInd);
86 // For the time being we will only support numerics here.
87 try
88 {
89 Integer.parseInt(replacement);
90 }
91 catch (NumberFormatException nfe)
92 {
93 Logging.errorPrintLocalised(
94 "Errors.Description.InvalidVariableReplacement", replacement); //$NON-NLS-1$
95 }
96 theComponents.add(VAR_MARKER + replacement);
97 }
98 else if (aString.charAt(percentInd + 1) == '%')
99 {
100 // This is an escape sequence so we can actually print a %
101 currentInd = percentInd + 2;
102 theComponents.add("%"); //$NON-NLS-1$
103 }
104 else
105 {
106 // In this case we have an unbracketed placeholder. We will
107 // walk the string until such time as we no longer have a number
108 currentInd = percentInd + 1;
109 while (currentInd < aString.length())
110 {
111 final char val = aString.charAt(currentInd);
112 try
113 {
114 Integer.parseInt(String.valueOf(val));
115 currentInd++;
116 }
117 catch (NumberFormatException nfe)
118 {
119 break;
120 }
121 }

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected