X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..efa1e6592fb03ce23b15276b2b91d885a3ee7da5:/icuSources/tools/toolutil/uparse.c diff --git a/icuSources/tools/toolutil/uparse.c b/icuSources/tools/toolutil/uparse.c index 9f31e74a..5878597a 100644 --- a/icuSources/tools/toolutil/uparse.c +++ b/icuSources/tools/toolutil/uparse.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2000-2003, International Business Machines +* Copyright (C) 2000-2012, 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,11 +240,12 @@ 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)) { *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; + return 0; } if(pFirst!=NULL) { @@ -226,21 +268,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 +293,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 +319,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,80 +339,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 const UChar * U_EXPORT2 -u_strSkipWhiteSpace(const UChar *s, int32_t length) { - int32_t i = 0, toReturn = 0; - UChar32 c = 0; - if(s == NULL) { - return NULL; - } - if(length == 0) { - return s; - } - if(length > 0) { - for(;;) { - if(i >= length) { - break; - } - toReturn = i; - U16_NEXT(s, i, length, c); - if(!(c == 0x20 || u_isUWhiteSpace(c))) { - break; - } - } - } else { - for(;;) { - toReturn = i; - U16_NEXT(s, i, length, c); - if(!(c == 0x20 || u_isUWhiteSpace(c)) || c == 0) { - break; - } - } - } - return s+toReturn; -} - - -U_CAPI const UChar * U_EXPORT2 -u_strTrailingWhiteSpaceStart(const UChar *s, int32_t length) { - int32_t i = 0, toReturn = 0; - UChar32 c = 0; - - if(s == NULL) { - return NULL; - } - if(length == 0) { - return s; - } - - if(length < 0) { - length = u_strlen(s); - } - - i = length; - for(;;) { - toReturn = i; - if(i <= 0) { - break; - } - U16_PREV(s, 0, i, c); - if(!(c == 0x20 || u_isUWhiteSpace(c))) { - break; +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 s+toReturn; + return rangeLength; } U_CAPI int32_t U_EXPORT2 @@ -385,7 +366,7 @@ u_parseUTF8(const char *source, int32_t sLen, char *dest, int32_t destCapacity, int32_t i = 0; unsigned int value = 0; if(sLen == -1) { - sLen = strlen(source); + sLen = (int32_t)strlen(source); } while(read < source+sLen) {