OLD | NEW |
1 /***************************************************************************** | 1 /***************************************************************************** |
2 * | 2 * |
3 * Copyright (C) 1999-2013, International Business Machines | 3 * Copyright (C) 1999-2014, International Business Machines |
4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
5 * | 5 * |
6 ******************************************************************************/ | 6 ******************************************************************************/ |
7 | 7 |
8 /* | 8 /* |
9 * uconv(1): an iconv(1)-like converter using ICU. | 9 * uconv(1): an iconv(1)-like converter using ICU. |
10 * | 10 * |
11 * Original code by Jonas Utterström <jonas.utterstrom@vittran.norrnod.se
> | 11 * Original code by Jonas Utterström <jonas.utterstrom@vittran.norrnod.se
> |
12 * contributed in 1999. | 12 * contributed in 1999. |
13 * | 13 * |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #endif | 59 #endif |
60 #endif | 60 #endif |
61 | 61 |
62 #ifdef UCONVMSG_LINK | 62 #ifdef UCONVMSG_LINK |
63 /* below from the README */ | 63 /* below from the README */ |
64 #include "unicode/utypes.h" | 64 #include "unicode/utypes.h" |
65 #include "unicode/udata.h" | 65 #include "unicode/udata.h" |
66 U_CFUNC char uconvmsg_dat[]; | 66 U_CFUNC char uconvmsg_dat[]; |
67 #endif | 67 #endif |
68 | 68 |
69 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) | |
70 | |
71 #define DEFAULT_BUFSZ 4096 | 69 #define DEFAULT_BUFSZ 4096 |
72 #define UCONVMSG "uconvmsg" | 70 #define UCONVMSG "uconvmsg" |
73 | 71 |
74 static UResourceBundle *gBundle = 0; /* Bundle containing messages. */ | 72 static UResourceBundle *gBundle = 0; /* Bundle containing messages. */ |
75 | 73 |
76 /* | 74 /* |
77 * Initialize the message bundle so that message strings can be fetched | 75 * Initialize the message bundle so that message strings can be fetched |
78 * by u_wmsg(). | 76 * by u_wmsg(). |
79 * | 77 * |
80 */ | 78 */ |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 650 |
653 if (translit != NULL && *translit) { | 651 if (translit != NULL && *translit) { |
654 UParseError parse; | 652 UParseError parse; |
655 UnicodeString str(translit), pestr; | 653 UnicodeString str(translit), pestr; |
656 | 654 |
657 /* Create from rules or by ID as needed. */ | 655 /* Create from rules or by ID as needed. */ |
658 | 656 |
659 parse.line = -1; | 657 parse.line = -1; |
660 | 658 |
661 if (uprv_strchr(translit, ':') || uprv_strchr(translit, '>') || uprv_str
chr(translit, '<') || uprv_strchr(translit, '>')) { | 659 if (uprv_strchr(translit, ':') || uprv_strchr(translit, '>') || uprv_str
chr(translit, '<') || uprv_strchr(translit, '>')) { |
662 t = Transliterator::createFromRules("Uconv", str, UTRANS_FORWARD, pa
rse, err); | 660 t = Transliterator::createFromRules(UNICODE_STRING_SIMPLE("Uconv"),
str, UTRANS_FORWARD, parse, err); |
663 } else { | 661 } else { |
664 t = Transliterator::createInstance(translit, UTRANS_FORWARD, err); | 662 t = Transliterator::createInstance(UnicodeString(translit, -1, US_IN
V), UTRANS_FORWARD, err); |
665 } | 663 } |
666 | 664 |
667 if (U_FAILURE(err)) { | 665 if (U_FAILURE(err)) { |
668 str.append((UChar32) 0); | 666 str.append((UChar32) 0); |
669 initMsg(pname); | 667 initMsg(pname); |
670 | 668 |
671 if (parse.line >= 0) { | 669 if (parse.line >= 0) { |
672 UChar linebuf[20], offsetbuf[20]; | 670 UChar linebuf[20], offsetbuf[20]; |
673 uprv_itou(linebuf, 20, parse.line, 10, 0); | 671 uprv_itou(linebuf, 20, parse.line, 10, 0); |
674 uprv_itou(offsetbuf, 20, parse.offset, 10, 0); | 672 uprv_itou(offsetbuf, 20, parse.offset, 10, 0); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 if (err == U_BUFFER_OVERFLOW_ERROR) { | 937 if (err == U_BUFFER_OVERFLOW_ERROR) { |
940 err = U_ZERO_ERROR; | 938 err = U_ZERO_ERROR; |
941 } else if (U_FAILURE(err)) { | 939 } else if (U_FAILURE(err)) { |
942 UChar errorUChars[4]; | 940 UChar errorUChars[4]; |
943 const char *errtag; | 941 const char *errtag; |
944 char pos[32]; | 942 char pos[32]; |
945 UChar32 c; | 943 UChar32 c; |
946 int8_t i, length, errorLength; | 944 int8_t i, length, errorLength; |
947 | 945 |
948 UErrorCode localError = U_ZERO_ERROR; | 946 UErrorCode localError = U_ZERO_ERROR; |
949 errorLength = (int8_t)LENGTHOF(errorUChars); | 947 errorLength = (int8_t)UPRV_LENGTHOF(errorUChars); |
950 ucnv_getInvalidUChars(convto, errorUChars, &errorLength, &lo
calError); | 948 ucnv_getInvalidUChars(convto, errorUChars, &errorLength, &lo
calError); |
951 if (U_FAILURE(localError) || errorLength == 0) { | 949 if (U_FAILURE(localError) || errorLength == 0) { |
952 // need at least 1 so that we don't access beyond the le
ngth of fromoffsets[] | 950 // need at least 1 so that we don't access beyond the le
ngth of fromoffsets[] |
953 errorLength = 1; | 951 errorLength = 1; |
954 } | 952 } |
955 | 953 |
956 int32_t ferroffset; | 954 int32_t ferroffset; |
957 | 955 |
958 if (useOffsets) { | 956 if (useOffsets) { |
959 // Unicode buffer offset of the start of the error UChar
s | 957 // Unicode buffer offset of the start of the error UChar
s |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 | 1386 |
1389 | 1387 |
1390 /* | 1388 /* |
1391 * Hey, Emacs, please set the following: | 1389 * Hey, Emacs, please set the following: |
1392 * | 1390 * |
1393 * Local Variables: | 1391 * Local Variables: |
1394 * indent-tabs-mode: nil | 1392 * indent-tabs-mode: nil |
1395 * End: | 1393 * End: |
1396 * | 1394 * |
1397 */ | 1395 */ |
OLD | NEW |