KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > query > QueryParserUtils


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 final String JavaDoc unEscapeStringLiteral(final String JavaDoc literal) {
28         StringBuffer JavaDoc result = new StringBuffer JavaDoc(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 }
48
Popular Tags