Escape '\\', '\'' and '\"', inverting the unescaping performed in #skipUntilEL(). @param input Non-EL input to be escaped @return The escaped version of the input
(String input)
| 261 | * @return The escaped version of the input |
| 262 | */ |
| 263 | private static String escapeELText(String input) { |
| 264 | int len = input.length(); |
| 265 | char quote = 0; |
| 266 | int lastAppend = 0; |
| 267 | int start = 0; |
| 268 | int end = len; |
| 269 | |
| 270 | // Look to see if the value is quoted |
| 271 | String trimmed = input.trim(); |
| 272 | int trimmedLen = trimmed.length(); |
| 273 | if (trimmedLen > 1) { |
| 274 | // Might be quoted |
| 275 | quote = trimmed.charAt(0); |
| 276 | if (quote == '\'' || quote == '\"') { |
| 277 | if (trimmed.charAt(trimmedLen - 1) != quote) { |
| 278 | throw new IllegalArgumentException(Localizer |
| 279 | .getMessage("org.apache.jasper.compiler.ELParser.invalidQuotesForStringLiteral", input)); |
| 280 | } |
| 281 | start = input.indexOf(quote) + 1; |
| 282 | end = start + trimmedLen - 2; |
| 283 | } else { |
| 284 | quote = 0; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | StringBuilder output = null; |
| 289 | for (int i = start; i < end; i++) { |
| 290 | char ch = input.charAt(i); |
| 291 | if (ch == '\\' || ch == quote) { |
| 292 | if (output == null) { |
| 293 | output = new StringBuilder(len + 20); |
| 294 | } |
| 295 | output.append(input, lastAppend, i); |
| 296 | lastAppend = i + 1; |
| 297 | output.append('\\'); |
| 298 | output.append(ch); |
| 299 | } |
| 300 | } |
| 301 | if (output == null) { |
| 302 | return input; |
| 303 | } else { |
| 304 | output.append(input, lastAppend, len); |
| 305 | return output.toString(); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | |
| 310 | /* |