mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-329 Move itou to putil.c add more error codes for parse errors and transliteration.
X-SVN-Rev: 5477
This commit is contained in:
parent
0e194efd89
commit
87d0db48ce
5 changed files with 146 additions and 69 deletions
|
@ -32,6 +32,7 @@
|
|||
* 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
|
||||
* 15/08/01 ram Add itou,stod,dtos,utoi functions
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
@ -61,6 +62,7 @@
|
|||
#include <math.h>
|
||||
#include <locale.h>
|
||||
#include <time.h>
|
||||
#include <float.h>
|
||||
|
||||
/* include ICU headers */
|
||||
#include "unicode/utypes.h"
|
||||
|
@ -596,6 +598,68 @@ 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.
|
||||
|
@ -1954,7 +2018,7 @@ const char* uprv_getDefaultCodepage()
|
|||
/*
|
||||
* These maps for ASCII to/from EBCDIC are from
|
||||
* "UTF-EBCDIC - EBCDIC-Friendly Unicode (or UCS) Transformation Format"
|
||||
* at http://www.unicode.org/unicode/reports/tr16/
|
||||
* at http:/*www.unicode.org/unicode/reports/tr16/
|
||||
* (which should reflect codepage 1047)
|
||||
* but modified to explicitly exclude the variant
|
||||
* control and graphical characters that are in ASCII-based
|
||||
|
@ -2190,6 +2254,33 @@ _uErrorInfoName[U_ERROR_INFO_LIMIT-U_ERROR_INFO_START]={
|
|||
"U_STATE_OLD_WARNING"
|
||||
};
|
||||
|
||||
static const char *
|
||||
_uTransErrorName[U_PARSE_ERROR_END - U_PARSE_ERROR_BASE + 1 ]={
|
||||
"U_PARSE_ERROR_BASE",
|
||||
"U_BAD_VARIABLE_DEFINITION",
|
||||
"U_MALFORMED_RULE",
|
||||
"U_MALFORMED_SET",
|
||||
"U_MALFORMED_SYMBOL_REFERENCE",
|
||||
"U_MALFORMED_UNICODE_ESCAPE",
|
||||
"U_MALFORMED_VARIABLE_DEFINITION",
|
||||
"U_MALFORMED_VARIABLE_REFERENCE",
|
||||
"U_MISMATCHED_SEGMENT_DELIMITERS",
|
||||
"U_MISPLACED_ANCHOR_START",
|
||||
"U_MISPLACED_CURSOR_OFFSET",
|
||||
"U_MISPLACED_QUANTIFIER",
|
||||
"U_MISSING_OPERATOR",
|
||||
"U_MISSING_SEGMENT_CLOSE",
|
||||
"U_MULTIPLE_ANTE_CONTEXTS",
|
||||
"U_MULTIPLE_CURSORS",
|
||||
"U_MULTIPLE_POST_CONTEXTS",
|
||||
"U_TRAILING_BACKSLASH",
|
||||
"U_UNDEFINED_SEGMENT_REFERENCE",
|
||||
"U_UNDEFINED_VARIABLE",
|
||||
"U_UNQUOTED_SPECIAL",
|
||||
"U_UNTERMINATED_QUOTE",
|
||||
"U_PARSE_ERROR_END"
|
||||
};
|
||||
|
||||
static const char *
|
||||
_uErrorName[U_ERROR_LIMIT]={
|
||||
"U_ZERO_ERROR",
|
||||
|
@ -2217,14 +2308,18 @@ _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"
|
||||
};
|
||||
|
||||
U_CAPI const char * U_EXPORT2
|
||||
u_errorName(UErrorCode code) {
|
||||
if(code>=0 && code<U_ERROR_LIMIT) {
|
||||
if(code>=0 && code<U_UNSUPPORTED_PROPERTY) {
|
||||
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 {
|
||||
return "[BOGUS UErrorCode]";
|
||||
}
|
||||
|
@ -2238,7 +2333,7 @@ struct
|
|||
_localeToDefaultCharmapTable [] =
|
||||
{
|
||||
/*
|
||||
See: http://czyborra.com/charsets/iso8859.html
|
||||
See: http:/*czyborra.com/charsets/iso8859.html
|
||||
*/
|
||||
|
||||
/* xx_XX locales first, so they will match: */
|
||||
|
|
|
@ -39,43 +39,6 @@
|
|||
#define UCNV_PRV_ESCAPE_JAVA 'J'
|
||||
|
||||
|
||||
/*Takes a int32_t and fills in a UChar* string with that number "radix"-based
|
||||
* and padded with "pad" zeroes
|
||||
*/
|
||||
#define MAX_DIGITS 10
|
||||
static int32_t
|
||||
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;
|
||||
}
|
||||
|
||||
/*Function Pointer STOPS at the ILLEGAL_SEQUENCE */
|
||||
void UCNV_FROM_U_CALLBACK_STOP (
|
||||
const void *context,
|
||||
|
@ -177,7 +140,7 @@ void UCNV_FROM_U_CALLBACK_SUBSTITUTE (
|
|||
}
|
||||
}
|
||||
|
||||
/*uses itou to get a unicode escape sequence of the offensive sequence,
|
||||
/*uses uprv_itou to get a unicode escape sequence of the offensive sequence,
|
||||
*uses a clean copy (resetted) of the converter, to convert that unicode
|
||||
*escape sequence to the target codepage (if conversion failure happens then
|
||||
*we revert to substituting with subchar)
|
||||
|
@ -227,7 +190,7 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (
|
|||
{
|
||||
valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
|
||||
valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
|
||||
itou (valueString + valueStringLength, codeUnits[i++], 16, 4);
|
||||
uprv_itou (valueString + valueStringLength, codeUnits[i++], 16, 4);
|
||||
valueStringLength += 4;
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +203,7 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (
|
|||
{
|
||||
valueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */
|
||||
valueString[valueStringLength++] = (UChar) UNICODE_U_LOW_CODEPOINT; /* adding u */
|
||||
itou (valueString + valueStringLength, codeUnits[i++], 16, 4);
|
||||
uprv_itou (valueString + valueStringLength, codeUnits[i++], 16, 4);
|
||||
valueStringLength += 4;
|
||||
}
|
||||
break;
|
||||
|
@ -251,12 +214,12 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (
|
|||
if(length==2){
|
||||
UChar32 temp = UTF16_GET_PAIR_VALUE(codeUnits[0],codeUnits[1]);
|
||||
valueString[valueStringLength++] = (UChar) UNICODE_U_LOW_CODEPOINT; /* adding u */
|
||||
valueStringLength += itou (valueString + valueStringLength, temp, 16, 8);
|
||||
valueStringLength += uprv_itou (valueString + valueStringLength, temp, 16, 8);
|
||||
|
||||
}
|
||||
else{
|
||||
valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
|
||||
valueStringLength += itou (valueString + valueStringLength, codeUnits[0], 16, 4);
|
||||
valueStringLength += uprv_itou (valueString + valueStringLength, codeUnits[0], 16, 4);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -266,11 +229,11 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (
|
|||
valueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */
|
||||
if(length==2){
|
||||
UChar32 temp = UTF16_GET_PAIR_VALUE(codeUnits[0],codeUnits[1]);
|
||||
valueStringLength += itou (valueString + valueStringLength, temp, 10, 0);
|
||||
valueStringLength += uprv_itou (valueString + valueStringLength, temp, 10, 0);
|
||||
|
||||
}
|
||||
else{
|
||||
valueStringLength += itou (valueString + valueStringLength, codeUnits[0], 10, 4);
|
||||
valueStringLength += uprv_itou (valueString + valueStringLength, codeUnits[0], 10, 4);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -281,11 +244,11 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (
|
|||
valueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */
|
||||
if(length==2){
|
||||
UChar32 temp = UTF16_GET_PAIR_VALUE(codeUnits[0],codeUnits[1]);
|
||||
valueStringLength += itou (valueString + valueStringLength, temp, 16, 0);
|
||||
valueStringLength += uprv_itou (valueString + valueStringLength, temp, 16, 0);
|
||||
|
||||
}
|
||||
else{
|
||||
valueStringLength += itou (valueString + valueStringLength, codeUnits[0], 16, 4);
|
||||
valueStringLength += uprv_itou (valueString + valueStringLength, codeUnits[0], 16, 4);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -293,7 +256,7 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (
|
|||
{
|
||||
valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
|
||||
valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
|
||||
itou (valueString + valueStringLength, codeUnits[i++], 16, 4);
|
||||
uprv_itou (valueString + valueStringLength, codeUnits[i++], 16, 4);
|
||||
valueStringLength += 4;
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +358,7 @@ void UCNV_TO_U_CALLBACK_SUBSTITUTE (
|
|||
|
||||
}
|
||||
|
||||
/*uses itou to get a unicode escape sequence of the offensive sequence,
|
||||
/*uses uprv_itou to get a unicode escape sequence of the offensive sequence,
|
||||
*and uses that as the substitution sequence
|
||||
*/
|
||||
void UCNV_TO_U_CALLBACK_ESCAPE (
|
||||
|
@ -425,7 +388,7 @@ void UCNV_TO_U_CALLBACK_ESCAPE (
|
|||
{
|
||||
uniValueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
|
||||
uniValueString[valueStringLength++] = (UChar) UNICODE_X_CODEPOINT; /* adding X */
|
||||
itou (uniValueString + valueStringLength, (uint8_t) codeUnits[i++], 16, 2);
|
||||
uprv_itou (uniValueString + valueStringLength, (uint8_t) codeUnits[i++], 16, 2);
|
||||
valueStringLength += 2;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,10 @@ 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)
|
||||
#else
|
||||
|
|
|
@ -326,21 +326,6 @@
|
|||
#define flushInternalUnicodeBuffer flushInternalUnicodeBuffer_1_9
|
||||
#define frenchSub frenchSub_1_9
|
||||
#define gGlobalMutex gGlobalMutex_1_9
|
||||
#define g_umsgDateModifierList g_umsgDateModifierList_1_9
|
||||
#define g_umsgListLength g_umsgListLength_1_9
|
||||
#define g_umsgModifierList g_umsgModifierList_1_9
|
||||
#define g_umsgTypeList g_umsgTypeList_1_9
|
||||
#define g_umsg_choice g_umsg_choice_1_9
|
||||
#define g_umsg_currency g_umsg_currency_1_9
|
||||
#define g_umsg_date g_umsg_date_1_9
|
||||
#define g_umsg_full g_umsg_full_1_9
|
||||
#define g_umsg_integer g_umsg_integer_1_9
|
||||
#define g_umsg_long g_umsg_long_1_9
|
||||
#define g_umsg_medium g_umsg_medium_1_9
|
||||
#define g_umsg_number g_umsg_number_1_9
|
||||
#define g_umsg_percent g_umsg_percent_1_9
|
||||
#define g_umsg_short g_umsg_short_1_9
|
||||
#define g_umsg_time g_umsg_time_1_9
|
||||
#define getDiscontiguous getDiscontiguous_1_9
|
||||
#define getFCHK_STAGE_1_ getFCHK_STAGE_1__1_9
|
||||
#define getFCHK_STAGE_2_ getFCHK_STAGE_2__1_9
|
||||
|
@ -766,7 +751,6 @@
|
|||
#define udat_getSymbols udat_getSymbols_1_9
|
||||
#define udat_isLenient udat_isLenient_1_9
|
||||
#define udat_open udat_open_1_9
|
||||
#define udat_openPattern udat_openPattern_1_9
|
||||
#define udat_parse udat_parse_1_9
|
||||
#define udat_set2DigitYearStart udat_set2DigitYearStart_1_9
|
||||
#define udat_setCalendar udat_setCalendar_1_9
|
||||
|
@ -859,7 +843,6 @@
|
|||
#define unum_getSymbols unum_getSymbols_1_9
|
||||
#define unum_getTextAttribute unum_getTextAttribute_1_9
|
||||
#define unum_open unum_open_1_9
|
||||
#define unum_openPattern unum_openPattern_1_9
|
||||
#define unum_parse unum_parse_1_9
|
||||
#define unum_parseDouble unum_parseDouble_1_9
|
||||
#define unum_setAttribute unum_setAttribute_1_9
|
||||
|
|
|
@ -383,6 +383,38 @@ enum UErrorCode {
|
|||
U_CE_NOT_FOUND_ERROR = 21, /**< Currently used only while setting variable top, but can be used generally */
|
||||
U_PRIMARY_TOO_LONG_ERROR = 22, /**< User tried to set variable top to a primary that is longer than two bytes */
|
||||
U_STATE_TOO_OLD_ERROR = 23, /**< ICU cannot construct a service from this state, as it is no longer supported */
|
||||
/* The errorcode are for Number format C API */
|
||||
U_UNSUPPORTED_ATTRIBUTE = 24,
|
||||
U_UNSUPPORTED_PROPERTY = 25,
|
||||
/*
|
||||
* the error code range 0x10000 0x10100 are reserved for Transliterator
|
||||
*/
|
||||
U_PARSE_ERROR_BASE = 0x10000, /**< start of Transliterator specific parse Errors */
|
||||
U_BAD_VARIABLE_DEFINITION,
|
||||
U_MALFORMED_RULE,
|
||||
U_MALFORMED_SET,
|
||||
U_MALFORMED_SYMBOL_REFERENCE,
|
||||
U_MALFORMED_UNICODE_ESCAPE,
|
||||
U_MALFORMED_VARIABLE_DEFINITION,
|
||||
U_MALFORMED_VARIABLE_REFERENCE,
|
||||
U_MISMATCHED_SEGMENT_DELIMITERS,
|
||||
U_MISPLACED_ANCHOR_START,
|
||||
U_MISPLACED_CURSOR_OFFSET,
|
||||
U_MISPLACED_QUANTIFIER,
|
||||
U_MISSING_OPERATOR,
|
||||
U_MISSING_SEGMENT_CLOSE,
|
||||
U_MULTIPLE_ANTE_CONTEXTS,
|
||||
U_MULTIPLE_CURSORS,
|
||||
U_MULTIPLE_POST_CONTEXTS,
|
||||
U_TRAILING_BACKSLASH,
|
||||
U_UNDEFINED_SEGMENT_REFERENCE,
|
||||
U_UNDEFINED_VARIABLE,
|
||||
U_UNQUOTED_SPECIAL,
|
||||
U_UNTERMINATED_QUOTE,
|
||||
U_PARSE_ERROR_END, /**< end of Transliterator specific parse Errors */
|
||||
/*
|
||||
* End Transliterator parse Errors
|
||||
*/
|
||||
U_ERROR_LIMIT /**< This must always be the last value to indicate the limit for UErrorCode (last error code +1) */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue