00001 /******************************************************************************* 00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * - Redistributions of source code must retain the above copyright notice, 00008 * this list of conditions and the following disclaimer. 00009 * 00010 * - Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 00014 * - Neither the name of Vintela, Inc. nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS 00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00028 * POSSIBILITY OF SUCH DAMAGE. 00029 *******************************************************************************/ 00030 00035 /*------------------------------------------------------------------------- 00036 * 00037 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group 00038 * Portions Copyright (c) 1994, Regents of the University of California 00039 * 00040 *------------------------------------------------------------------------- 00041 */ 00042 #include "OW_WQLScanUtils.hpp" 00043 #include "OW_String.hpp" 00044 #include "OW_StringBuffer.hpp" 00045 00046 namespace OW_NAMESPACE 00047 { 00048 00049 String 00050 WQLRemoveStringEscapes(const String& s) 00051 { 00052 if (s.empty()) 00053 { 00054 return s; 00055 } 00056 StringBuffer newStr(s.length()); 00057 int len = s.length(); 00058 for (int i = 0; i < len; i++) 00059 { 00060 if (s[i] == '\'') 00061 { 00062 /* 00063 * Note: if scanner is working right, unescaped quotes can 00064 * only appear in pairs, so there should be another character. 00065 */ 00066 i++; 00067 newStr += s[i]; 00068 } 00069 else if (s[i] == '\\') 00070 { 00071 i++; 00072 switch (s[i]) 00073 { 00074 case 'b': 00075 newStr += '\b'; 00076 break; 00077 case 'f': 00078 newStr += '\f'; 00079 break; 00080 case 'n': 00081 newStr += '\n'; 00082 break; 00083 case 'r': 00084 newStr += '\r'; 00085 break; 00086 case 't': 00087 newStr += '\t'; 00088 break; 00089 case '0': 00090 case '1': 00091 case '2': 00092 case '3': 00093 case '4': 00094 case '5': 00095 case '6': 00096 case '7': 00097 { 00098 int k; 00099 long octVal = 0; 00100 for (k = 0; 00101 s[i + k] >= '0' && s[i + k] <= '7' && k < 3; 00102 k++) 00103 octVal = (octVal << 3) + (s[i + k] - '0'); 00104 i += k - 1; 00105 newStr += (static_cast<char>(octVal)); 00106 } 00107 break; 00108 default: 00109 newStr += s[i]; 00110 break; 00111 } /* switch */ 00112 } /* s[i] == '\\' */ 00113 else 00114 newStr += s[i]; 00115 } 00116 return newStr.releaseString(); 00117 } 00118 00119 } // end namespace OW_NAMESPACE 00120