From 7801efa305b8659372ce766c46ea1168fed767cb Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Thu, 14 Mar 2002 00:40:08 +0000 Subject: [PATCH] ICU-1718 Don't use tabs, and use the ICU standard for indentation. X-SVN-Rev: 8009 --- icu4c/source/extra/ustdio/ustdio.c | 850 +++++++++++++++-------------- 1 file changed, 426 insertions(+), 424 deletions(-) diff --git a/icu4c/source/extra/ustdio/ustdio.c b/icu4c/source/extra/ustdio/ustdio.c index be0d558eace..fa4b2d17504 100644 --- a/icu4c/source/extra/ustdio/ustdio.c +++ b/icu4c/source/extra/ustdio/ustdio.c @@ -19,6 +19,7 @@ #include "unicode/ustdio.h" #include "unicode/putil.h" +#include "cmemory.h" #include "ufile.h" #include "ufmt_cmn.h" #include "unicode/ucnv.h" @@ -38,213 +39,213 @@ static const uint32_t DELIMITERS_LEN = 1; #endif #define IS_STRING_DELIMITER(s) (UBool)( (s) == DELIM_CR || \ - (s) == DELIM_LF ) +(s) == DELIM_LF ) U_CAPI UTransliterator* U_EXPORT2 u_fsettransliterator(UFILE *file, UFileDirection direction, - UTransliterator *adopt, UErrorCode *status) + UTransliterator *adopt, UErrorCode *status) { - UTransliterator *old = NULL; + UTransliterator *old = NULL; - if(file==NULL || U_FAILURE(*status)) - { - return adopt; - } - - if(!file) - { - *status = U_ILLEGAL_ARGUMENT_ERROR; - return adopt; - } - - if(direction & U_READ) - { - /** TODO: implement */ - *status = U_UNSUPPORTED_ERROR; - return adopt; - } - - if(adopt == NULL) /* they are clearing it */ - { - if(file->fTranslit != NULL) + if(file==NULL || U_FAILURE(*status)) { - /* TODO: Check side */ - old = file->fTranslit->translit; - free(file->fTranslit->buffer); - file->fTranslit->buffer=NULL; - free(file->fTranslit); - file->fTranslit=NULL; + return adopt; + } + + if(!file) + { + *status = U_ILLEGAL_ARGUMENT_ERROR; + return adopt; + } + + if(direction & U_READ) + { + /** TODO: implement */ + *status = U_UNSUPPORTED_ERROR; + return adopt; + } + + if(adopt == NULL) /* they are clearing it */ + { + if(file->fTranslit != NULL) + { + /* TODO: Check side */ + old = file->fTranslit->translit; + uprv_free(file->fTranslit->buffer); + file->fTranslit->buffer=NULL; + uprv_free(file->fTranslit); + file->fTranslit=NULL; + } } - } - else - { - if(file->fTranslit == NULL) - { - file->fTranslit = (UFILETranslitBuffer*) malloc(sizeof(UFILETranslitBuffer)); - if(!file->fTranslit) - { - *status = U_MEMORY_ALLOCATION_ERROR; - return adopt; - } - file->fTranslit->capacity = 0; - file->fTranslit->length = 0; - file->fTranslit->pos = 0; - file->fTranslit->buffer = NULL; - } else - { - old = file->fTranslit->translit; - ufile_flush_translit(file); - } + { + if(file->fTranslit == NULL) + { + file->fTranslit = (UFILETranslitBuffer*) uprv_malloc(sizeof(UFILETranslitBuffer)); + if(!file->fTranslit) + { + *status = U_MEMORY_ALLOCATION_ERROR; + return adopt; + } + file->fTranslit->capacity = 0; + file->fTranslit->length = 0; + file->fTranslit->pos = 0; + file->fTranslit->buffer = NULL; + } + else + { + old = file->fTranslit->translit; + ufile_flush_translit(file); + } - file->fTranslit->translit = adopt; - } + file->fTranslit->translit = adopt; + } - return old; + return old; } const UChar * u_file_translit(UFILE *f, const UChar *src, int32_t *count, UBool flush) { - int32_t newlen; - int32_t junkCount = 0; - int32_t textLength; - int32_t textLimit; - UTransPosition pos; - UErrorCode status = U_ZERO_ERROR; - - if(count == NULL) - { - count = &junkCount; - } + int32_t newlen; + int32_t junkCount = 0; + int32_t textLength; + int32_t textLimit; + UTransPosition pos; + UErrorCode status = U_ZERO_ERROR; - if ((!f)||(!f->fTranslit)||(!f->fTranslit->translit)) - { - /* fast path */ - return src; - } - - /* First: slide over everything */ - if(f->fTranslit->length > f->fTranslit->pos) - { - memmove(f->fTranslit->buffer, f->fTranslit->buffer + f->fTranslit->pos, - (f->fTranslit->length - f->fTranslit->pos)*sizeof(UChar)); - } - f->fTranslit->length -= f->fTranslit->pos; /* always */ - f->fTranslit->pos = 0; - - /* Calculate new buffer size needed */ - newlen = (*count + f->fTranslit->length) * 4; - - if(newlen > f->fTranslit->capacity) - { - if(f->fTranslit->buffer == NULL) + if(count == NULL) { - f->fTranslit->buffer = (UChar*)malloc(newlen * sizeof(UChar)); + count = &junkCount; + } + + if ((!f)||(!f->fTranslit)||(!f->fTranslit->translit)) + { + /* fast path */ + return src; + } + + /* First: slide over everything */ + if(f->fTranslit->length > f->fTranslit->pos) + { + memmove(f->fTranslit->buffer, f->fTranslit->buffer + f->fTranslit->pos, + (f->fTranslit->length - f->fTranslit->pos)*sizeof(UChar)); + } + f->fTranslit->length -= f->fTranslit->pos; /* always */ + f->fTranslit->pos = 0; + + /* Calculate new buffer size needed */ + newlen = (*count + f->fTranslit->length) * 4; + + if(newlen > f->fTranslit->capacity) + { + if(f->fTranslit->buffer == NULL) + { + f->fTranslit->buffer = (UChar*)uprv_malloc(newlen * sizeof(UChar)); + } + else + { + f->fTranslit->buffer = (UChar*)uprv_realloc(f->fTranslit->buffer, newlen * sizeof(UChar)); + } + f->fTranslit->capacity = newlen; + } + + /* Now, copy any data over */ + u_strncpy(f->fTranslit->buffer + f->fTranslit->length, + src, + *count); + f->fTranslit->length += *count; + + /* Now, translit in place as much as we can */ + if(flush == FALSE) + { + textLength = f->fTranslit->length; + pos.contextStart = 0; + pos.contextLimit = textLength; + pos.start = 0; + pos.limit = textLength; + + utrans_transIncrementalUChars(f->fTranslit->translit, + f->fTranslit->buffer, /* because we shifted */ + &textLength, + f->fTranslit->capacity, + &pos, + &status); + + if(U_FAILURE(status)) + { + fprintf(stderr, " Gack. Translit blew up with a %s\n", u_errorName(status)); + return src; + } + + /* now: start/limit point to the transliterated text */ + /* Transliterated is [buffer..pos.start) */ + *count = pos.start; + f->fTranslit->pos = pos.start; + f->fTranslit->length = pos.limit; + + return f->fTranslit->buffer; } else { - f->fTranslit->buffer = (UChar*)realloc(f->fTranslit->buffer, newlen * sizeof(UChar)); + textLength = f->fTranslit->length; + textLimit = f->fTranslit->length; + + utrans_transUChars(f->fTranslit->translit, + f->fTranslit->buffer, + &textLength, + f->fTranslit->capacity, + 0, + &textLimit, + &status); + + if(U_FAILURE(status)) + { + fprintf(stderr, " Gack. Translit(flush) blew up with a %s\n", u_errorName(status)); + return src; + } + + /* out: converted len */ + *count = textLimit; + + /* Set pointers to 0 */ + f->fTranslit->pos = 0; + f->fTranslit->length = 0; + + return f->fTranslit->buffer; } - f->fTranslit->capacity = newlen; - } - - /* Now, copy any data over */ - u_strncpy(f->fTranslit->buffer + f->fTranslit->length, - src, - *count); - f->fTranslit->length += *count; - - /* Now, translit in place as much as we can */ - if(flush == FALSE) - { - textLength = f->fTranslit->length; - pos.contextStart = 0; - pos.contextLimit = textLength; - pos.start = 0; - pos.limit = textLength; - - utrans_transIncrementalUChars(f->fTranslit->translit, - f->fTranslit->buffer, /* because we shifted */ - &textLength, - f->fTranslit->capacity, - &pos, - &status); - - if(U_FAILURE(status)) - { - fprintf(stderr, " Gack. Translit blew up with a %s\n", u_errorName(status)); - return src; - } - - /* now: start/limit point to the transliterated text */ - /* Transliterated is [buffer..pos.start) */ - *count = pos.start; - f->fTranslit->pos = pos.start; - f->fTranslit->length = pos.limit; - - return f->fTranslit->buffer; - } - else - { - textLength = f->fTranslit->length; - textLimit = f->fTranslit->length; - - utrans_transUChars(f->fTranslit->translit, - f->fTranslit->buffer, - &textLength, - f->fTranslit->capacity, - 0, - &textLimit, - &status); - - if(U_FAILURE(status)) - { - fprintf(stderr, " Gack. Translit(flush) blew up with a %s\n", u_errorName(status)); - return src; - } - - /* out: converted len */ - *count = textLimit; - - /* Set pointers to 0 */ - f->fTranslit->pos = 0; - f->fTranslit->length = 0; - - return f->fTranslit->buffer; - } } -void +void ufile_flush_translit(UFILE *f) { - if((!f)||(!f->fTranslit)) - return; + if((!f)||(!f->fTranslit)) + return; - u_file_write_flush(NULL, 0, f, TRUE); + u_file_write_flush(NULL, 0, f, TRUE); } -void +void ufile_close_translit(UFILE *f) { - if((!f)||(!f->fTranslit)) - return; + if((!f)||(!f->fTranslit)) + return; - ufile_flush_translit(f); + ufile_flush_translit(f); - if(f->fTranslit->translit) - utrans_close(f->fTranslit->translit); - - if(f->fTranslit->buffer) - { - free(f->fTranslit->buffer); - } + if(f->fTranslit->translit) + utrans_close(f->fTranslit->translit); - free(f->fTranslit); - f->fTranslit = NULL; + if(f->fTranslit->buffer) + { + uprv_free(f->fTranslit->buffer); + } + + uprv_free(f->fTranslit); + f->fTranslit = NULL; } @@ -252,83 +253,83 @@ ufile_close_translit(UFILE *f) U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ u_fputs(const UChar *s, - UFILE *f) + UFILE *f) { - int32_t count = u_file_write(s, u_strlen(s), f); - count += u_file_write(DELIMITERS, DELIMITERS_LEN, f); - return count; + int32_t count = u_file_write(s, u_strlen(s), f); + count += u_file_write(DELIMITERS, DELIMITERS_LEN, f); + return count; } U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ u_fputc(UChar uc, - UFILE *f) + UFILE *f) { - return u_file_write(&uc, 1, f) == 1 ? uc : EOF; + return u_file_write(&uc, 1, f) == 1 ? uc : EOF; } U_CAPI int32_t U_EXPORT2 -u_file_write_flush( const UChar *chars, - int32_t count, - UFILE *f, - UBool flush) +u_file_write_flush( const UChar *chars, + int32_t count, + UFILE *f, + UBool flush) { - /* Set up conversion parameters */ - UErrorCode status = U_ZERO_ERROR; - const UChar *mySource = chars; - const UChar *sourceAlias = chars; - const UChar *mySourceEnd = chars + count; - char *myTarget = f->fCharBuffer; - int32_t bufferSize = UFILE_CHARBUFFER_SIZE; - int32_t written = 0; + /* Set up conversion parameters */ + UErrorCode status = U_ZERO_ERROR; + const UChar *mySource = chars; + const UChar *sourceAlias = chars; + const UChar *mySourceEnd = chars + count; + char *myTarget = f->fCharBuffer; + int32_t bufferSize = UFILE_CHARBUFFER_SIZE; + int32_t written = 0; - if((f->fTranslit) && (f->fTranslit->translit)) - { - /* Do the transliteration */ - mySource = u_file_translit(f, chars, &count, flush); - sourceAlias = mySource; - mySourceEnd = mySource + count; - } - - /* Perform the conversion in a loop */ - do { - status = U_ZERO_ERROR; - sourceAlias = mySource; - if(f->fConverter != NULL) { /* We have a valid converter */ - ucnv_fromUnicode(f->fConverter, - &myTarget, - f->fCharBuffer + bufferSize, - &mySource, - mySourceEnd, - NULL, - flush, - &status); - } else { /*weiv: do the invariant conversion */ - u_UCharsToChars(mySource, myTarget, count); - myTarget += count; - } + if((f->fTranslit) && (f->fTranslit->translit)) + { + /* Do the transliteration */ + mySource = u_file_translit(f, chars, &count, flush); + sourceAlias = mySource; + mySourceEnd = mySource + count; + } - /* write the converted bytes */ - fwrite(f->fCharBuffer, - sizeof(char), - myTarget - f->fCharBuffer, - f->fFile); - - written += (myTarget - f->fCharBuffer); - myTarget = f->fCharBuffer; - } - while(status == U_BUFFER_OVERFLOW_ERROR); + /* Perform the conversion in a loop */ + do { + status = U_ZERO_ERROR; + sourceAlias = mySource; + if(f->fConverter != NULL) { /* We have a valid converter */ + ucnv_fromUnicode(f->fConverter, + &myTarget, + f->fCharBuffer + bufferSize, + &mySource, + mySourceEnd, + NULL, + flush, + &status); + } else { /*weiv: do the invariant conversion */ + u_UCharsToChars(mySource, myTarget, count); + myTarget += count; + } - /* return # of chars written */ - return written; + /* write the converted bytes */ + fwrite(f->fCharBuffer, + sizeof(char), + myTarget - f->fCharBuffer, + f->fFile); + + written += (myTarget - f->fCharBuffer); + myTarget = f->fCharBuffer; + } + while(status == U_BUFFER_OVERFLOW_ERROR); + + /* return # of chars written */ + return written; } U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ -u_file_write( const UChar *chars, - int32_t count, - UFILE *f) +u_file_write( const UChar *chars, + int32_t count, + UFILE *f) { - return u_file_write_flush(chars,count,f,FALSE); + return u_file_write_flush(chars,count,f,FALSE); } @@ -336,184 +337,184 @@ u_file_write( const UChar *chars, void ufile_fill_uchar_buffer(UFILE *f) { - UErrorCode status; - const char *mySource; - const char *mySourceEnd; - UChar *myTarget; - int32_t bufferSize; - int32_t maxCPBytes; - int32_t bytesRead; - int32_t availLength; - int32_t dataSize; + UErrorCode status; + const char *mySource; + const char *mySourceEnd; + UChar *myTarget; + int32_t bufferSize; + int32_t maxCPBytes; + int32_t bytesRead; + int32_t availLength; + int32_t dataSize; - /* shift the buffer if it isn't empty */ - dataSize = f->fUCLimit - f->fUCPos; - if(dataSize != 0) { - memmove(f->fUCBuffer, - f->fUCPos, - dataSize * sizeof(UChar)); - } - + /* shift the buffer if it isn't empty */ + dataSize = f->fUCLimit - f->fUCPos; + if(dataSize != 0) { + memmove(f->fUCBuffer, + f->fUCPos, + dataSize * sizeof(UChar)); + } - /* record how much buffer space is available */ - availLength = UFILE_UCHARBUFFER_SIZE - dataSize; - - /* Determine the # of codepage bytes needed to fill our UChar buffer */ - /* weiv: if converter is NULL, we use invariant converter with charwidth = 1)*/ - maxCPBytes = availLength / (f->fConverter!=NULL?(2*ucnv_getMinCharSize(f->fConverter)):1); - /* Read in the data to convert */ - bytesRead = fread(f->fCharBuffer, - sizeof(char), - ufmt_min(maxCPBytes, UFILE_CHARBUFFER_SIZE), - f->fFile); + /* record how much buffer space is available */ + availLength = UFILE_UCHARBUFFER_SIZE - dataSize; - /* Set up conversion parameters */ - status = U_ZERO_ERROR; - mySource = f->fCharBuffer; - mySourceEnd = f->fCharBuffer + bytesRead; - myTarget = f->fUCBuffer + dataSize; - bufferSize = UFILE_UCHARBUFFER_SIZE; + /* Determine the # of codepage bytes needed to fill our UChar buffer */ + /* weiv: if converter is NULL, we use invariant converter with charwidth = 1)*/ + maxCPBytes = availLength / (f->fConverter!=NULL?(2*ucnv_getMinCharSize(f->fConverter)):1); - if(f->fConverter != NULL) { /* We have a valid converter */ - /* Perform the conversion */ - ucnv_toUnicode(f->fConverter, - &myTarget, - f->fUCBuffer + bufferSize, - &mySource, - mySourceEnd, - NULL, - (UBool)(feof(f->fFile) != 0), - &status); + /* Read in the data to convert */ + bytesRead = fread(f->fCharBuffer, + sizeof(char), + ufmt_min(maxCPBytes, UFILE_CHARBUFFER_SIZE), + f->fFile); - } else { /*weiv: do the invariant conversion */ - u_charsToUChars(mySource, myTarget, bytesRead); - myTarget += bytesRead; - } - - /* update the pointers into our array */ - f->fUCPos = f->fUCBuffer; - f->fUCLimit = myTarget; + /* Set up conversion parameters */ + status = U_ZERO_ERROR; + mySource = f->fCharBuffer; + mySourceEnd = f->fCharBuffer + bytesRead; + myTarget = f->fUCBuffer + dataSize; + bufferSize = UFILE_UCHARBUFFER_SIZE; + + if(f->fConverter != NULL) { /* We have a valid converter */ + /* Perform the conversion */ + ucnv_toUnicode(f->fConverter, + &myTarget, + f->fUCBuffer + bufferSize, + &mySource, + mySourceEnd, + NULL, + (UBool)(feof(f->fFile) != 0), + &status); + + } else { /*weiv: do the invariant conversion */ + u_charsToUChars(mySource, myTarget, bytesRead); + myTarget += bytesRead; + } + + /* update the pointers into our array */ + f->fUCPos = f->fUCBuffer; + f->fUCLimit = myTarget; } U_CAPI UChar* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ u_fgets(UFILE *f, - int32_t n, - UChar *s) + int32_t n, + UChar *s) { - int32_t dataSize; - int32_t read; - int32_t count; - UChar *alias; + int32_t dataSize; + int32_t read; + int32_t count; + UChar *alias; - - /* fill the buffer */ - ufile_fill_uchar_buffer(f); - /* subtract 1 from n to compensate for the terminator */ - --n; - - /* determine the amount of data in the buffer */ - dataSize = f->fUCLimit - f->fUCPos; - - /* if the buffer contains more data than requested, operate on the buffer */ - if(dataSize > n) { - - /* find the first occurrence of a delimiter character */ - alias = f->fUCPos; - count = 0; - while( ! IS_STRING_DELIMITER(*alias) && count < n) { - ++count; - alias++; - } - - /* copy the characters into the target*/ - memcpy(s, f->fUCPos, count * sizeof(UChar)); - - /* add the terminator */ - s[count] = 0x0000; - - /* update the current buffer position */ - f->fUCPos += count; - - /* refill the buffer */ + /* fill the buffer */ ufile_fill_uchar_buffer(f); - - /* skip over any remaining delimiters */ - while(IS_STRING_DELIMITER(*(f->fUCPos)) && f->fUCPos < f->fUCLimit) - (f->fUCPos)++; - - /* return s */ - return s; - } - /* otherwise, iteratively fill the buffer and copy */ - read = 0; - do { - + /* subtract 1 from n to compensate for the terminator */ + --n; + /* determine the amount of data in the buffer */ dataSize = f->fUCLimit - f->fUCPos; - /* find the first occurrence of a delimiter character, if present */ - alias = f->fUCPos; - count = 0; - while( ! IS_STRING_DELIMITER(*alias) && alias < f->fUCLimit && count < n) { - ++count; - alias++; - } - - /* copy the current data in the buffer */ - memcpy(s + read, f->fUCPos, count * sizeof(UChar)); - - /* update number of items read */ - read += count; + /* if the buffer contains more data than requested, operate on the buffer */ + if(dataSize > n) { - /* update the current buffer position */ - f->fUCPos += count; + /* find the first occurrence of a delimiter character */ + alias = f->fUCPos; + count = 0; + while( ! IS_STRING_DELIMITER(*alias) && count < n) { + ++count; + alias++; + } - /* if we found a delimiter */ - if(alias < f->fUCLimit) { + /* copy the characters into the target*/ + memcpy(s, f->fUCPos, count * sizeof(UChar)); - /* refill the buffer */ - ufile_fill_uchar_buffer(f); + /* add the terminator */ + s[count] = 0x0000; - /* skip over any remaining delimiters */ - while(IS_STRING_DELIMITER(*(f->fUCPos)) && f->fUCPos < f->fUCLimit) - (f->fUCPos)++; + /* update the current buffer position */ + f->fUCPos += count; - /* break out */ - break; + /* refill the buffer */ + ufile_fill_uchar_buffer(f); + + /* skip over any remaining delimiters */ + while(IS_STRING_DELIMITER(*(f->fUCPos)) && f->fUCPos < f->fUCLimit) + (f->fUCPos)++; + + /* return s */ + return s; } - /* refill the buffer */ - ufile_fill_uchar_buffer(f); + /* otherwise, iteratively fill the buffer and copy */ + read = 0; + do { - } while(dataSize != 0 && read < n); + /* determine the amount of data in the buffer */ + dataSize = f->fUCLimit - f->fUCPos; - /* if 0 characters were read, return 0 */ - if(read == 0) - return 0; + /* find the first occurrence of a delimiter character, if present */ + alias = f->fUCPos; + count = 0; + while( ! IS_STRING_DELIMITER(*alias) && alias < f->fUCLimit && count < n) { + ++count; + alias++; + } - /* add the terminator and return s */ - s[read] = 0x0000; - return s; + /* copy the current data in the buffer */ + memcpy(s + read, f->fUCPos, count * sizeof(UChar)); + + /* update number of items read */ + read += count; + + /* update the current buffer position */ + f->fUCPos += count; + + /* if we found a delimiter */ + if(alias < f->fUCLimit) { + + /* refill the buffer */ + ufile_fill_uchar_buffer(f); + + /* skip over any remaining delimiters */ + while(IS_STRING_DELIMITER(*(f->fUCPos)) && f->fUCPos < f->fUCLimit) + (f->fUCPos)++; + + /* break out */ + break; + } + + /* refill the buffer */ + ufile_fill_uchar_buffer(f); + + } while(dataSize != 0 && read < n); + + /* if 0 characters were read, return 0 */ + if(read == 0) + return 0; + + /* add the terminator and return s */ + s[read] = 0x0000; + return s; } U_CAPI UChar U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ u_fgetc(UFILE *f) { - /* if we have an available character in the buffer, return it */ - if(f->fUCPos < f->fUCLimit) - return *(f->fUCPos)++; - /* otherwise, fill the buffer and return the next character */ - else { - ufile_fill_uchar_buffer(f); + /* if we have an available character in the buffer, return it */ if(f->fUCPos < f->fUCLimit) - return *(f->fUCPos)++; - else - return 0xFFFF; - } + return *(f->fUCPos)++; + /* otherwise, fill the buffer and return the next character */ + else { + ufile_fill_uchar_buffer(f); + if(f->fUCPos < f->fUCLimit) + return *(f->fUCPos)++; + else + return 0xFFFF; + } } /* u_unescapeAt() callback to return a UChar from a UFILE */ @@ -523,15 +524,16 @@ static UChar _charAt(int32_t offset, void *context) { /* Read a UChar from a UFILE and process escape sequences */ U_CAPI UChar32 U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ -u_fgetcx(UFILE *f) { +u_fgetcx(UFILE *f) +{ int32_t length; int32_t offset; UChar32 c32; UChar c16; - + /* Fill the buffer if it is empty */ if (f->fUCPos >= f->fUCLimit) { - ufile_fill_uchar_buffer(f); + ufile_fill_uchar_buffer(f); } /* Get the next character in the buffer */ @@ -550,13 +552,13 @@ u_fgetcx(UFILE *f) { length = f->fUCLimit - f->fUCPos; /* The longest escape sequence is \Uhhhhhhhh; make sure - we have at least that many characters */ + we have at least that many characters */ if (length < 10) { /* fill the buffer */ ufile_fill_uchar_buffer(f); length = f->fUCLimit - f->fUCPos; } - + /* Process the escape */ offset = 0; c32 = u_unescapeAt(_charAt, &offset, length, (void*)f); @@ -569,63 +571,63 @@ u_fgetcx(UFILE *f) { U_CAPI UChar U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ u_fungetc(UChar c, - UFILE *f) + UFILE *f) { - /* if we're at the beginning of the buffer, sorry! */ - if(f->fUCPos == f->fUCBuffer) - return 0xFFFF; - /* otherwise, put the character back */ - else { - *--(f->fUCPos) = c; - return c; - } + /* if we're at the beginning of the buffer, sorry! */ + if(f->fUCPos == f->fUCBuffer) + return 0xFFFF; + /* otherwise, put the character back */ + else { + *--(f->fUCPos) = c; + return c; + } } U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ -u_file_read( UChar *chars, - int32_t count, - UFILE *f) +u_file_read( UChar *chars, + int32_t count, + UFILE *f) { - int32_t dataSize; - int32_t read; + int32_t dataSize; + int32_t read; - /* fill the buffer */ - ufile_fill_uchar_buffer(f); + /* fill the buffer */ + ufile_fill_uchar_buffer(f); - /* determine the amount of data in the buffer */ - dataSize = f->fUCLimit - f->fUCPos; - - /* if the buffer contains the amount requested, just copy */ - if(dataSize > count) { - memcpy(chars, f->fUCPos, count * sizeof(UChar)); - - /* update the current buffer position */ - f->fUCPos += count; - - /* return # of chars read */ - return count; - } - - /* otherwise, iteratively fill the buffer and copy */ - read = 0; - do { - /* determine the amount of data in the buffer */ dataSize = f->fUCLimit - f->fUCPos; - /* copy the current data in the buffer */ - memcpy(chars + read, f->fUCPos, dataSize * sizeof(UChar)); - - /* update number of items read */ - read += dataSize; + /* if the buffer contains the amount requested, just copy */ + if(dataSize > count) { + memcpy(chars, f->fUCPos, count * sizeof(UChar)); - /* update the current buffer position */ - f->fUCPos += dataSize; + /* update the current buffer position */ + f->fUCPos += count; - /* refill the buffer */ - ufile_fill_uchar_buffer(f); + /* return # of chars read */ + return count; + } - } while(dataSize != 0 && read < count); - - return read; + /* otherwise, iteratively fill the buffer and copy */ + read = 0; + do { + + /* determine the amount of data in the buffer */ + dataSize = f->fUCLimit - f->fUCPos; + + /* copy the current data in the buffer */ + memcpy(chars + read, f->fUCPos, dataSize * sizeof(UChar)); + + /* update number of items read */ + read += dataSize; + + /* update the current buffer position */ + f->fUCPos += dataSize; + + /* refill the buffer */ + ufile_fill_uchar_buffer(f); + + } while(dataSize != 0 && read < count); + + return read; }