Lines 115-138
Link Here
|
115 |
// for compatibility with MessageFormat which eliminates double quotes in original message |
115 |
// for compatibility with MessageFormat which eliminates double quotes in original message |
116 |
char[] messageWithNoDoubleQuotes = |
116 |
char[] messageWithNoDoubleQuotes = |
117 |
CharOperation.replace(message.toCharArray(), DOUBLE_QUOTES, SINGLE_QUOTE); |
117 |
CharOperation.replace(message.toCharArray(), DOUBLE_QUOTES, SINGLE_QUOTE); |
118 |
message = new String(messageWithNoDoubleQuotes); |
118 |
|
119 |
if (bindings == null) return message; |
119 |
if (bindings == null) return new String(messageWithNoDoubleQuotes); |
120 |
|
120 |
|
121 |
int length = message.length(); |
121 |
int length = messageWithNoDoubleQuotes.length; |
122 |
int start = -1; |
122 |
int start = 0; |
123 |
int end = length; |
123 |
int end = length; |
124 |
StringBuffer output = null; |
124 |
StringBuffer output = null; |
125 |
while (true) { |
125 |
while (true) { |
126 |
if ((end = message.indexOf('{', start)) > -1) { |
126 |
if ((end = CharOperation.indexOf('{', messageWithNoDoubleQuotes, start)) > -1) { |
127 |
if (output == null) output = new StringBuffer(80); |
127 |
if (output == null) output = new StringBuffer(length); |
128 |
output.append(message.substring(start + 1, end)); |
128 |
output.append(messageWithNoDoubleQuotes, start, end - start); |
129 |
if ((start = message.indexOf('}', end)) > -1) { |
129 |
if ((start = CharOperation.indexOf('}', messageWithNoDoubleQuotes, end + 1)) > -1) { |
130 |
int index = -1; |
130 |
int index = -1; |
|
|
131 |
String argId = new String(messageWithNoDoubleQuotes, end + 1, start - end - 1); |
131 |
try { |
132 |
try { |
132 |
index = Integer.parseInt(message.substring(end + 1, start)); |
133 |
index = Integer.parseInt(argId); |
133 |
output.append(bindings[index]); |
134 |
output.append(bindings[index]); |
134 |
} catch (NumberFormatException nfe) { // could be nested message ID {compiler.name} |
135 |
} catch (NumberFormatException nfe) { // could be nested message ID {compiler.name} |
135 |
String argId = message.substring(end + 1, start); |
|
|
136 |
boolean done = false; |
136 |
boolean done = false; |
137 |
if (!id.equals(argId)) { |
137 |
if (!id.equals(argId)) { |
138 |
String argMessage = null; |
138 |
String argMessage = null; |
Lines 144-164
Link Here
|
144 |
// unable to bind argument, ignore (will leave argument in) |
144 |
// unable to bind argument, ignore (will leave argument in) |
145 |
} |
145 |
} |
146 |
} |
146 |
} |
147 |
if (!done) output.append(message.substring(end + 1, start + 1)); |
147 |
if (!done) output.append(messageWithNoDoubleQuotes, end + 1, start - end); |
148 |
} catch (ArrayIndexOutOfBoundsException e) { |
148 |
} catch (ArrayIndexOutOfBoundsException e) { |
149 |
output.append("{missing " + Integer.toString(index) + "}"); //$NON-NLS-2$ //$NON-NLS-1$ |
149 |
output.append("{missing " + Integer.toString(index) + "}"); //$NON-NLS-2$ //$NON-NLS-1$ |
150 |
} |
150 |
} |
|
|
151 |
start++; |
151 |
} else { |
152 |
} else { |
152 |
output.append(message.substring(end, length)); |
153 |
output.append(messageWithNoDoubleQuotes, end, length); |
153 |
break; |
154 |
break; |
154 |
} |
155 |
} |
155 |
} else { |
156 |
} else { |
156 |
if (output == null) return message; |
157 |
if (output == null) return new String(messageWithNoDoubleQuotes); |
157 |
output.append(message.substring(start + 1, length)); |
158 |
output.append(messageWithNoDoubleQuotes, start, length - start); |
158 |
break; |
159 |
break; |
159 |
} |
160 |
} |
160 |
} |
161 |
} |
161 |
return output.toString(); |
162 |
return output.toString(); |
162 |
} |
163 |
} |
163 |
|
164 |
|
164 |
/** |
165 |
/** |