X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..4388f060552cc537e71e957d32f35e9d75a61233:/icuSources/tools/toolutil/uparse.c diff --git a/icuSources/tools/toolutil/uparse.c b/icuSources/tools/toolutil/uparse.c index 0a49ecb9..3d098cbf 100644 --- a/icuSources/tools/toolutil/uparse.c +++ b/icuSources/tools/toolutil/uparse.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2000-2004, International Business Machines +* Copyright (C) 2000-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -19,23 +19,56 @@ */ #include "unicode/utypes.h" +#include "unicode/uchar.h" +#include "unicode/ustring.h" +#include "unicode/utf16.h" #include "cstring.h" #include "filestrm.h" #include "uparse.h" -#include "unicode/uchar.h" -#include "unicode/ustring.h" #include "ustr_imp.h" #include U_CAPI const char * U_EXPORT2 u_skipWhitespace(const char *s) { - while(*s==' ' || *s=='\t') { + while(U_IS_INV_WHITESPACE(*s)) { ++s; } return s; } +U_CAPI char * U_EXPORT2 +u_rtrim(char *s) { + char *end=uprv_strchr(s, 0); + while(s0 && (line[length-1]=='\r' || line[length-1]=='\n')) { - line[--length]=0; + length=(int32_t)(u_rtrim(line)-line); + + /* + * detect a line with # @missing: + * start parsing after that, or else from the beginning of the line + * set the default warning for @missing lines + */ + start=(char *)getMissingLimit(line); + if(start==line) { + *pErrorCode=U_ZERO_ERROR; + } else { + *pErrorCode=U_USING_DEFAULT_WARNING; } /* skip this line if it is empty or a comment */ - if(line[0]==0 || line[0]=='#') { + if(*start==0 || *start=='#') { continue; } /* remove in-line comments */ - limit=uprv_strchr(line, '#'); + limit=uprv_strchr(start, '#'); if(limit!=NULL) { /* get white space before the pound sign */ - while(limit>line && (*(limit-1)==' ' || *(limit-1)=='\t')) { + while(limit>start && U_IS_INV_WHITESPACE(*(limit-1))) { --limit; } @@ -92,12 +133,11 @@ u_parseDelimitedFile(const char *filename, char delimiter, } /* skip lines with only whitespace */ - if(u_skipWhitespace(line)[0]==0) { + if(u_skipWhitespace(start)[0]==0) { continue; } /* for each field, call the corresponding field function */ - start=line; for(i=0; i0 && dest==NULL)) { *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; + return 0; } count=0; @@ -167,7 +208,7 @@ u_parseCodePoints(const char *s, /* read one code point */ value=(uint32_t)uprv_strtoul(s, &end, 16); - if(end<=s || (*end!=' ' && *end!='\t' && *end!=';' && *end!=0) || value>=0x110000) { + if(end<=s || (!U_IS_INV_WHITESPACE(*end) && *end!=';' && *end!=0) || value>=0x110000) { *pErrorCode=U_PARSE_ERROR; return 0; } @@ -199,7 +240,7 @@ u_parseString(const char *s, uint32_t value; int32_t destLength; - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { + if(U_FAILURE(*pErrorCode)) { return 0; } if(s==NULL || destCapacity<0 || (destCapacity>0 && dest==NULL)) { @@ -226,21 +267,22 @@ u_parseString(const char *s, /* read one code point */ value=(uint32_t)uprv_strtoul(s, &end, 16); - if(end<=s || (*end!=' ' && *end!='\t' && *end!=';' && *end!=0) || value>=0x110000) { + if(end<=s || (!U_IS_INV_WHITESPACE(*end) && *end!=';' && *end!=0) || value>=0x110000) { *pErrorCode=U_PARSE_ERROR; return 0; } /* store the first code point */ - if(destLength==0 && pFirst!=NULL) { + if(pFirst!=NULL) { *pFirst=value; + pFirst=NULL; } /* append it to the destination array */ - if((destLength+UTF_CHAR_LENGTH(value))<=destCapacity) { - UTF_APPEND_CHAR_UNSAFE(dest, destLength, value); + if((destLength+U16_LENGTH(value))<=destCapacity) { + U16_APPEND_UNSAFE(dest, destLength, value); } else { - destLength+=UTF_CHAR_LENGTH(value); + destLength+=U16_LENGTH(value); } /* go to the following characters */ @@ -250,28 +292,25 @@ u_parseString(const char *s, /* read a range like start or start..end */ U_CAPI int32_t U_EXPORT2 -u_parseCodePointRange(const char *s, - uint32_t *pStart, uint32_t *pEnd, - UErrorCode *pErrorCode) { +u_parseCodePointRangeAnyTerminator(const char *s, + uint32_t *pStart, uint32_t *pEnd, + const char **terminator, + UErrorCode *pErrorCode) { char *end; uint32_t value; - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { + if(U_FAILURE(*pErrorCode)) { return 0; } if(s==NULL || pStart==NULL || pEnd==NULL) { *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; - } - - s=u_skipWhitespace(s); - if(*s==';' || *s==0) { - *pErrorCode=U_PARSE_ERROR; return 0; } /* read the start code point */ + s=u_skipWhitespace(s); value=(uint32_t)uprv_strtoul(s, &end, 16); - if(end<=s || (*end!=' ' && *end!='\t' && *end!='.' && *end!=';') || value>=0x110000) { + if(end<=s || value>=0x110000) { *pErrorCode=U_PARSE_ERROR; return 0; } @@ -279,19 +318,15 @@ u_parseCodePointRange(const char *s, /* is there a "..end"? */ s=u_skipWhitespace(end); - if(*s==';' || *s==0) { - return 1; - } - if(*s!='.' || s[1]!='.') { - *pErrorCode=U_PARSE_ERROR; - return 0; + *terminator=end; + return 1; } - s+=2; + s=u_skipWhitespace(s+2); /* read the end code point */ value=(uint32_t)uprv_strtoul(s, &end, 16); - if(end<=s || (*end!=' ' && *end!='\t' && *end!=';') || value>=0x110000) { + if(end<=s || value>=0x110000) { *pErrorCode=U_PARSE_ERROR; return 0; } @@ -303,14 +338,25 @@ u_parseCodePointRange(const char *s, return 0; } - /* no garbage after that? */ - s=u_skipWhitespace(end); - if(*s==';' || *s==0) { - return value-*pStart+1; - } else { - *pErrorCode=U_PARSE_ERROR; - return 0; + *terminator=end; + return value-*pStart+1; +} + +U_CAPI int32_t U_EXPORT2 +u_parseCodePointRange(const char *s, + uint32_t *pStart, uint32_t *pEnd, + UErrorCode *pErrorCode) { + const char *terminator; + int32_t rangeLength= + u_parseCodePointRangeAnyTerminator(s, pStart, pEnd, &terminator, pErrorCode); + if(U_SUCCESS(*pErrorCode)) { + terminator=u_skipWhitespace(terminator); + if(*terminator!=';' && *terminator!=0) { + *pErrorCode=U_PARSE_ERROR; + return 0; + } } + return rangeLength; } U_CAPI int32_t U_EXPORT2