/src/logging-log4cxx/src/main/cpp/transform.cpp
| Line | Count | Source | 
| 1 |  | /* | 
| 2 |  |  * Licensed to the Apache Software Foundation (ASF) under one or more | 
| 3 |  |  * contributor license agreements.  See the NOTICE file distributed with | 
| 4 |  |  * this work for additional information regarding copyright ownership. | 
| 5 |  |  * The ASF licenses this file to You under the Apache License, Version 2.0 | 
| 6 |  |  * (the "License"); you may not use this file except in compliance with | 
| 7 |  |  * the License.  You may obtain a copy of the License at | 
| 8 |  |  * | 
| 9 |  |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
| 10 |  |  * | 
| 11 |  |  * Unless required by applicable law or agreed to in writing, software | 
| 12 |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
| 13 |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 14 |  |  * See the License for the specific language governing permissions and | 
| 15 |  |  * limitations under the License. | 
| 16 |  |  */ | 
| 17 |  |  | 
| 18 |  | #include <log4cxx/logstring.h> | 
| 19 |  | #include <log4cxx/helpers/transform.h> | 
| 20 |  | #include <log4cxx/helpers/widelife.h> | 
| 21 |  |  | 
| 22 |  | using namespace LOG4CXX_NS; | 
| 23 |  | using namespace LOG4CXX_NS::helpers; | 
| 24 |  |  | 
| 25 |  |  | 
| 26 |  |  | 
| 27 |  | void Transform::appendEscapingTags( | 
| 28 |  |   LogString& buf, const LogString& input) | 
| 29 | 0 | { | 
| 30 |  |   //Check if the string is zero length -- if so, return | 
| 31 |  |   //what was sent in. | 
| 32 |  | 
 | 
| 33 | 0 |   if (input.length() == 0 ) | 
| 34 | 0 |   { | 
| 35 | 0 |     return; | 
| 36 | 0 |   } | 
| 37 |  |  | 
| 38 | 0 |   logchar specials[] = { 0x22 /* " */, 0x26 /* & */, 0x3C /* < */, 0x3E /* > */, 0x00 }; | 
| 39 | 0 |   size_t start = 0; | 
| 40 | 0 |   size_t special = input.find_first_of(specials, start); | 
| 41 |  | 
 | 
| 42 | 0 |   while (special != LogString::npos) | 
| 43 | 0 |   { | 
| 44 | 0 |     if (special > start) | 
| 45 | 0 |     { | 
| 46 | 0 |       buf.append(input, start, special - start); | 
| 47 | 0 |     } | 
| 48 |  | 
 | 
| 49 | 0 |     switch (input[special]) | 
| 50 | 0 |     { | 
| 51 | 0 |       case 0x22: | 
| 52 | 0 |         buf.append(LOG4CXX_STR(""")); | 
| 53 | 0 |         break; | 
| 54 |  |  | 
| 55 | 0 |       case 0x26: | 
| 56 | 0 |         buf.append(LOG4CXX_STR("&")); | 
| 57 | 0 |         break; | 
| 58 |  |  | 
| 59 | 0 |       case 0x3C: | 
| 60 | 0 |         buf.append(LOG4CXX_STR("<")); | 
| 61 | 0 |         break; | 
| 62 |  |  | 
| 63 | 0 |       case 0x3E: | 
| 64 | 0 |         buf.append(LOG4CXX_STR(">")); | 
| 65 | 0 |         break; | 
| 66 |  |  | 
| 67 | 0 |       default: | 
| 68 | 0 |         buf.append(1, input[special]); | 
| 69 | 0 |         break; | 
| 70 | 0 |     } | 
| 71 |  |  | 
| 72 | 0 |     start = special + 1; | 
| 73 |  | 
 | 
| 74 | 0 |     if (special < input.size()) | 
| 75 | 0 |     { | 
| 76 | 0 |       special = input.find_first_of(specials, start); | 
| 77 | 0 |     } | 
| 78 | 0 |     else | 
| 79 | 0 |     { | 
| 80 | 0 |       special = LogString::npos; | 
| 81 | 0 |     } | 
| 82 | 0 |   } | 
| 83 |  |  | 
| 84 | 0 |   if (start < input.size()) | 
| 85 | 0 |   { | 
| 86 | 0 |     buf.append(input, start, input.size() - start); | 
| 87 | 0 |   } | 
| 88 | 0 | } | 
| 89 |  |  | 
| 90 |  | void Transform::appendEscapingCDATA( | 
| 91 |  |   LogString& buf, const LogString& input) | 
| 92 | 0 | { | 
| 93 | 0 |   static const WideLife<LogString> CDATA_END(LOG4CXX_STR("]]>")); | 
| 94 | 0 |   static const WideLife<LogString> CDATA_EMBEDED_END(LOG4CXX_STR("]]>]]><![CDATA[")); | 
| 95 |  | 
 | 
| 96 | 0 |   const LogString::size_type CDATA_END_LEN = 3; | 
| 97 |  |  | 
| 98 |  | 
 | 
| 99 | 0 |   if (input.length() == 0 ) | 
| 100 | 0 |   { | 
| 101 | 0 |     return; | 
| 102 | 0 |   } | 
| 103 |  |  | 
| 104 | 0 |   LogString::size_type end = input.find(CDATA_END); | 
| 105 |  | 
 | 
| 106 | 0 |   if (end == LogString::npos) | 
| 107 | 0 |   { | 
| 108 | 0 |     buf.append(input); | 
| 109 | 0 |     return; | 
| 110 | 0 |   } | 
| 111 |  |  | 
| 112 | 0 |   LogString::size_type start = 0; | 
| 113 |  | 
 | 
| 114 | 0 |   while (end != LogString::npos) | 
| 115 | 0 |   { | 
| 116 | 0 |     buf.append(input, start, end - start); | 
| 117 | 0 |     buf.append(CDATA_EMBEDED_END); | 
| 118 | 0 |     start = end + CDATA_END_LEN; | 
| 119 |  | 
 | 
| 120 | 0 |     if (start < input.length()) | 
| 121 | 0 |     { | 
| 122 | 0 |       end = input.find(CDATA_END, start); | 
| 123 | 0 |     } | 
| 124 | 0 |     else | 
| 125 | 0 |     { | 
| 126 | 0 |       return; | 
| 127 | 0 |     } | 
| 128 | 0 |   } | 
| 129 |  |  | 
| 130 | 0 |   buf.append(input, start, input.length() - start); | 
| 131 | 0 | } | 
| 132 |  |  |