void DataDrivenNumberFormatTestSuite::showFailure(const UnicodeString &message) { UChar lineStr[20]; uprv_itou( lineStr, UPRV_LENGTHOF(lineStr), (uint32_t) fFileLineNumber, 10, 1); UnicodeString fullMessage("line "); dataerrln(fullMessage.append(lineStr).append(": ") .append(prettify(message))); showLineInfo(); }
static void intToStr( const void *intPtr, UnicodeString &appendTo) { UChar buffer[20]; int32_t x = *static_cast<const int32_t *>(intPtr); UBool neg = FALSE; if (x < 0) { neg = TRUE; x = -x; } if (neg) { appendTo.append(0x2D); } int32_t len = uprv_itou(buffer, UPRV_LENGTHOF(buffer), (uint32_t) x, 10, 1); appendTo.append(buffer, 0, len); }
static void printOutBundle(FILE *out, UConverter *converter, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status) { static const UChar cr[] = { '\n' }; /* int32_t noOfElements = ures_getSize(resource);*/ int32_t i = 0; const char *key = ures_getKey(resource); switch(ures_getType(resource)) { case RES_STRING : { int32_t len=0; const UChar* thestr = ures_getString(resource, &len, status); UChar *string = quotedString(thestr); /* TODO: String truncation */ if(trunc && len > truncsize) { char msg[128]; printIndent(out, converter, indent); sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", (long)len, (long)(truncsize/2)); printCString(out, converter, msg, -1); len = truncsize/2; } printIndent(out, converter, indent); if(key != NULL) { static const UChar openStr[] = { 0x0020, 0x007B, 0x0020, 0x0022 }; /* " { \"" */ static const UChar closeStr[] = { 0x0022, 0x0020, 0x007D }; /* "\" }" */ printCString(out, converter, key, (int32_t)uprv_strlen(key)); printString(out, converter, openStr, (int32_t)(sizeof(openStr)/sizeof(*openStr))); printString(out, converter, string, len); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); } else { static const UChar openStr[] = { 0x0022 }; /* "\"" */ static const UChar closeStr[] = { 0x0022, 0x002C }; /* "\"," */ printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); printString(out, converter, string, (int32_t)(u_strlen(string))); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); } if(verbose) { printCString(out, converter, "// STRING", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); uprv_free(string); } break; case RES_INT : { static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0020, 0x007B, 0x0020 }; /* ":int { " */ static const UChar closeStr[] = { 0x0020, 0x007D }; /* " }" */ UChar num[20]; printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); uprv_itou(num, 20, ures_getInt(resource, status), 10, 0); printString(out, converter, num, u_strlen(num)); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); if(verbose) { printCString(out, converter, "// INT", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); break; } case RES_BINARY : { int32_t len = 0; const int8_t *data = (const int8_t *)ures_getBinary(resource, &len, status); if(trunc && len > truncsize) { char msg[128]; printIndent(out, converter, indent); sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", (long)len, (long)(truncsize/2)); printCString(out, converter, msg, -1); len = truncsize; } if(U_SUCCESS(*status)) { static const UChar openStr[] = { 0x003A, 0x0062, 0x0069, 0x006E, 0x0061, 0x0072, 0x0079, 0x0020, 0x007B, 0x0020 }; /* ":binary { " */ static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); for(i = 0; i<len; i++) { printHex(out, converter, *data++); } printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); if(verbose) { printCString(out, converter, " // BINARY", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); } else { reportError(pname, status, "getting binary value"); } } break; case RES_INT_VECTOR : { int32_t len = 0; const int32_t *data = ures_getIntVector(resource, &len, status); if(U_SUCCESS(*status)) { static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0076, 0x0065, 0x0063, 0x0074, 0x006F, 0x0072, 0x0020, 0x007B, 0x0020 }; /* ":intvector { " */ static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ UChar num[20]; printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); for(i = 0; i < len - 1; i++) { int32_t numLen = uprv_itou(num, 20, data[i], 10, 0); num[numLen++] = 0x002C; /* ',' */ num[numLen++] = 0x0020; /* ' ' */ num[numLen] = 0; printString(out, converter, num, u_strlen(num)); } if(len > 0) { uprv_itou(num, 20, data[len - 1], 10, 0); printString(out, converter, num, u_strlen(num)); } printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); if(verbose) { printCString(out, converter, "// INTVECTOR", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); } else { reportError(pname, status, "getting int vector"); } } break; case RES_TABLE : case RES_ARRAY : { static const UChar openStr[] = { 0x007B }; /* "{" */ static const UChar closeStr[] = { 0x007D, '\n' }; /* "}\n" */ UResourceBundle *t = NULL; ures_resetIterator(resource); printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); if(verbose) { if(ures_getType(resource) == RES_TABLE) { printCString(out, converter, "// TABLE", -1); } else { printCString(out, converter, "// ARRAY", -1); } } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); if(suppressAliases == FALSE) { while(U_SUCCESS(*status) && ures_hasNext(resource)) { t = ures_getNextResource(resource, t, status); if(U_SUCCESS(*status)) { printOutBundle(out, converter, t, indent+indentsize, pname, status); } else { reportError(pname, status, "While processing table"); *status = U_ZERO_ERROR; } } } else { /* we have to use low level access to do this */ Resource r = RES_BOGUS; for(i = 0; i < ures_getSize(resource); i++) { /* need to know if it's an alias */ if(ures_getType(resource) == RES_TABLE) { r = derb_getTableItem(resource->fResData.pRoot, resource->fRes, (int16_t)i); key = derb_getTableKey(resource->fResData.pRoot, resource->fRes, (int16_t)i); } else { r = derb_getArrayItem(resource->fResData.pRoot, resource->fRes, i); } if(U_SUCCESS(*status)) { if(RES_GET_TYPE(r) == RES_ALIAS) { printOutAlias(out, converter, resource, r, key, indent+indentsize, pname, status); } else { t = ures_getByIndex(resource, i, t, status); printOutBundle(out, converter, t, indent+indentsize, pname, status); } } else { reportError(pname, status, "While processing table"); *status = U_ZERO_ERROR; } } } printIndent(out, converter, indent); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); ures_close(t); } break; default: break; } }
// Convert a file from one encoding to another static UBool convertFile(const char *pname, const char *fromcpage, UConverterToUCallback toucallback, const void *touctxt, const char *tocpage, UConverterFromUCallback fromucallback, const void *fromuctxt, int fallback, size_t bufsz, const char *translit, const char *infilestr, FILE * outfile, int verbose) { FILE *infile; UBool ret = TRUE; UConverter *convfrom = 0; UConverter *convto = 0; UErrorCode err = U_ZERO_ERROR; UBool flush; const char *cbufp; char *bufp; char *buf = 0; uint32_t infoffset = 0, outfoffset = 0; /* Where we are in the file, for error reporting. */ const UChar *unibufbp; UChar *unibufp; UChar *unibuf = 0; int32_t *fromoffsets = 0, *tooffsets = 0; size_t rd, wr, tobufsz; #if !UCONFIG_NO_TRANSLITERATION Transliterator *t = 0; // Transliterator acting on Unicode data. #endif UnicodeString u; // String to do the transliteration. // Open the correct input file or connect to stdin for reading input if (infilestr != 0 && strcmp(infilestr, "-")) { infile = fopen(infilestr, "rb"); if (infile == 0) { UnicodeString str1(infilestr, ""); str1.append((UChar32) 0); UnicodeString str2(strerror(errno), ""); str2.append((UChar32) 0); initMsg(pname); u_wmsg(stderr, "cantOpenInputF", str1.getBuffer(), str2.getBuffer()); return FALSE; } } else { infilestr = "-"; infile = stdin; #ifdef WIN32 if (setmode(fileno(stdin), O_BINARY) == -1) { initMsg(pname); u_wmsg(stderr, "cantSetInBinMode"); return FALSE; } #endif } if (verbose) { fprintf(stderr, "%s:\n", infilestr); } #if !UCONFIG_NO_TRANSLITERATION // Create transliterator as needed. if (translit != NULL && *translit) { UParseError parse; UnicodeString str(translit), pestr; /* Create from rules or by ID as needed. */ parse.line = -1; if (uprv_strchr(translit, ':') || uprv_strchr(translit, '>') || uprv_strchr(translit, '<') || uprv_strchr(translit, '>')) { t = Transliterator::createFromRules("Uconv", str, UTRANS_FORWARD, parse, err); } else { t = Transliterator::createInstance(translit, UTRANS_FORWARD, err); } if (U_FAILURE(err)) { str.append((UChar32) 0); initMsg(pname); if (parse.line >= 0) { UChar linebuf[20], offsetbuf[20]; uprv_itou(linebuf, 20, parse.line, 10, 0); uprv_itou(offsetbuf, 20, parse.offset, 10, 0); u_wmsg(stderr, "cantCreateTranslitParseErr", str.getBuffer(), u_wmsg_errorName(err), linebuf, offsetbuf); } else { u_wmsg(stderr, "cantCreateTranslit", str.getBuffer(), u_wmsg_errorName(err)); } if (t) { delete t; t = 0; } goto error_exit; } } #endif // Create codepage converter. If the codepage or its aliases weren't // available, it returns NULL and a failure code. We also set the // callbacks, and return errors in the same way. convfrom = ucnv_open(fromcpage, &err); if (U_FAILURE(err)) { UnicodeString str(fromcpage, (int32_t)(uprv_strlen(fromcpage) + 1)); initMsg(pname); u_wmsg(stderr, "cantOpenFromCodeset", str.getBuffer(), u_wmsg_errorName(err)); goto error_exit; } ucnv_setToUCallBack(convfrom, toucallback, touctxt, 0, 0, &err); if (U_FAILURE(err)) { initMsg(pname); u_wmsg(stderr, "cantSetCallback", u_wmsg_errorName(err)); goto error_exit; } convto = ucnv_open(tocpage, &err); if (U_FAILURE(err)) { UnicodeString str(tocpage, (int32_t)(uprv_strlen(tocpage) + 1)); initMsg(pname); u_wmsg(stderr, "cantOpenToCodeset", str.getBuffer(), u_wmsg_errorName(err)); goto error_exit; } ucnv_setFromUCallBack(convto, fromucallback, fromuctxt, 0, 0, &err); if (U_FAILURE(err)) { initMsg(pname); u_wmsg(stderr, "cantSetCallback", u_wmsg_errorName(err)); goto error_exit; } ucnv_setFallback(convto, fallback); // To ensure that the buffer always is of enough size, we // must take the worst case scenario, that is the character in // the codepage that uses the most bytes and multiply it against // the buffer size. // use bufsz+1 to allow for additional BOM/signature character (U+FEFF) tobufsz = (bufsz+1) * ucnv_getMaxCharSize(convto); buf = new char[tobufsz]; unibuf = new UChar[bufsz]; fromoffsets = new int32_t[bufsz]; tooffsets = new int32_t[tobufsz]; // OK, we can convert now. do { char willexit = 0; rd = fread(buf, 1, bufsz, infile); if (ferror(infile) != 0) { UnicodeString str(strerror(errno)); str.append((UChar32) 0); initMsg(pname); u_wmsg(stderr, "cantRead", str.getBuffer()); goto error_exit; } // Convert the read buffer into the new coding // After the call 'unibufp' will be placed on the last // character that was converted in the 'unibuf'. // Also the 'cbufp' is positioned on the last converted // character. // At the last conversion in the file, flush should be set to // true so that we get all characters converted // // The converter must be flushed at the end of conversion so // that characters on hold also will be written. unibufp = unibuf; cbufp = buf; flush = rd != bufsz; ucnv_toUnicode(convfrom, &unibufp, unibufp + bufsz, &cbufp, cbufp + rd, fromoffsets, flush, &err); infoffset += (uint32_t)(cbufp - buf); if (U_FAILURE(err)) { char pos[32]; sprintf(pos, "%u", infoffset - 1); UnicodeString str(pos, (int32_t)(uprv_strlen(pos) + 1)); initMsg(pname); u_wmsg(stderr, "problemCvtToU", str.getBuffer(), u_wmsg_errorName(err)); willexit = 1; err = U_ZERO_ERROR; /* reset the error for the rest of the conversion. */ } // At the last conversion, the converted characters should be // equal to number of chars read. if (flush && !willexit && cbufp != (buf + rd)) { char pos[32]; sprintf(pos, "%u", infoffset); UnicodeString str(pos, (int32_t)(uprv_strlen(pos) + 1)); initMsg(pname); u_wmsg(stderr, "premEndInput", str.getBuffer()); willexit = 1; } // Prepare to transliterate and convert. Transliterate if needed. #if !UCONFIG_NO_TRANSLITERATION if (t) { u.setTo(unibuf, (int32_t)(unibufp - unibuf)); // Copy into string. t->transliterate(u); } else #endif { u.setTo(unibuf, (int32_t)(unibufp - unibuf), (int32_t)(bufsz)); // Share the buffer. } int32_t ulen = u.length(); // Convert the Unicode buffer into the destination codepage // Again 'bufp' will be placed on the last converted character // And 'unibufbp' will be placed on the last converted unicode character // At the last conversion flush should be set to true to ensure that // all characters left get converted const UChar *unibufu = unibufbp = u.getBuffer(); do { int32_t len = ulen > (int32_t)bufsz ? (int32_t)bufsz : ulen; bufp = buf; unibufp = (UChar *) (unibufbp + len); ucnv_fromUnicode(convto, &bufp, bufp + tobufsz, &unibufbp, unibufp, tooffsets, flush, &err); if (U_FAILURE(err)) { const char *errtag; char pos[32]; uint32_t erroffset = dataOffset((int32_t)(bufp - buf - 1), fromoffsets, (int32_t)(bufsz), tooffsets, (int32_t)(tobufsz)); int32_t ferroffset = (int32_t)(infoffset - (unibufp - unibufu) + erroffset); if ((int32_t) ferroffset < 0) { ferroffset = (int32_t)(outfoffset + (bufp - buf)); errtag = "problemCvtFromUOut"; } else { errtag = "problemCvtFromU"; } sprintf(pos, "%u", ferroffset); UnicodeString str(pos, (int32_t)(uprv_strlen(pos) + 1)); initMsg(pname); u_wmsg(stderr, errtag, str.getBuffer(), u_wmsg_errorName(err)); willexit = 1; } // At the last conversion, the converted characters should be equal to number // of consumed characters. if (flush && !willexit && unibufbp != (unibufu + (size_t) (unibufp - unibufu))) { char pos[32]; sprintf(pos, "%u", infoffset); UnicodeString str(pos, (int32_t)(uprv_strlen(pos) + 1)); initMsg(pname); u_wmsg(stderr, "premEnd", str.getBuffer()); willexit = 1; } // Finally, write the converted buffer to the output file rd = (size_t) (bufp - buf); outfoffset += (int32_t)(wr = fwrite(buf, 1, rd, outfile)); if (wr != rd) { UnicodeString str(strerror(errno), ""); initMsg(pname); u_wmsg(stderr, "cantWrite", str.getBuffer()); willexit = 1; } if (willexit) { goto error_exit; } } while ((ulen -= (int32_t)(bufsz)) > 0); } while (!flush); // Stop when we have flushed the // converters (this means that it's // the end of output) goto normal_exit; error_exit: ret = FALSE; normal_exit: // Cleanup. if (convfrom) ucnv_close(convfrom); if (convto) ucnv_close(convto); #if !UCONFIG_NO_TRANSLITERATION if (t) delete t; #endif if (buf) delete[] buf; if (unibuf) delete[] unibuf; if (fromoffsets) delete[] fromoffsets; if (tooffsets) delete[] tooffsets; if (infile != stdin) { fclose(infile); } return ret; }
/*uses uprv_itou to get a unicode escape sequence of the offensive sequence, *and uses that as the substitution sequence */ U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_ESCAPE ( const void *context, UConverterToUnicodeArgs *toArgs, const char* codeUnits, int32_t length, UConverterCallbackReason reason, UErrorCode * err) { UChar uniValueString[VALUE_STRING_LENGTH]; int32_t valueStringLength = 0; int32_t i = 0; if (reason > UCNV_IRREGULAR) { return; } if(context==NULL) { while (i < length) { uniValueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */ uniValueString[valueStringLength++] = (UChar) UNICODE_X_CODEPOINT; /* adding X */ valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t) codeUnits[i++], 16, 2); } } else { switch(*((char*)context)) { case UCNV_PRV_ESCAPE_XML_DEC: while (i < length) { uniValueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */ uniValueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */ valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t)codeUnits[i++], 10, 0); uniValueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */ } break; case UCNV_PRV_ESCAPE_XML_HEX: while (i < length) { uniValueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */ uniValueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */ uniValueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */ valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t)codeUnits[i++], 16, 0); uniValueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */ } break; case UCNV_PRV_ESCAPE_C: while (i < length) { uniValueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */ uniValueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */ valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t)codeUnits[i++], 16, 2); } break; default: while (i < length) { uniValueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */ uniValueString[valueStringLength++] = (UChar) UNICODE_X_CODEPOINT; /* adding X */ uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t) codeUnits[i++], 16, 2); valueStringLength += 2; } } } /* reset the error */ *err = U_ZERO_ERROR; ucnv_cbToUWriteUChars(toArgs, uniValueString, valueStringLength, 0, err); }
/*uses uprv_itou to get a unicode escape sequence of the offensive sequence, *uses a clean copy (resetted) of the converter, to convert that unicode *escape sequence to the target codepage (if conversion failure happens then *we revert to substituting with subchar) */ U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_ESCAPE ( const void *context, UConverterFromUnicodeArgs *fromArgs, const UChar *codeUnits, int32_t length, UChar32 codePoint, UConverterCallbackReason reason, UErrorCode * err) { UChar valueString[VALUE_STRING_LENGTH]; int32_t valueStringLength = 0; int32_t i = 0; const UChar *myValueSource = NULL; UErrorCode err2 = U_ZERO_ERROR; UConverterFromUCallback original = NULL; const void *originalContext; UConverterFromUCallback ignoredCallback = NULL; const void *ignoredContext; if (reason > UCNV_IRREGULAR) { return; } ucnv_setFromUCallBack (fromArgs->converter, (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE, NULL, &original, &originalContext, &err2); if (U_FAILURE (err2)) { *err = err2; return; } if(context==NULL) { while (i < length) { valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */ valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[i++], 16, 4); } } else { switch(*((char*)context)) { case UCNV_PRV_ESCAPE_JAVA: while (i < length) { valueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */ valueString[valueStringLength++] = (UChar) UNICODE_U_LOW_CODEPOINT; /* adding u */ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[i++], 16, 4); } break; case UCNV_PRV_ESCAPE_C: valueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */ if(length==2){ valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 8); } else{ valueString[valueStringLength++] = (UChar) UNICODE_U_LOW_CODEPOINT; /* adding u */ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 16, 4); } break; case UCNV_PRV_ESCAPE_XML_DEC: valueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */ valueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */ if(length==2){ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 10, 0); } else{ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 10, 0); } valueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */ break; case UCNV_PRV_ESCAPE_XML_HEX: valueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */ valueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */ valueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */ if(length==2){ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 0); } else{ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 16, 0); } valueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */ break; case UCNV_PRV_ESCAPE_UNICODE: valueString[valueStringLength++] = (UChar) UNICODE_LEFT_CURLY_CODEPOINT; /* adding { */ valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */ valueString[valueStringLength++] = (UChar) UNICODE_PLUS_CODEPOINT; /* adding + */ if (length == 2) { valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 4); } else { valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 16, 4); } valueString[valueStringLength++] = (UChar) UNICODE_RIGHT_CURLY_CODEPOINT; /* adding } */ break; case UCNV_PRV_ESCAPE_CSS2: valueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 0); /* Always add space character, becase the next character might be whitespace, which would erroneously be considered the termination of the escape sequence. */ valueString[valueStringLength++] = (UChar) UNICODE_SPACE_CODEPOINT; break; default: while (i < length) { valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */ valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[i++], 16, 4); } } } myValueSource = valueString; /* reset the error */ *err = U_ZERO_ERROR; ucnv_cbFromUWriteUChars(fromArgs, &myValueSource, myValueSource+valueStringLength, 0, err); ucnv_setFromUCallBack (fromArgs->converter, original, originalContext, &ignoredCallback, &ignoredContext, &err2); if (U_FAILURE (err2)) { *err = err2; return; } return; }
/** * Convert an integer value to a string and append the result to * the given UnicodeString. */ static UnicodeString& itos(int32_t i, UnicodeString& appendTo) { UChar temp[16]; uprv_itou(temp,16,i,10,0); // 10 == radix appendTo.append(temp); return appendTo; }
void RuleChain::dumpRules(UnicodeString& result) { UChar digitString[16]; if ( ruleHeader != NULL ) { result += keyword; OrConstraint* orRule=ruleHeader; while ( orRule != NULL ) { AndConstraint* andRule=orRule->childNode; while ( andRule != NULL ) { if ( (andRule->op==AndConstraint::NONE) && (andRule->rangeHigh==-1) ) { result += UNICODE_STRING_SIMPLE(" n is "); if (andRule->notIn) { result += UNICODE_STRING_SIMPLE("not "); } uprv_itou(digitString,16, andRule->rangeLow,10,0); result += UnicodeString(digitString); } else { if (andRule->op==AndConstraint::MOD) { result += UNICODE_STRING_SIMPLE(" n mod "); uprv_itou(digitString,16, andRule->opNum,10,0); result += UnicodeString(digitString); } else { result += UNICODE_STRING_SIMPLE(" n "); } if (andRule->rangeHigh==-1) { if (andRule->notIn) { result += UNICODE_STRING_SIMPLE(" is not "); uprv_itou(digitString,16, andRule->rangeLow,10,0); result += UnicodeString(digitString); } else { result += UNICODE_STRING_SIMPLE(" is "); uprv_itou(digitString,16, andRule->rangeLow,10,0); result += UnicodeString(digitString); } } else { if (andRule->notIn) { if ( andRule->integerOnly ) { result += UNICODE_STRING_SIMPLE(" not in "); } else { result += UNICODE_STRING_SIMPLE(" not within "); } uprv_itou(digitString,16, andRule->rangeLow,10,0); result += UnicodeString(digitString); result += UNICODE_STRING_SIMPLE(" .. "); uprv_itou(digitString,16, andRule->rangeHigh,10,0); result += UnicodeString(digitString); } else { if ( andRule->integerOnly ) { result += UNICODE_STRING_SIMPLE(" in "); } else { result += UNICODE_STRING_SIMPLE(" within "); } uprv_itou(digitString,16, andRule->rangeLow,10,0); result += UnicodeString(digitString); result += UNICODE_STRING_SIMPLE(" .. "); uprv_itou(digitString,16, andRule->rangeHigh,10,0); } } } if ( (andRule=andRule->next) != NULL) { result.append(PK_AND, 3); } } if ( (orRule = orRule->next) != NULL ) { result.append(PK_OR, 2); } } } if ( next != NULL ) { next->dumpRules(result); } }