mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-329 Add more error codes for formatting api
X-SVN-Rev: 5503
This commit is contained in:
parent
d2f648798c
commit
0a3e11290a
7 changed files with 58 additions and 62 deletions
|
@ -27,7 +27,7 @@
|
|||
#include "unicode/choicfmt.h"
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "mutex.h"
|
||||
#include "ustrfmt.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// class ChoiceFormat
|
||||
|
@ -561,8 +561,8 @@ ChoiceFormat::applyPattern(const UnicodeString& pattern,
|
|||
return;
|
||||
|
||||
error:
|
||||
//status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
syntaxError(pattern,i,parseError,status);
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
syntaxError(pattern,i,parseError);
|
||||
delete[] newLimits;
|
||||
delete[] newClosures;
|
||||
delete[] newFormats;
|
||||
|
|
|
@ -2312,7 +2312,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
if (digitRightCount > 0) {
|
||||
// Unexpected '0'
|
||||
debug("Unexpected '0'")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
++zeroDigitCount;
|
||||
|
@ -2329,7 +2330,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
if (decimalPos >= 0) {
|
||||
// Grouping separator after decimal
|
||||
debug("Grouping separator after decimal")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
groupingCount2 = groupingCount;
|
||||
|
@ -2338,7 +2340,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
if (decimalPos >= 0) {
|
||||
// Multiple decimal separators
|
||||
debug("Multiple decimal separators")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_MULTIPLE_DECIMAL_SEPERATORS;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
// Intentionally incorporate the digitRightCount,
|
||||
|
@ -2350,13 +2353,15 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
if (expDigits >= 0) {
|
||||
// Multiple exponential symbols
|
||||
debug("Multiple exponential symbols")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_MULTIPLE_EXPONENTIAL_SYMBOLS;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
if (groupingCount >= 0) {
|
||||
// Grouping separator in exponential pattern
|
||||
debug("Grouping separator in exponential pattern")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_MALFORMED_EXPONENTIAL_PATTERN;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
// Check for positive prefix
|
||||
|
@ -2377,7 +2382,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
expDigits < 1) {
|
||||
// Malformed exponential pattern
|
||||
debug("Malformed exponential pattern")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_MALFORMED_EXPONENTIAL_PATTERN;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -2436,7 +2442,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
if (subpart == 1 || part == 1) {
|
||||
// Unexpected separator
|
||||
debug("Unexpected separator")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
sub2Limit = pos;
|
||||
|
@ -2447,7 +2454,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
if (multiplier != 1) {
|
||||
// Too many percent/perMill characters
|
||||
debug("Too many percent/perMill characters")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_MULTIPLE_PERCENT_SYMBOLS;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
affix->append(kQuote); // Encode percent/perMill
|
||||
|
@ -2463,7 +2471,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
if (padPos >= 0 || // Multiple pad specifiers
|
||||
(pos+1) == pattern.length()) { // Nothing after padEscape
|
||||
debug("Multiple pad specifiers")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_MULTIPLE_PAD_SPECIFIERS;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
padPos = pos;
|
||||
|
@ -2543,7 +2552,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
groupingCount == 0 || groupingCount2 == 0 ||
|
||||
subpart > 2) { // subpart > 2 == unmatched quote
|
||||
debug("Syntax error")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_PATTERN_SYNTAX_ERROR;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2560,7 +2570,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
} else {
|
||||
// Illegal pad position
|
||||
debug("Illegal pad position")
|
||||
syntaxError(pattern,pos,parseError,status);
|
||||
status = U_ILLEGAL_PAD_POSITION;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,31 +98,6 @@ Format::operator==(const Format& /*that*/) const
|
|||
// Add this implementation to make linker happy.
|
||||
return TRUE;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// handle syntax errors
|
||||
inline void
|
||||
Format::syntaxError(const UnicodeString& pattern,
|
||||
int32_t pos,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status){
|
||||
parseError.offset = pos;
|
||||
|
||||
// for pre-context
|
||||
int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - U_PARSE_CONTEXT_LEN);
|
||||
int32_t stop = pos;
|
||||
pattern.extract(start,stop,parseError.preContext,0);
|
||||
//null terminate the buffer
|
||||
parseError.preContext[stop-start] = 0;
|
||||
|
||||
//for post-context
|
||||
start = pos;
|
||||
stop = ((pos+U_PARSE_CONTEXT_LEN)<=pattern.length()) ? (pos+U_PARSE_CONTEXT_LEN) :
|
||||
pattern.length();
|
||||
pattern.extract(start,stop,parseError.postContext,0);
|
||||
//null terminate the buffer
|
||||
parseError.postContext[stop-start]= 0;
|
||||
|
||||
status = U_PARSE_ERROR;
|
||||
}
|
||||
//---------------------------------------
|
||||
|
||||
//eof
|
||||
|
|
|
@ -24,10 +24,9 @@
|
|||
#include "unicode/datefmt.h"
|
||||
#include "unicode/smpdtfmt.h"
|
||||
#include "unicode/choicfmt.h"
|
||||
//#include "mutex.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "unicode/ucnv_err.h"
|
||||
|
||||
#include "ustrfmt.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// class MessageFormat
|
||||
|
@ -442,7 +441,7 @@ MessageFormat::applyPattern(const UnicodeString& newPattern,
|
|||
part = 0;
|
||||
makeFormat(/*i,*/ formatNumber, segments, parseError,success);
|
||||
if(U_FAILURE(success)){
|
||||
parseError.offset=i;
|
||||
syntaxError(newPattern,i,parseError);
|
||||
return;
|
||||
}
|
||||
formatNumber++;
|
||||
|
@ -462,7 +461,8 @@ MessageFormat::applyPattern(const UnicodeString& newPattern,
|
|||
}
|
||||
if (braceStack == 0 && part != 0) {
|
||||
fMaxOffset = -1;
|
||||
syntaxError(newPattern,i,parseError,success);
|
||||
success = U_UNMATCHED_BRACES;
|
||||
syntaxError(newPattern,i,parseError);
|
||||
return;
|
||||
//throw new IllegalArgumentException("Unmatched braces in the pattern.");
|
||||
}
|
||||
|
|
|
@ -411,7 +411,7 @@ public:
|
|||
*/
|
||||
int32_t* createSegments() const;
|
||||
|
||||
int syntaxError(int32_t code,
|
||||
int syntaxError(UErrorCode code,
|
||||
const UnicodeString& rule,
|
||||
int32_t start) {
|
||||
return parser.syntaxError(code, rule, start);
|
||||
|
@ -1132,11 +1132,10 @@ int32_t TransliteratorParser::parseRule(int32_t pos, int32_t limit) {
|
|||
* @param rule pattern string
|
||||
* @param start position of first character of current rule
|
||||
*/
|
||||
int32_t TransliteratorParser::syntaxError(int32_t parseErrorCode,
|
||||
int32_t TransliteratorParser::syntaxError(UErrorCode parseErrorCode,
|
||||
const UnicodeString& rule,
|
||||
int32_t start) {
|
||||
if (parseError != 0) {
|
||||
// parseError->code = parseErrorCode;
|
||||
parseError->line = 0; // We don't return a line #
|
||||
parseError->offset = start; // Character offset from rule start
|
||||
int32_t end = quotedIndexOf(rule, start, rule.length(), END_OF_RULE);
|
||||
|
|
|
@ -158,7 +158,7 @@ private:
|
|||
* @param rule pattern string
|
||||
* @param start position of first character of current rule
|
||||
*/
|
||||
int32_t syntaxError(int32_t parseErrorCode, const UnicodeString&, int32_t start);
|
||||
int32_t syntaxError(UErrorCode parseErrorCode, const UnicodeString&, int32_t start);
|
||||
|
||||
/**
|
||||
* Parse a UnicodeSet out, store it, and return the stand-in character
|
||||
|
|
|
@ -63,32 +63,34 @@ void ucol_tok_initTokenList(UColTokenParser *src, const UChar *rules, const uint
|
|||
src->resultLen = 0;
|
||||
}
|
||||
|
||||
U_INLINE void syntaxError( const UChar* rules,
|
||||
int32_t pos,
|
||||
UParseError* parseError,
|
||||
UErrorCode* status){
|
||||
U_INLINE void
|
||||
syntaxError( const UChar* rules,
|
||||
int32_t pos,
|
||||
int32_t rulesLen,
|
||||
UParseError* parseError){
|
||||
parseError->offset = pos;
|
||||
|
||||
parseError->line = 0 ; /* we are not using line numbers */
|
||||
|
||||
// for pre-context
|
||||
int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - U_PARSE_CONTEXT_LEN);
|
||||
int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1));
|
||||
int32_t stop = pos;
|
||||
|
||||
u_memcpy(parseError->preContext,rules+start,pos);
|
||||
|
||||
u_memcpy(parseError->preContext,rules+start,stop-start);
|
||||
//null terminate the buffer
|
||||
parseError->preContext[stop-start] = 0;
|
||||
|
||||
//for post-context
|
||||
start = pos;
|
||||
stop = ((pos+U_PARSE_CONTEXT_LEN)<=u_strlen(rules)) ? (pos+U_PARSE_CONTEXT_LEN) :
|
||||
start = pos+1;
|
||||
stop = ((pos+U_PARSE_CONTEXT_LEN)<= rulesLen )? (pos+(U_PARSE_CONTEXT_LEN-1)) :
|
||||
u_strlen(rules);
|
||||
u_memcpy(parseError->postContext,rules+start,stop);
|
||||
|
||||
u_memcpy(parseError->postContext,rules+start,stop-start);
|
||||
//null terminate the buffer
|
||||
parseError->postContext[stop-start]= 0;
|
||||
|
||||
*status = U_PARSE_ERROR;
|
||||
}
|
||||
|
||||
void ucol_uprv_tok_setOptionInImage(UColOptionSet *opts, UColAttribute attrib, UColAttributeValue value) {
|
||||
void
|
||||
ucol_uprv_tok_setOptionInImage(UColOptionSet *opts, UColAttribute attrib, UColAttributeValue value) {
|
||||
switch(attrib) {
|
||||
case UCOL_FRENCH_COLLATION:
|
||||
opts->frenchCollation = value;
|
||||
|
@ -410,6 +412,7 @@ const UChar *ucol_tok_parseNextToken(UColTokenParser *src,
|
|||
|
||||
case 0x0026/*'&'*/:
|
||||
if (newStrength != UCOL_TOK_UNSET) {
|
||||
/**/
|
||||
goto EndOfLoop;
|
||||
}
|
||||
|
||||
|
@ -440,15 +443,19 @@ const UChar *ucol_tok_parseNextToken(UColTokenParser *src,
|
|||
goto EndOfLoop;
|
||||
} else {
|
||||
*status = U_INVALID_FORMAT_ERROR;
|
||||
syntaxError(src->source,(src->current-src->source),(src->end-src->source),parseError);
|
||||
}
|
||||
} else if (result & UCOL_TOK_BEFORE){
|
||||
if(newStrength == UCOL_TOK_RESET) {
|
||||
before = result & UCOL_TOK_BEFORE;
|
||||
} else {
|
||||
*status = U_INVALID_FORMAT_ERROR;
|
||||
syntaxError(src->source,(src->current-src->source),(src->end-src->source),parseError);
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
syntaxError(src->source,(src->current-src->source),(src->end-src->source),parseError);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -469,6 +476,7 @@ const UChar *ucol_tok_parseNextToken(UColTokenParser *src,
|
|||
case 0x0027/*'\''*/:
|
||||
if (newStrength == UCOL_TOK_UNSET) { /* quote is illegal until we have a strength */
|
||||
*status = U_INVALID_FORMAT_ERROR;
|
||||
syntaxError(src->source,(src->current-src->source),(src->end-src->source),parseError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -514,11 +522,13 @@ const UChar *ucol_tok_parseNextToken(UColTokenParser *src,
|
|||
default:
|
||||
if (newStrength == UCOL_TOK_UNSET) {
|
||||
*status = U_INVALID_FORMAT_ERROR;
|
||||
syntaxError(src->source,(src->current-src->source),(src->end-src->source),parseError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ucol_tok_isSpecialChar(ch) && (inQuote == FALSE)) {
|
||||
*status = U_INVALID_FORMAT_ERROR;
|
||||
syntaxError(src->source,(src->current-src->source),(src->end-src->source),parseError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -573,6 +583,7 @@ const UChar *ucol_tok_parseNextToken(UColTokenParser *src,
|
|||
}
|
||||
|
||||
if (newCharsLen == 0 && top == FALSE) {
|
||||
syntaxError(src->source,(src->current-src->source),(src->end-src->source),parseError);
|
||||
*status = U_INVALID_FORMAT_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue