1 |
/* MessageFormat.java - Localized message formatting. |
/* MessageFormat.java - Localized message formatting. |
2 |
Copyright (C) 1999, 2001, 2002, 2004 Free Software Foundation, Inc. |
Copyright (C) 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
193 |
{ |
{ |
194 |
int max = pat.length(); |
int max = pat.length(); |
195 |
buffer.setLength(0); |
buffer.setLength(0); |
196 |
|
boolean quoted = false; |
197 |
for (; index < max; ++index) |
for (; index < max; ++index) |
198 |
{ |
{ |
199 |
char c = pat.charAt(index); |
char c = pat.charAt(index); |
200 |
if (c == '\'' && index + 2 < max && pat.charAt(index + 2) == '\'') |
if (quoted) |
201 |
{ |
{ |
202 |
buffer.append(pat.charAt(index + 1)); |
// In a quoted context, a single quote ends the quoting. |
203 |
index += 2; |
if (c == '\'') |
204 |
|
quoted = false; |
205 |
|
else |
206 |
|
buffer.append(c); |
207 |
} |
} |
208 |
else if (c == '\'' && index + 1 < max |
// Check for '', which is a single quote. |
209 |
&& pat.charAt(index + 1) == '\'') |
else if (c == '\'' && index + 1 < max && pat.charAt(index + 1) == '\'') |
210 |
{ |
{ |
211 |
buffer.append(c); |
buffer.append(c); |
212 |
++index; |
++index; |
213 |
} |
} |
214 |
|
else if (c == '\'') |
215 |
|
{ |
216 |
|
// Start quoting. |
217 |
|
quoted = true; |
218 |
|
} |
219 |
else if (c == '{') |
else if (c == '{') |
220 |
break; |
break; |
|
else if (c == '}') |
|
|
throw new IllegalArgumentException("Found '}' without '{'"); |
|
221 |
else |
else |
222 |
buffer.append(c); |
buffer.append(c); |
223 |
} |
} |
224 |
|
// Note that we explicitly allow an unterminated quote. This is |
225 |
|
// done for compatibility. |
226 |
return index; |
return index; |
227 |
} |
} |
228 |
|
|
234 |
int max = pat.length(); |
int max = pat.length(); |
235 |
buffer.setLength(0); |
buffer.setLength(0); |
236 |
int brace_depth = 1; |
int brace_depth = 1; |
237 |
|
boolean quoted = false; |
238 |
|
|
239 |
for (; index < max; ++index) |
for (; index < max; ++index) |
240 |
{ |
{ |
241 |
char c = pat.charAt(index); |
char c = pat.charAt(index); |
242 |
if (c == '\'' && index + 2 < max && pat.charAt(index + 2) == '\'') |
// First see if we should turn off quoting. |
243 |
|
if (quoted) |
244 |
{ |
{ |
245 |
buffer.append(c); |
if (c == '\'') |
246 |
buffer.append(pat.charAt(index + 1)); |
quoted = false; |
247 |
buffer.append(c); |
// In both cases we fall through to inserting the |
248 |
index += 2; |
// character here. |
249 |
} |
} |
250 |
|
// See if we have just a plain quote to insert. |
251 |
else if (c == '\'' && index + 1 < max |
else if (c == '\'' && index + 1 < max |
252 |
&& pat.charAt(index + 1) == '\'') |
&& pat.charAt(index + 1) == '\'') |
253 |
{ |
{ |
254 |
buffer.append(c); |
buffer.append(c); |
255 |
++index; |
++index; |
256 |
} |
} |
257 |
|
// See if quoting should turn on. |
258 |
|
else if (c == '\'') |
259 |
|
quoted = true; |
260 |
else if (c == '{') |
else if (c == '{') |
261 |
{ |
++brace_depth; |
|
buffer.append(c); |
|
|
++brace_depth; |
|
|
} |
|
262 |
else if (c == '}') |
else if (c == '}') |
263 |
{ |
{ |
264 |
if (--brace_depth == 0) |
if (--brace_depth == 0) |
265 |
break; |
break; |
|
buffer.append(c); |
|
266 |
} |
} |
267 |
// Check for TERM after braces, because TERM might be `}'. |
// Check for TERM after braces, because TERM might be `}'. |
268 |
else if (c == term) |
else if (c == term) |
269 |
break; |
break; |
270 |
else |
// All characters, including opening and closing quotes, are |
271 |
buffer.append(c); |
// inserted here. |
272 |
|
buffer.append(c); |
273 |
} |
} |
274 |
return index; |
return index; |
275 |
} |
} |