From 61e489cacdcae30672c3205ea86586a08837e34d Mon Sep 17 00:00:00 2001 From: Ram Viswanadha Date: Fri, 17 Aug 2001 01:40:34 +0000 Subject: [PATCH] ICU-329 Move uprv_strtod and other functions to private headers and files X-SVN-Rev: 5498 --- icu4c/source/common/Makefile.in | 2 +- icu4c/source/common/common.dsp | 8 +++ icu4c/source/common/putil.c | 95 +++++++---------------------- icu4c/source/common/ucnv_err.c | 1 + icu4c/source/common/unicode/putil.h | 3 - icu4c/source/common/ustrfmt.c | 71 +++++++++++++++++++++ icu4c/source/common/ustrfmt.h | 24 ++++++++ 7 files changed, 127 insertions(+), 77 deletions(-) create mode 100644 icu4c/source/common/ustrfmt.c create mode 100644 icu4c/source/common/ustrfmt.h diff --git a/icu4c/source/common/Makefile.in b/icu4c/source/common/Makefile.in index 82e85e55d09..c1151fc5bd5 100644 --- a/icu4c/source/common/Makefile.in +++ b/icu4c/source/common/Makefile.in @@ -77,7 +77,7 @@ uchar.o ucmp8.o ucmp16.o ucmp32.o ucmpe32.o uvector.o uhash.o uhash_us.o \ unames.o unicode.o unistr.o ustring.o cstring.o utf_impl.o \ scsu.o ucnv.o ucnv_bld.o ucnv_cb.o ucnv_cnv.o ucnv_err.o ucnv_io.o convert.o \ ucnvlat1.o ucnvmbcs.o ucnv_utf.o ucnv2022.o ucnvhz.o ucnv_lmb.o ucnvscsu.o \ -ustream.o uscript.o ucnvisci.o ucln_cmn.o +ustream.o uscript.o ucnvisci.o ucln_cmn.o ustrfmt.o STATIC_OBJECTS = $(OBJECTS:.o=.$(STATIC_O)) diff --git a/icu4c/source/common/common.dsp b/icu4c/source/common/common.dsp index 680183dab17..d50bf2ccee2 100644 --- a/icu4c/source/common/common.dsp +++ b/icu4c/source/common/common.dsp @@ -382,6 +382,10 @@ SOURCE=.\ustream.cpp # End Source File # Begin Source File +SOURCE=.\ustrfmt.c +# End Source File +# Begin Source File + SOURCE=.\ustring.c # ADD CPP /Za # End Source File @@ -1360,6 +1364,10 @@ InputPath=.\unicode\ustream.h # End Source File # Begin Source File +SOURCE=.\ustrfmt.h +# End Source File +# Begin Source File + SOURCE=.\unicode\ustring.h !IF "$(CFG)" == "common - Win32 Release" diff --git a/icu4c/source/common/putil.c b/icu4c/source/common/putil.c index 20235bea8fa..b30c20794e7 100644 --- a/icu4c/source/common/putil.c +++ b/icu4c/source/common/putil.c @@ -32,7 +32,6 @@ * 08/04/99 jeffrey R. Added OS/2 changes * 11/15/99 helena Integrated S/390 IEEE support. * 04/26/01 Barry N. OS/400 support for uprv_getDefaultLocaleID -* 08/15/01 ram Add itou,stod,dtos,utoi functions * 08/15/01 Steven H. OS/400 support for uprv_getDefaultCodepage ****************************************************************************** */ @@ -602,68 +601,6 @@ uprv_longBitsFromDouble(double d, int32_t *hi, uint32_t *lo) *lo = *(uint32_t*)u_bottomNBytesOfDouble(&d, sizeof(uint32_t)); } -U_CAPI double -uprv_strtod(const char* source, char** end) -{ - return strtod(source,end); -} - - -U_CAPI char* -uprv_dtostr(double value, char *buffer, int maximumDigits,UBool fixedPoint) -{ - int start = 0; - int end =0; - sprintf(buffer,"%.3f",value); - /* truncate trailing zeros */ - end = uprv_strlen(buffer); - start=(uprv_strchr(buffer, '.')+2-buffer); - while(end-- > start){ - if(buffer[end]=='0'){ - buffer[end]=0; - }else{ - break; - } - } - return buffer; -} - -/*Takes a int32_t and fills in a UChar* string with that number "radix"-based - * and padded with "pad" zeroes - */ -#define MAX_DIGITS 10 -U_CAPI int32_t -uprv_itou (UChar * buffer, uint32_t i, uint32_t radix, int32_t pad) -{ - int32_t length = 0; - int32_t num = 0; - int digit; - int32_t j; - UChar temp; - - do{ - digit = (int)(i % radix); - buffer[length++]=(UChar)(digit<=9?(0x0030+digit):(0x0030+digit+7)); - i=i/radix; - } while(i); - - while (length < pad){ - buffer[length++] = (UChar) 0x0030;/*zero padding */ - } - /* null terminate the buffer */ - if(length=length) ? pad :length; - - /* Reverses the string */ - for (j = 0; j < (num / 2); j++){ - temp = buffer[(length-1) - j]; - buffer[(length-1) - j] = buffer[j]; - buffer[j] = temp; - } - return length; -} /** * Return the floor of the log base 10 of a given double. @@ -2388,8 +2325,7 @@ _uErrorInfoName[U_ERROR_INFO_LIMIT-U_ERROR_INFO_START]={ }; static const char * -_uTransErrorName[U_PARSE_ERROR_END - U_PARSE_ERROR_BASE + 1 ]={ - "U_PARSE_ERROR_BASE", +_uTransErrorName[U_PARSE_ERROR_LIMIT - U_PARSE_ERROR_START]={ "U_BAD_VARIABLE_DEFINITION", "U_MALFORMED_RULE", "U_MALFORMED_SET", @@ -2410,12 +2346,11 @@ _uTransErrorName[U_PARSE_ERROR_END - U_PARSE_ERROR_BASE + 1 ]={ "U_UNDEFINED_SEGMENT_REFERENCE", "U_UNDEFINED_VARIABLE", "U_UNQUOTED_SPECIAL", - "U_UNTERMINATED_QUOTE", - "U_PARSE_ERROR_END" + "U_UNTERMINATED_QUOTE" }; static const char * -_uErrorName[U_ERROR_LIMIT]={ +_uErrorName[U_STANDARD_ERROR_LIMIT]={ "U_ZERO_ERROR", "U_ILLEGAL_ARGUMENT_ERROR", @@ -2441,18 +2376,32 @@ _uErrorName[U_ERROR_LIMIT]={ "U_CE_NOT_FOUND_ERROR", "U_PRIMARY_TOO_LONG_ERROR", "U_STATE_TOO_OLD_ERROR" - "U_UNSUPPORTED_ATTRIBUTE", - "U_UNSUPPORTED_PROPERTY" +}; +static const char * +_uFmtErrorName[U_FMT_PARSE_ERROR_LIMIT - U_FMT_PARSE_ERROR_START] = { + "U_UNEXPECTED_TOKEN", + "U_MULTIPLE_DECIMAL_SEPERATORS", + "U_MULTIPLE_EXPONENTIAL_SYMBOLS", + "U_MALFORMED_EXPONENTIAL_PATTERN", + "U_MULTIPLE_PERCENT_SYMBOLS", + "U_MULTIPLE_PAD_SPECIFIERS", + "U_PATTERN_SYNTAX_ERROR", + "U_ILLEGAL_PAD_POSITION", + "U_UNMATCHED_BRACES", + "U_UNSUPPORTED_PROPERTY", + "U_UNSUPPORTED_ATTRIBUTE" }; U_CAPI const char * U_EXPORT2 u_errorName(UErrorCode code) { - if(code>=0 && code=0 && code=U_ERROR_INFO_START && code start){ + if(buffer[end]=='0'){ + buffer[end]=0; + }else{ + break; + } + } + return buffer; +} + +/*Takes a int32_t and fills in a UChar* string with that number "radix"-based + * and padded with "pad" zeroes + */ +#define MAX_DIGITS 10 +U_CAPI int32_t +uprv_itou (UChar * buffer, uint32_t i, uint32_t radix, int32_t pad) +{ + int32_t length = 0; + int32_t num = 0; + int digit; + int32_t j; + UChar temp; + + do{ + digit = (int)(i % radix); + buffer[length++]=(UChar)(digit<=9?(0x0030+digit):(0x0030+digit+7)); + i=i/radix; + } while(i); + + while (length < pad){ + buffer[length++] = (UChar) 0x0030;/*zero padding */ + } + /* null terminate the buffer */ + if(length=length) ? pad :length; + + /* Reverses the string */ + for (j = 0; j < (num / 2); j++){ + temp = buffer[(length-1) - j]; + buffer[(length-1) - j] = buffer[j]; + buffer[j] = temp; + } + return length; +} \ No newline at end of file diff --git a/icu4c/source/common/ustrfmt.h b/icu4c/source/common/ustrfmt.h new file mode 100644 index 00000000000..6eb2edb9277 --- /dev/null +++ b/icu4c/source/common/ustrfmt.h @@ -0,0 +1,24 @@ +/* +********************************************************************** +* Copyright (C) 2001-2003, International Business Machines +* Corporation and others. All Rights Reserved. +********************************************************************** +*/ + +#ifndef USTRFMT_H +#define USTRFMT_H + +#include +#include +#include "unicode/utypes.h" +#include "cstring.h" + +U_CAPI double +U_EXPORT2 uprv_strtod(const char* source, char** end); +U_CAPI char* +U_EXPORT2 uprv_dtostr(double value, char *buffer, int maximumDigits,UBool fixedPoint); +U_CAPI int32_t +U_EXPORT2 uprv_itou (UChar * buffer, uint32_t i, uint32_t radix, int32_t pad); + + +#endif