| 206 | |
| 207 | |
| 208 | std::string util_ConvertMB(const std::string& sIn) |
| 209 | { |
| 210 | #if !USES_MBLEN |
| 211 | return sIn; |
| 212 | #else |
| 213 | cDebug d("cPolicyParser::util_ConvertMB"); |
| 214 | |
| 215 | std::string sOut; |
| 216 | std::string::const_iterator at; |
| 217 | |
| 218 | for (at = sIn.begin(); at != sIn.end(); |
| 219 | // at gets incremented when used.... |
| 220 | ) |
| 221 | { |
| 222 | int nBytes = ::mblen((char*)&at[0], MB_CUR_MAX); |
| 223 | if (nBytes == -1) |
| 224 | { |
| 225 | d.TraceDebug("Unrecognized Character: %c\n", *at); |
| 226 | if ((unsigned char)*at > 0x7F) |
| 227 | { |
| 228 | d.TraceDebug("Normalizing.\n"); |
| 229 | sOut += convert_to_encoded_hex(*(at++)); |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | d.TraceDebug("Incorrectly Formed, Cannot Normalize!\n"); |
| 234 | std::string s(1, *at); |
| 235 | TSTRING ts = cStringUtil::StrToTstr(s); |
| 236 | throw eParserBadCharacter(ts); |
| 237 | } |
| 238 | } |
| 239 | else if (nBytes == 0) |
| 240 | { |
| 241 | break; // done with sIn |
| 242 | } |
| 243 | else if (nBytes == 1) |
| 244 | { |
| 245 | sOut += *(at++); // regular SB char |
| 246 | } |
| 247 | else // ( nBytes > 1 ) |
| 248 | { |
| 249 | // mb char -- output it as encoded bytes |
| 250 | while (nBytes-- > 0) |
| 251 | { |
| 252 | ASSERT(at != sIn.end()); |
| 253 | sOut += convert_to_encoded_hex(*(at++)); |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return sOut; |
| 259 | #endif |
| 260 | } |
no test coverage detected