ICU-2899 fix small bugs
X-SVN-Rev: 13053
This commit is contained in:
parent
a82ed5bf21
commit
8152813699
@ -18,6 +18,15 @@
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/parseerr.h"
|
||||
#include "prscmnts.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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; i<MAX_SPLIT_STRINGS; i++){
|
||||
matcher.reset(stringArray[i]);
|
||||
if(matcher.lookingAt(*status)){
|
||||
UnicodeString out = matcher.group(1, *status);
|
||||
@ -100,14 +109,14 @@ getDescription( 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);
|
||||
|
||||
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<MAX_SPLIT_STRINGS; i++){
|
||||
matcher.reset(stringArray[i]);
|
||||
if(matcher.lookingAt(*status)){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(option == UPC_TRANSLATE && count > 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; i<MAX_SPLIT_STRINGS; i++){
|
||||
matcher.reset(stringArray[i]);
|
||||
if(matcher.lookingAt(*status)){
|
||||
if(count == index){
|
||||
UnicodeString out = matcher.group(1, *status);
|
||||
return out.extract(*dest, destCapacity,*status);
|
||||
}
|
||||
count++;
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
U_CFUNC int32_t
|
||||
getTranslate( const UChar* source, int32_t srcLen,
|
||||
UChar** dest, int32_t destCapacity,
|
||||
|
@ -19,6 +19,14 @@
|
||||
#ifndef PRSCMNTS_H
|
||||
#define PRSCMNTS_H 1
|
||||
|
||||
enum UParseCommentsOption {
|
||||
UPC_TRANSLATE,
|
||||
UPC_NOTE,
|
||||
UPC_LIMIT,
|
||||
};
|
||||
|
||||
typedef enum UParseCommentsOption UParseCommentsOption;
|
||||
|
||||
U_CFUNC int32_t
|
||||
getNote(const UChar* source, int32_t srcLen,
|
||||
UChar** dest, int32_t destCapacity,
|
||||
@ -35,5 +43,15 @@ getTranslate( const UChar* source, int32_t srcLen,
|
||||
UChar** dest, int32_t destCapacity,
|
||||
UErrorCode* status);
|
||||
|
||||
U_CFUNC int32_t
|
||||
getAt(const UChar* source, int32_t srcLen,
|
||||
UChar** dest, int32_t destCapacity,
|
||||
int32_t index,
|
||||
UParseCommentsOption option,
|
||||
UErrorCode* status);
|
||||
|
||||
U_CFUNC int32_t
|
||||
getCount(const UChar* source, int32_t srcLen,
|
||||
UParseCommentsOption option, UErrorCode *status);
|
||||
#endif
|
||||
|
||||
|
@ -491,11 +491,12 @@ print(UChar* src, int32_t srcLen,const char *tagStart,const char *tagEnd, UErro
|
||||
}
|
||||
}
|
||||
static void
|
||||
printNote(struct UString *src, UErrorCode *status){
|
||||
printNoteElements(struct UString *src, UErrorCode *status){
|
||||
|
||||
int32_t capacity = 0;
|
||||
UChar* note = NULL;
|
||||
int32_t noteLen = 0;
|
||||
int32_t count = 0,i;
|
||||
|
||||
if(src == NULL){
|
||||
return;
|
||||
@ -504,13 +505,20 @@ printNote(struct UString *src, UErrorCode *status){
|
||||
capacity = src->fLength;
|
||||
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,"<note>", "</note>", 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,"<note>", "</note>", 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user