ICU-329 Move uprv_strtod and other functions to private headers and files

X-SVN-Rev: 5498
This commit is contained in:
Ram Viswanadha 2001-08-17 01:40:34 +00:00
parent 209441543f
commit 61e489cacd
7 changed files with 127 additions and 77 deletions

View File

@ -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))

View File

@ -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"

View File

@ -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<MAX_DIGITS){
buffer[length] = (UChar) 0x0000;
}
num= (pad>=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<U_UNSUPPORTED_PROPERTY) {
if(code>=0 && code<U_STANDARD_ERROR_LIMIT) {
return _uErrorName[code];
} else if(code>=U_ERROR_INFO_START && code<U_ERROR_INFO_LIMIT) {
return _uErrorInfoName[code-U_ERROR_INFO_START];
} else if(U_PARSE_ERROR_END - code <= U_PARSE_ERROR_END - U_PARSE_ERROR_BASE){
return _uTransErrorName[code - U_PARSE_ERROR_BASE];
} else if(U_PARSE_ERROR_LIMIT - code <= U_PARSE_ERROR_LIMIT- U_PARSE_ERROR_START){
return _uTransErrorName[code - U_PARSE_ERROR_START];
} else if(U_FMT_PARSE_ERROR_LIMIT - code <= U_FMT_PARSE_ERROR_LIMIT- U_FMT_PARSE_ERROR_START){
return _uFmtErrorName[code - U_FMT_PARSE_ERROR_START];
} else {
return "[BOGUS UErrorCode]";
}

View File

@ -20,6 +20,7 @@
#include "ucnv_cnv.h"
#include "cmemory.h"
#include "unicode/ucnv.h"
#include "ustrfmt.h"
#define VALUE_STRING_LENGTH 32
/*Magic # 32 = 4(number of char in value string) * 8(max number of bytes per char for any converter) */

View File

@ -64,9 +64,6 @@ U_CAPI int32_t U_EXPORT2 uprv_max(int32_t x, int32_t y);
U_CAPI int32_t U_EXPORT2 uprv_min(int32_t x, int32_t y);
U_CAPI double U_EXPORT2 uprv_trunc(double d);
U_CAPI void U_EXPORT2 uprv_longBitsFromDouble(double d, int32_t *hi, uint32_t *lo);
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);
#if U_IS_BIG_ENDIAN
# define uprv_isNegative(number) (*((signed char *)&(number))<0)

View File

@ -0,0 +1,71 @@
/*
**********************************************************************
* Copyright (C) 2001-2003, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
#include "ustrfmt.h"
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<MAX_DIGITS){
buffer[length] = (UChar) 0x0000;
}
num= (pad>=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;
}

View File

@ -0,0 +1,24 @@
/*
**********************************************************************
* Copyright (C) 2001-2003, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
#ifndef USTRFMT_H
#define USTRFMT_H
#include <stdlib.h>
#include <stdio.h>
#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