01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.query;
17:
18: /**
19: * Utility code for the QueryParser, easier to write here then embedded
20: * in the grammer.
21: */
22: final class QueryParserUtils {
23: /**
24: * @param literal a text literal within single quotes, within which single quotes
25: * are escaped by using them double.
26: */
27: public static String unEscapeStringLiteral(final String literal) {
28: StringBuilder result = new StringBuilder(literal.length());
29: boolean inSingleQuote = false;
30: for (int i = 1; i < literal.length() - 1; i++) {
31: char c = literal.charAt(i);
32: switch (c) {
33: case '\'':
34: if (inSingleQuote) {
35: inSingleQuote = false;
36: result.append(c);
37: } else {
38: inSingleQuote = true;
39: }
40: break;
41: default:
42: result.append(c);
43: }
44: }
45: return result.toString();
46: }
47: }
|