From 815281369909c7b57941d23c7e5574f0db1c8789 Mon Sep 17 00:00:00 2001 From: Ram Viswanadha Date: Wed, 10 Sep 2003 01:05:44 +0000 Subject: [PATCH] ICU-2899 fix small bugs X-SVN-Rev: 13053 --- icu4c/source/tools/genrb/prscmnts.cpp | 96 +++++++++++++++++++++++++-- icu4c/source/tools/genrb/prscmnts.h | 18 +++++ icu4c/source/tools/genrb/wrtxml.c | 48 ++++++++------ 3 files changed, 137 insertions(+), 25 deletions(-) diff --git a/icu4c/source/tools/genrb/prscmnts.cpp b/icu4c/source/tools/genrb/prscmnts.cpp index f2ec35d4df..d62c5a8ad0 100644 --- a/icu4c/source/tools/genrb/prscmnts.cpp +++ b/icu4c/source/tools/genrb/prscmnts.cpp @@ -18,6 +18,15 @@ #include "unicode/unistr.h" #include "unicode/parseerr.h" #include "prscmnts.h" +#include +#include + +#define MAX_SPLIT_STRINGS 20 + +const char *patternStrings[UPC_LIMIT]={ + "^translate\\s*?(.*)", + "^note\\s*?(.*)" +}; U_CFUNC int32_t removeText(UChar *source, int32_t srcLen, UnicodeString patString,uint32_t options, UErrorCode *status){ @@ -65,20 +74,20 @@ getText(const UChar* source, int32_t srcLen, return 0; } - UnicodeString stringArray[3]; + UnicodeString stringArray[MAX_SPLIT_STRINGS]; RegexPattern *pattern = RegexPattern::compile("@", 0, *status); UnicodeString src = source; if (U_FAILURE(*status)) { return 0; } - pattern->split(src, stringArray, 3, *status); + pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); RegexMatcher matcher(patternString, 0, *status); if (U_FAILURE(*status)) { return 0; } - for(int32_t i=0; i<3; i++){ + for(int32_t i=0; isplit(src, stringArray, 3, *status); + pattern->split(src, stringArray,MAX_SPLIT_STRINGS , *status); if(stringArray[0].indexOf((UChar)AT_SIGN)==-1){ int32_t destLen = stringArray[0].extract(*dest, destCapacity, *status); @@ -116,6 +125,83 @@ getDescription( const UChar* source, int32_t srcLen, return 0; } +U_CFUNC int32_t +getCount(const UChar* source, int32_t srcLen, + UParseCommentsOption option, UErrorCode *status){ + + if(status == NULL || U_FAILURE(*status)){ + return 0; + } + + UnicodeString stringArray[MAX_SPLIT_STRINGS]; + RegexPattern *pattern = RegexPattern::compile("@", 0, *status); + UnicodeString src = source; + + + if (U_FAILURE(*status)) { + return 0; + } + int32_t retLen = pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); + + RegexMatcher matcher(patternStrings[option], 0, *status); + if (U_FAILURE(*status)) { + return 0; + } + int32_t count = 0; + for(int32_t i=0; i 1){ + fprintf(stderr, "Multiple @translate tags cannot be supported.\n"); + exit(U_UNSUPPORTED_ERROR); + } + return count; +} + +U_CFUNC int32_t +getAt(const UChar* source, int32_t srcLen, + UChar** dest, int32_t destCapacity, + int32_t index, + UParseCommentsOption option, + UErrorCode* status){ + + if(status == NULL || U_FAILURE(*status)){ + return 0; + } + + UnicodeString stringArray[MAX_SPLIT_STRINGS]; + RegexPattern *pattern = RegexPattern::compile("@", 0, *status); + UnicodeString src = source; + + + if (U_FAILURE(*status)) { + return 0; + } + int32_t retLen = pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); + + RegexMatcher matcher(patternStrings[option], 0, *status); + if (U_FAILURE(*status)) { + return 0; + } + int32_t count = 0; + for(int32_t i=0; ifLength; note = (UChar*) uprv_malloc(U_SIZEOF_UCHAR * capacity); - noteLen = getNote(src->fChars,src->fLength, ¬e, capacity, status); - - if(noteLen > 0){ - write_tabs(out); - print(note, noteLen,"", "", status); + count = getCount(src->fChars,src->fLength, UPC_NOTE, status); + if(U_FAILURE(*status)){ + return; + } + for(i=0; i < count; i++){ + noteLen = getAt(src->fChars,src->fLength, ¬e, capacity, i, UPC_NOTE, status); + if(U_FAILURE(*status)){ + return; + } + if(noteLen > 0){ + write_tabs(out); + print(note, noteLen,"", "", status); + } } - uprv_free(note); } @@ -612,7 +620,7 @@ string_write_xml(struct SResource *res, const char* id, const char* language, UE T_FileStream_write(out,buf,bufLen); T_FileStream_write(out,valStrEnd,uprv_strlen(valStrEnd)); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); tabCount--; write_tabs(out); @@ -651,7 +659,7 @@ string_write_xml(struct SResource *res, const char* id, const char* language, UE T_FileStream_write(out,valStrEnd,uprv_strlen(valStrEnd)); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); tabCount--; write_tabs(out); @@ -720,7 +728,7 @@ alias_write_xml(struct SResource *res, const char* id, const char* language, UEr T_FileStream_write(out,buf,bufLen); T_FileStream_write(out, endKey, uprv_strlen(endKey)); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); tabCount--; write_tabs(out); @@ -751,7 +759,7 @@ array_write_xml( struct SResource *res, const char* id, const char* language, UE T_FileStream_write(out, "\"", 1); if(res->fComment!=NULL && res->fComment->fChars != NULL){ printComments(res->fComment, sid, FALSE, status); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); }else{ T_FileStream_write(out,">\n", 2); } @@ -765,7 +773,7 @@ array_write_xml( struct SResource *res, const char* id, const char* language, UE T_FileStream_write(out, endKey, uprv_strlen(endKey)); if(res->fComment!=NULL && res->fComment->fChars != NULL){ printComments(res->fComment, sid, FALSE, status); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); }else{ T_FileStream_write(out,">\n", 2); } @@ -837,7 +845,7 @@ intvector_write_xml( struct SResource *res, const char* id, const char* language T_FileStream_write(out, endKey, uprv_strlen(endKey)); if(res->fComment!=NULL && res->fComment->fChars != NULL){ printComments(res->fComment, sid, FALSE, status); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); }else{ T_FileStream_write(out,">\n", 2); } @@ -930,7 +938,7 @@ int_write_xml(struct SResource *res, const char* id, const char* language, UErro T_FileStream_write(out,buf,len); T_FileStream_write(out, valIntEnd, uprv_strlen(valIntEnd)); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); tabCount--; write_tabs(out); T_FileStream_write(out, intEnd, uprv_strlen(intEnd)); @@ -1019,7 +1027,7 @@ bin_write_xml( struct SResource *res, const char* id, const char* language, UErr write_tabs(out); T_FileStream_write(out, valEnd, uprv_strlen(valEnd)); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); tabCount--; write_tabs(out); T_FileStream_write(out,end,uprv_strlen(end)); @@ -1080,7 +1088,7 @@ bin_write_xml( struct SResource *res, const char* id, const char* language, UErr tabCount--; write_tabs(out); T_FileStream_write(out, valEnd, uprv_strlen(valEnd)); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); tabCount--; write_tabs(out); @@ -1134,7 +1142,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr if(res->fComment!=NULL && res->fComment->fChars != NULL){ printComments(res->fComment, sid, FALSE, status); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); }else{ T_FileStream_write(out,">\n", 2); } @@ -1156,7 +1164,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr if(res->fComment!=NULL && res->fComment->fChars != NULL){ printComments(res->fComment, sid, FALSE, status); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); }else{ T_FileStream_write(out,">\n", 2); } @@ -1186,7 +1194,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr if(res->fComment!=NULL && res->fComment->fChars != NULL){ printComments(res->fComment, sid, FALSE, status); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); }else{ T_FileStream_write(out,">\n", 2); } @@ -1201,7 +1209,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr if(res->fComment!=NULL && res->fComment->fChars != NULL){ printComments(res->fComment, sid, FALSE, status); - printNote(res->fComment, status); + printNoteElements(res->fComment, status); }else{ T_FileStream_write(out,">\n", 2); }