ICU-329 Add parseError and UErrorCode to all public API's to make them consitent with ICU's design. Fix implementation to bubble the error code.
X-SVN-Rev: 5653
This commit is contained in:
parent
81fc8fb03e
commit
e7042af1b8
@ -1735,7 +1735,9 @@ _uTransErrorName[U_PARSE_ERROR_LIMIT - U_PARSE_ERROR_START]={
|
||||
"U_UNDEFINED_SEGMENT_REFERENCE",
|
||||
"U_UNDEFINED_VARIABLE",
|
||||
"U_UNQUOTED_SPECIAL",
|
||||
"U_UNTERMINATED_QUOTE"
|
||||
"U_UNTERMINATED_QUOTE",
|
||||
"U_RULE_MASK_ERROR"
|
||||
|
||||
};
|
||||
|
||||
static const char * const
|
||||
|
@ -429,6 +429,7 @@ enum UErrorCode {
|
||||
U_UNDEFINED_VARIABLE,
|
||||
U_UNQUOTED_SPECIAL,
|
||||
U_UNTERMINATED_QUOTE,
|
||||
U_RULE_MASK_ERROR,
|
||||
U_PARSE_ERROR_LIMIT, /**< end of Transliterator specific parse Errors */
|
||||
|
||||
/*
|
||||
|
@ -50,17 +50,19 @@ CompoundTransliterator::CompoundTransliterator(
|
||||
CompoundTransliterator::CompoundTransliterator(const UnicodeString& id,
|
||||
UTransDirection direction,
|
||||
UnicodeFilter* adoptedFilter,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) :
|
||||
Transliterator(id, adoptedFilter),
|
||||
trans(0), compoundRBTIndex(-1) {
|
||||
init(id, direction, -1, 0, TRUE, status);
|
||||
init(id, direction, -1, 0, TRUE,parseError,status);
|
||||
}
|
||||
|
||||
CompoundTransliterator::CompoundTransliterator(const UnicodeString& id,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) :
|
||||
Transliterator(id, 0), // set filter to 0 here!
|
||||
trans(0), compoundRBTIndex(-1) {
|
||||
init(id, UTRANS_FORWARD, -1, 0, TRUE, status);
|
||||
init(id, UTRANS_FORWARD, -1, 0, TRUE,parseError,status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,10 +74,11 @@ CompoundTransliterator::CompoundTransliterator(const UnicodeString& ID,
|
||||
const UnicodeString& idBlock,
|
||||
int32_t idSplitPoint,
|
||||
Transliterator *adoptedTrans,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) :
|
||||
Transliterator(ID, 0),
|
||||
trans(0), compoundRBTIndex(-1) {
|
||||
init(idBlock, UTRANS_FORWARD, idSplitPoint, adoptedTrans, FALSE, status);
|
||||
init(idBlock, UTRANS_FORWARD, idSplitPoint, adoptedTrans, FALSE,parseError,status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,6 +117,7 @@ void CompoundTransliterator::init(const UnicodeString& id,
|
||||
int32_t idSplitPoint,
|
||||
Transliterator *adoptedSplitTrans,
|
||||
UBool fixReverseID,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) {
|
||||
// assert(trans == 0);
|
||||
|
||||
@ -127,7 +131,7 @@ void CompoundTransliterator::init(const UnicodeString& id,
|
||||
Transliterator::parseCompoundID(id, regenID, direction,
|
||||
idSplitPoint, adoptedSplitTrans,
|
||||
list, compoundRBTIndex,
|
||||
NULL, status);
|
||||
parseError, status);
|
||||
|
||||
init(list, direction, fixReverseID, status);
|
||||
}
|
||||
|
@ -17,15 +17,13 @@ char RuleBasedTransliterator::fgClassID = 0; // Value is irrelevant
|
||||
|
||||
void RuleBasedTransliterator::_construct(const UnicodeString& rules,
|
||||
UTransDirection direction,
|
||||
UErrorCode& status,
|
||||
UParseError* parseError) {
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) {
|
||||
data = 0;
|
||||
isDataOwned = TRUE;
|
||||
if (U_SUCCESS(status)) {
|
||||
data = TransliteratorParser::parse(rules, direction, parseError);
|
||||
if (data == 0) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
} else {
|
||||
data = TransliteratorParser::parse(rules, direction, parseError,status);
|
||||
if (U_SUCCESS(status)) {
|
||||
setMaximumContextLength(data->ruleSet.getMaximumContextLength());
|
||||
}
|
||||
}
|
||||
|
@ -769,7 +769,8 @@ int32_t* RuleHalf::createSegments(UErrorCode& status) const {
|
||||
TransliterationRuleData*
|
||||
TransliteratorParser::parse(const UnicodeString& rules,
|
||||
UTransDirection direction,
|
||||
UParseError* parseError) {
|
||||
UParseError& parseError,
|
||||
UErrorCode& ec) {
|
||||
TransliteratorParser parser(rules, direction, parseError);
|
||||
UnicodeString idBlock;
|
||||
int32_t idSplitPoint, count;
|
||||
@ -777,6 +778,7 @@ TransliteratorParser::parse(const UnicodeString& rules,
|
||||
if (U_FAILURE(parser.status) || idBlock.length() != 0) {
|
||||
delete parser.data;
|
||||
parser.data = 0;
|
||||
ec = parser.status;
|
||||
}
|
||||
return parser.data;
|
||||
}
|
||||
@ -800,7 +802,7 @@ void TransliteratorParser::parse(const UnicodeString& rules,
|
||||
TransliterationRuleData*& ruleDataResult,
|
||||
UnicodeString& idBlockResult,
|
||||
int32_t& idSplitPointResult,
|
||||
UParseError* parseError,
|
||||
UParseError& parseError,
|
||||
UErrorCode& ec) {
|
||||
if (U_FAILURE(ec)) {
|
||||
ruleDataResult = 0;
|
||||
@ -822,12 +824,14 @@ void TransliteratorParser::parse(const UnicodeString& rules,
|
||||
* @exception IllegalArgumentException if there is a syntax error in the
|
||||
* rules
|
||||
*/
|
||||
|
||||
/* Ram: Reordered member initializers to match declaration order and make GCC happy */
|
||||
TransliteratorParser::TransliteratorParser(
|
||||
const UnicodeString& theRules,
|
||||
UTransDirection theDirection,
|
||||
UParseError* theParseError)
|
||||
UParseError& theParseError)
|
||||
:
|
||||
rules(theRules), direction(theDirection), variablesVector(status), data(0), parseError(theParseError)
|
||||
rules(theRules), direction(theDirection),data(0),parseError(theParseError), variablesVector(status)
|
||||
{
|
||||
parseData = new ParseData(0, &variablesVector);
|
||||
if (parseData == NULL) {
|
||||
@ -857,11 +861,11 @@ void TransliteratorParser::parseRules(UnicodeString& idBlockResult,
|
||||
ruleCount = 0;
|
||||
|
||||
// Clear error struct
|
||||
if (parseError != 0) {
|
||||
//if (parseError != 0) {
|
||||
//parseError->code = parseError->line = 0;
|
||||
parseError->offset = 0;
|
||||
parseError->preContext[0] = parseError->postContext[0] = (UChar)0;
|
||||
}
|
||||
parseError.offset = 0;
|
||||
parseError.preContext[0] = parseError.postContext[0] = (UChar)0;
|
||||
//}
|
||||
|
||||
delete data;
|
||||
data = new TransliterationRuleData(status);
|
||||
@ -918,11 +922,12 @@ void TransliteratorParser::parseRules(UnicodeString& idBlockResult,
|
||||
int32_t p = pos;
|
||||
UBool sawDelim;
|
||||
UnicodeString regenID;
|
||||
Transliterator::parseID(rules, regenID, p, sawDelim, direction, NULL, FALSE);
|
||||
if (p == pos || !sawDelim) {
|
||||
Transliterator::parseID(rules, regenID, p, sawDelim, direction,parseError, FALSE,status);
|
||||
//if (p == pos || !sawDelim) {
|
||||
// Invalid ::id
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
} else {
|
||||
//status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
//else {
|
||||
if(p != pos || sawDelim) {
|
||||
if (mode == 1) {
|
||||
mode = 2;
|
||||
idSplitPointResult = idBlockResult.length();
|
||||
@ -942,8 +947,10 @@ void TransliteratorParser::parseRules(UnicodeString& idBlockResult,
|
||||
if (mode == 2) {
|
||||
// ::id in illegal position (because a rule
|
||||
// occurred after the ::id footer block)
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
syntaxError(U_ILLEGAL_ARGUMENT_ERROR,rules,pos);
|
||||
}
|
||||
}else{
|
||||
syntaxError(status,rules,pos);
|
||||
}
|
||||
mode = 1;
|
||||
}
|
||||
@ -964,7 +971,7 @@ void TransliteratorParser::parseRules(UnicodeString& idBlockResult,
|
||||
|
||||
// Index the rules
|
||||
if (U_SUCCESS(status)) {
|
||||
data->ruleSet.freeze(status);
|
||||
data->ruleSet.freeze(parseError,status);
|
||||
if (idSplitPointResult < 0) {
|
||||
idSplitPointResult = idBlockResult.length();
|
||||
}
|
||||
@ -1049,7 +1056,6 @@ int32_t TransliteratorParser::parseRule(int32_t pos, int32_t limit) {
|
||||
// We allow anything on the right, including an empty string.
|
||||
UnicodeString* value = new UnicodeString(right->text);
|
||||
data->variableNames->put(undefinedVariableName, value, status);
|
||||
|
||||
++variableLimit;
|
||||
return pos;
|
||||
}
|
||||
@ -1057,7 +1063,7 @@ int32_t TransliteratorParser::parseRule(int32_t pos, int32_t limit) {
|
||||
// If this is not a variable definition rule, we shouldn't have
|
||||
// any undefined variable names.
|
||||
if (undefinedVariableName.length() != 0) {
|
||||
syntaxError(// "Undefined variable $" + undefinedVariableName,
|
||||
return syntaxError(// "Undefined variable $" + undefinedVariableName,
|
||||
U_UNDEFINED_VARIABLE,
|
||||
rule, start);
|
||||
}
|
||||
@ -1150,9 +1156,9 @@ int32_t TransliteratorParser::parseRule(int32_t pos, int32_t limit) {
|
||||
*/
|
||||
int32_t TransliteratorParser::syntaxError(UErrorCode parseErrorCode,
|
||||
const UnicodeString& rule,
|
||||
int32_t start) {
|
||||
if (parseError != 0) {
|
||||
parseError->line = 0; // We don't return a line #
|
||||
int32_t pos) {
|
||||
// if (parseError != 0) {
|
||||
/* 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);
|
||||
if (end < 0) {
|
||||
@ -1165,9 +1171,30 @@ int32_t TransliteratorParser::syntaxError(UErrorCode parseErrorCode,
|
||||
rule.extract(start, len, parseError->preContext); // Current rule
|
||||
parseError->preContext[len] = 0;
|
||||
parseError->postContext[0] = 0;
|
||||
}
|
||||
*/
|
||||
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-1));
|
||||
int32_t stop = pos;
|
||||
|
||||
rule.extract(start,stop-start,parseError.preContext);
|
||||
//null terminate the buffer
|
||||
parseError.preContext[stop-start] = 0;
|
||||
|
||||
//for post-context
|
||||
start = pos+1;
|
||||
stop = ((pos+U_PARSE_CONTEXT_LEN)<= rule.length() )? (pos+(U_PARSE_CONTEXT_LEN-1)) :
|
||||
rule.length();
|
||||
|
||||
rule.extract(start,stop-start,parseError.postContext);
|
||||
//null terminate the buffer
|
||||
parseError.postContext[stop-start]= 0;
|
||||
// }
|
||||
status = (UErrorCode)parseErrorCode;
|
||||
return start;
|
||||
return pos;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ class TransliteratorParser {
|
||||
* Pointer to user structure in which to return parse error information.
|
||||
* May be NULL.
|
||||
*/
|
||||
UParseError* parseError;
|
||||
UParseError& parseError;
|
||||
|
||||
/**
|
||||
* Temporary symbol table used during parsing.
|
||||
@ -83,7 +83,8 @@ public:
|
||||
static TransliterationRuleData*
|
||||
parse(const UnicodeString& rules,
|
||||
UTransDirection direction,
|
||||
UParseError* parseError = 0);
|
||||
UParseError& parseError,
|
||||
UErrorCode& ec);
|
||||
|
||||
/**
|
||||
* Parse a given set of rules. Return up to three pieces of
|
||||
@ -104,7 +105,7 @@ public:
|
||||
TransliterationRuleData*& ruleDataResult,
|
||||
UnicodeString& idBlockResult,
|
||||
int32_t& idSplitPointResult,
|
||||
UParseError* parseError,
|
||||
UParseError& parseError,
|
||||
UErrorCode& ec);
|
||||
|
||||
private:
|
||||
@ -116,7 +117,7 @@ private:
|
||||
*/
|
||||
TransliteratorParser(const UnicodeString& rules,
|
||||
UTransDirection direction,
|
||||
UParseError* parseError = 0);
|
||||
UParseError& parseError);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
const UChar TransliterationRule::ETHER = 0xFFFF;
|
||||
|
||||
static const UChar APOSTROPHE = 0x0027; // '
|
||||
static const UChar BACKSLASH = 0x005C; // \
|
||||
static const UChar APOSTROPHE = 0x0027; // '\''
|
||||
static const UChar BACKSLASH = 0x005C; // '\'
|
||||
|
||||
// To process segments we need to allocate arrays of integers. We use
|
||||
// stack storage as long as the segment count is <= MAX_STATIC_SEGS.
|
||||
@ -136,14 +136,16 @@ TransliterationRule::TransliterationRule(const UnicodeString& input,
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
|
||||
/* Ram: Reordered member initializers to match declaration order and make GCC happy */
|
||||
TransliterationRule::TransliterationRule(TransliterationRule& other) :
|
||||
pattern(other.pattern),
|
||||
output(other.output),
|
||||
firstKeySeg(other.firstKeySeg),
|
||||
anteContextLength(other.anteContextLength),
|
||||
keyLength(other.keyLength),
|
||||
cursorPos(other.cursorPos),
|
||||
flags(other.flags),
|
||||
firstKeySeg(other.firstKeySeg),
|
||||
data(other.data) {
|
||||
|
||||
segments = 0;
|
||||
|
@ -244,6 +244,10 @@ public:
|
||||
*/
|
||||
virtual UnicodeString& toRule(UnicodeString& pat,
|
||||
UBool escapeUnprintable) const;
|
||||
UnicodeString& getPattern(UnicodeString& fillIn){
|
||||
fillIn.append(pattern);
|
||||
return fillIn;
|
||||
}
|
||||
private:
|
||||
|
||||
friend class StringMatcher;
|
||||
|
@ -16,6 +16,30 @@ static void U_CALLCONV _deleteRule(void *rule) {
|
||||
delete (TransliterationRule *)rule;
|
||||
}
|
||||
|
||||
static void syntaxError(const UnicodeString& r1,
|
||||
const UnicodeString& r2,
|
||||
UParseError& parseError) {
|
||||
parseError.line =0 ;
|
||||
parseError.offset =0;
|
||||
int32_t len1 = r1.length();
|
||||
int32_t len2 = r2.length();
|
||||
// for pre-context
|
||||
int32_t start = (len1<U_PARSE_CONTEXT_LEN) ? 0: (len1 - (U_PARSE_CONTEXT_LEN-1));
|
||||
int32_t stop = len1;
|
||||
|
||||
r1.extract(start,stop-start,parseError.preContext);
|
||||
//null terminate the buffer
|
||||
parseError.preContext[stop-start] = 0;
|
||||
//for post-context
|
||||
start = 0;
|
||||
stop = (len2<U_PARSE_CONTEXT_LEN)? len2 : (U_PARSE_CONTEXT_LEN-1);
|
||||
|
||||
r2.extract(start,stop-start,parseError.postContext);
|
||||
//null terminate the buffer
|
||||
parseError.postContext[stop-start]= 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new empty rule set.
|
||||
*/
|
||||
@ -95,7 +119,7 @@ void TransliterationRuleSet::addRule(TransliterationRule* adoptedRule,
|
||||
* That is, <code>freeze()</code> may be called multiple times,
|
||||
* although for optimal performance it shouldn't be.
|
||||
*/
|
||||
void TransliterationRuleSet::freeze(UErrorCode& status) {
|
||||
void TransliterationRuleSet::freeze(UParseError& parseError,UErrorCode& status) {
|
||||
/* Construct the rule array and index table. We reorder the
|
||||
* rules by sorting them into 256 bins. Each bin contains all
|
||||
* rules matching the index value for that bin. A rule
|
||||
@ -181,7 +205,9 @@ void TransliterationRuleSet::freeze(UErrorCode& status) {
|
||||
//| errors.append("\n");
|
||||
//| }
|
||||
//| errors.append("Rule " + r1 + " masks " + r2);
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
status = U_RULE_MASK_ERROR;
|
||||
UnicodeString rp1,rp2;
|
||||
syntaxError(r1->getPattern(rp1),r2->getPattern(rp2),parseError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -217,6 +243,8 @@ UBool TransliterationRuleSet::transliterate(Replaceable& text,
|
||||
return TRUE;
|
||||
case U_PARTIAL_MATCH:
|
||||
return FALSE;
|
||||
default: /* Ram: added default to make GCC happy */
|
||||
break;
|
||||
}
|
||||
}
|
||||
// No match or partial match from any rule
|
||||
|
@ -90,7 +90,7 @@ public:
|
||||
* That is, <code>freeze()</code> may be called multiple times,
|
||||
* although for optimal performance it shouldn't be.
|
||||
*/
|
||||
virtual void freeze(UErrorCode& status);
|
||||
virtual void freeze(UParseError& parseError, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Transliterate the given text with the given UTransPosition
|
||||
|
@ -636,8 +636,9 @@ void Transliterator::adoptFilter(UnicodeFilter* filterToAdopt) {
|
||||
* transliterator is registered.
|
||||
* @see #registerInstance
|
||||
*/
|
||||
Transliterator* Transliterator::createInverse(void) const {
|
||||
return Transliterator::createInstance(ID, UTRANS_REVERSE);
|
||||
Transliterator* Transliterator::createInverse(UErrorCode& status) const {
|
||||
UParseError parseError;
|
||||
return Transliterator::createInstance(ID, UTRANS_REVERSE,parseError,status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -653,8 +654,15 @@ Transliterator* Transliterator::createInverse(void) const {
|
||||
*/
|
||||
Transliterator* Transliterator::createInstance(const UnicodeString& ID,
|
||||
UTransDirection dir,
|
||||
UParseError* parseError) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) {
|
||||
return createInstance(ID, dir, -1, NULL, parseError, status);
|
||||
}
|
||||
|
||||
Transliterator* Transliterator::createInstance(const UnicodeString& ID,
|
||||
UTransDirection dir,
|
||||
UErrorCode& status) {
|
||||
UParseError parseError;
|
||||
return createInstance(ID, dir, -1, NULL, parseError, status);
|
||||
}
|
||||
|
||||
@ -671,7 +679,7 @@ Transliterator* Transliterator::createInstance(const UnicodeString& ID,
|
||||
UTransDirection dir,
|
||||
int32_t idSplitPoint,
|
||||
Transliterator *adoptedSplitTrans,
|
||||
UParseError* parseError,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) {
|
||||
if (U_FAILURE(status)) {
|
||||
return 0;
|
||||
@ -714,11 +722,11 @@ Transliterator* Transliterator::createInstance(const UnicodeString& ID,
|
||||
Transliterator* Transliterator::createFromRules(const UnicodeString& ID,
|
||||
const UnicodeString& rules,
|
||||
UTransDirection dir,
|
||||
UParseError* parseError) {
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) {
|
||||
UnicodeString idBlock;
|
||||
int32_t idSplitPoint = -1;
|
||||
TransliterationRuleData *data = 0;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
TransliteratorParser::parse(rules, dir, data,
|
||||
idBlock, idSplitPoint,
|
||||
@ -743,7 +751,7 @@ Transliterator* Transliterator::createFromRules(const UnicodeString& ID,
|
||||
} else {
|
||||
if (data == 0) {
|
||||
// idBlock, no data -- this is an alias
|
||||
Transliterator *t = createInstance(idBlock, dir, parseError);
|
||||
Transliterator *t = createInstance(idBlock, dir, parseError,status);
|
||||
if (t != 0) {
|
||||
t->setID(ID);
|
||||
}
|
||||
@ -754,7 +762,7 @@ Transliterator* Transliterator::createFromRules(const UnicodeString& ID,
|
||||
UnicodeString id("_", "");
|
||||
Transliterator *t = new RuleBasedTransliterator(id, data, TRUE); // TRUE == adopt data object
|
||||
t = new CompoundTransliterator(ID, idBlock, idSplitPoint,
|
||||
t, status);
|
||||
t,parseError,status);
|
||||
if (U_FAILURE(status)) {
|
||||
delete t;
|
||||
t = 0;
|
||||
@ -798,7 +806,7 @@ void Transliterator::parseCompoundID(const UnicodeString& id,
|
||||
Transliterator *adoptedSplitTrans,
|
||||
UVector& result,
|
||||
int32_t& splitTransIndex,
|
||||
UParseError* parseError,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) {
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
@ -819,7 +827,13 @@ void Transliterator::parseCompoundID(const UnicodeString& id,
|
||||
int32_t p = pos;
|
||||
UBool sawDelimiter; // We ignore this
|
||||
Transliterator *t =
|
||||
parseID(id, regenID, p, sawDelimiter, dir, parseError, TRUE);
|
||||
parseID(id, regenID, p, sawDelimiter, dir, parseError, TRUE,status);
|
||||
|
||||
if(U_FAILURE(status)){
|
||||
delete t;
|
||||
break;
|
||||
}
|
||||
|
||||
if (p == pos || (p < id.length() && !sawDelimiter)) {
|
||||
delete t;
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
@ -885,8 +899,9 @@ Transliterator* Transliterator::parseID(const UnicodeString& ID,
|
||||
int32_t& pos,
|
||||
UBool& sawDelimiter,
|
||||
UTransDirection dir,
|
||||
UParseError* parseError,
|
||||
UBool create) {
|
||||
UParseError& parseError,
|
||||
UBool create,
|
||||
UErrorCode& status) {
|
||||
int32_t limit, preDelimLimit,
|
||||
revStart, revLimit,
|
||||
idStart, idLimit,
|
||||
@ -1016,17 +1031,17 @@ Transliterator* Transliterator::parseID(const UnicodeString& ID,
|
||||
|
||||
else {
|
||||
// Create the actual transliterator from the registry
|
||||
if (parseError != 0) {
|
||||
parseError->line = parseError->offset = 0;
|
||||
parseError->preContext[0] = parseError->postContext[0] = 0;
|
||||
}
|
||||
//if (parseError != 0) {
|
||||
parseError.line = parseError.offset = 0;
|
||||
parseError.preContext[0] = parseError.postContext[0] = 0;
|
||||
//}
|
||||
if (registry == 0) {
|
||||
initializeRegistry();
|
||||
}
|
||||
{
|
||||
Mutex lock(®istryMutex);
|
||||
str.truncate(0);
|
||||
t = registry->get(id, str, parseError);
|
||||
t = registry->get(id, str, parseError,status);
|
||||
// Need to enclose this in a block to prevent deadlock when
|
||||
// instantiating aliases (below).
|
||||
}
|
||||
@ -1034,7 +1049,7 @@ Transliterator* Transliterator::parseID(const UnicodeString& ID,
|
||||
if (str.length() != 0) {
|
||||
// assert(t==0);
|
||||
// Instantiate an alias
|
||||
t = createInstance(str, UTRANS_FORWARD, parseError);
|
||||
t = createInstance(str, UTRANS_FORWARD, parseError,status);
|
||||
}
|
||||
|
||||
if (t == 0) {
|
||||
|
@ -300,10 +300,11 @@ TransliteratorRegistry::~TransliteratorRegistry() {
|
||||
|
||||
Transliterator* TransliteratorRegistry::get(const UnicodeString& ID,
|
||||
UnicodeString& aliasReturn,
|
||||
UParseError* parseError) {
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) {
|
||||
Entry *entry = find(ID);
|
||||
return (entry == 0) ? 0
|
||||
: instantiateEntry(ID, entry, aliasReturn, parseError);
|
||||
: instantiateEntry(ID, entry, aliasReturn, parseError,status);
|
||||
}
|
||||
|
||||
void TransliteratorRegistry::put(Transliterator* adoptedProto,
|
||||
@ -829,8 +830,8 @@ Entry* TransliteratorRegistry::find(UnicodeString& source,
|
||||
Transliterator* TransliteratorRegistry::instantiateEntry(const UnicodeString& ID,
|
||||
Entry *entry,
|
||||
UnicodeString &aliasReturn,
|
||||
UParseError* parseError) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) {
|
||||
|
||||
for (;;) {
|
||||
if (entry->entryType == Entry::RBT_DATA) {
|
||||
@ -846,7 +847,7 @@ Transliterator* TransliteratorRegistry::instantiateEntry(const UnicodeString& ID
|
||||
UnicodeString id("_", "");
|
||||
Transliterator *t = new RuleBasedTransliterator(id, entry->u.data);
|
||||
t = new CompoundTransliterator(ID, entry->stringArg,
|
||||
entry->intArg, t, status);
|
||||
entry->intArg, t, parseError, status);
|
||||
if (U_FAILURE(status)) {
|
||||
delete t;
|
||||
t = 0;
|
||||
|
@ -64,7 +64,8 @@ class TransliteratorRegistry {
|
||||
*/
|
||||
Transliterator* get(const UnicodeString& ID,
|
||||
UnicodeString& aliasReturn,
|
||||
UParseError* parseError);
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Register a prototype (adopted). This adds an entry to the
|
||||
@ -246,7 +247,8 @@ class TransliteratorRegistry {
|
||||
Transliterator* instantiateEntry(const UnicodeString& ID,
|
||||
Entry *entry,
|
||||
UnicodeString& aliasReturn,
|
||||
UParseError* parseError);
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
static void IDtoSTV(const UnicodeString& id,
|
||||
UnicodeString& source,
|
||||
|
@ -34,7 +34,7 @@ class U_I18N_API UVector;
|
||||
* <p>Copyright © IBM Corporation 1999. All rights reserved.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @version $RCSfile: cpdtrans.h,v $ $Revision: 1.16 $ $Date: 2001/08/15 19:06:25 $
|
||||
* @version $RCSfile: cpdtrans.h,v $ $Revision: 1.17 $ $Date: 2001/08/31 03:22:53 $
|
||||
* @draft
|
||||
*/
|
||||
class U_I18N_API CompoundTransliterator : public Transliterator {
|
||||
@ -83,6 +83,7 @@ public:
|
||||
CompoundTransliterator(const UnicodeString& id,
|
||||
UTransDirection dir,
|
||||
UnicodeFilter* adoptedFilter,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
@ -91,6 +92,7 @@ public:
|
||||
* @draft
|
||||
*/
|
||||
CompoundTransliterator(const UnicodeString& id,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
@ -179,6 +181,7 @@ private:
|
||||
const UnicodeString& idBlock,
|
||||
int32_t idSplitPoint,
|
||||
Transliterator *adoptedTrans,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
@ -193,6 +196,7 @@ private:
|
||||
int32_t idSplitPoint,
|
||||
Transliterator *adoptedRbt,
|
||||
UBool fixReverseID,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
void init(UVector& list,
|
||||
|
@ -477,8 +477,8 @@ private:
|
||||
|
||||
void _construct(const UnicodeString& rules,
|
||||
UTransDirection direction,
|
||||
UErrorCode& status,
|
||||
UParseError* parseError = 0);
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -496,7 +496,7 @@ inline RuleBasedTransliterator::RuleBasedTransliterator(
|
||||
UParseError& parseError,
|
||||
UErrorCode& status) :
|
||||
Transliterator(id, adoptedFilter) {
|
||||
_construct(rules, direction, status, &parseError);
|
||||
_construct(rules, direction,parseError,status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -513,7 +513,8 @@ inline RuleBasedTransliterator::RuleBasedTransliterator(
|
||||
UnicodeFilter* adoptedFilter,
|
||||
UErrorCode& status) :
|
||||
Transliterator(id, adoptedFilter) {
|
||||
_construct(rules, direction, status);
|
||||
UParseError parseError;
|
||||
_construct(rules, direction,parseError, status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -525,7 +526,8 @@ inline RuleBasedTransliterator::RuleBasedTransliterator(
|
||||
UTransDirection direction,
|
||||
UErrorCode& status) :
|
||||
Transliterator(id, 0) {
|
||||
_construct(rules, direction, status);
|
||||
UParseError parseError;
|
||||
_construct(rules, direction,parseError, status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -536,7 +538,8 @@ inline RuleBasedTransliterator::RuleBasedTransliterator(
|
||||
const UnicodeString& rules,
|
||||
UErrorCode& status) :
|
||||
Transliterator(id, 0) {
|
||||
_construct(rules, UTRANS_FORWARD, status);
|
||||
UParseError parseError;
|
||||
_construct(rules, UTRANS_FORWARD, parseError, status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -548,7 +551,8 @@ inline RuleBasedTransliterator::RuleBasedTransliterator(
|
||||
UnicodeFilter* adoptedFilter,
|
||||
UErrorCode& status) :
|
||||
Transliterator(id, adoptedFilter) {
|
||||
_construct(rules, UTRANS_FORWARD, status);
|
||||
UParseError parseError;
|
||||
_construct(rules, UTRANS_FORWARD,parseError, status);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -278,7 +278,7 @@ protected:
|
||||
UTransDirection dir,
|
||||
int32_t idSplitPoint,
|
||||
Transliterator *adoptedSplitTrans,
|
||||
UParseError* parseError,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
@ -291,7 +291,7 @@ protected:
|
||||
Transliterator *adoptedSplitTrans,
|
||||
UVector& result,
|
||||
int32_t& splitTransIndex,
|
||||
UParseError* parseError,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
/**
|
||||
* Internal parsing method for subclasses.
|
||||
@ -301,8 +301,9 @@ protected:
|
||||
int32_t& pos,
|
||||
UBool& sawDelimiter,
|
||||
UTransDirection dir,
|
||||
UParseError* parseError,
|
||||
UBool create);
|
||||
UParseError& parseError,
|
||||
UBool create,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Internal parsing method for parseID.
|
||||
@ -677,7 +678,7 @@ public:
|
||||
* @see #registerInstance
|
||||
* @draft
|
||||
*/
|
||||
Transliterator* createInverse(void) const;
|
||||
Transliterator* createInverse(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Returns a <code>Transliterator</code> object given its ID.
|
||||
@ -693,9 +694,13 @@ public:
|
||||
* @draft
|
||||
*/
|
||||
static Transliterator* createInstance(const UnicodeString& ID,
|
||||
UTransDirection dir = UTRANS_FORWARD,
|
||||
UParseError* parseError = 0);
|
||||
UTransDirection dir,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
static Transliterator* createInstance(const UnicodeString& ID,
|
||||
UTransDirection dir,
|
||||
UErrorCode& status);
|
||||
/**
|
||||
* Returns a <code>Transliterator</code> object constructed from
|
||||
* the given rule string. This will be a RuleBasedTransliterator,
|
||||
@ -706,8 +711,9 @@ public:
|
||||
*/
|
||||
static Transliterator* createFromRules(const UnicodeString& ID,
|
||||
const UnicodeString& rules,
|
||||
UTransDirection dir = UTRANS_FORWARD,
|
||||
UParseError* parseError = 0);
|
||||
UTransDirection dir,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create a rule string that can be passed to createFromRules()
|
||||
|
@ -58,7 +58,7 @@ typedef void* UTransliterator;
|
||||
* @draft
|
||||
*/
|
||||
typedef enum _UTransDirection {
|
||||
|
||||
|
||||
/**
|
||||
* UTRANS_FORWARD means from <source> to <target> for a
|
||||
* transliterator with ID <source>-<target>. For a transliterator
|
||||
@ -134,7 +134,7 @@ typedef struct _UTransPosition {
|
||||
/********************************************************************
|
||||
* General API
|
||||
********************************************************************/
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Open a system transliterator, given its ID. Any non-NULL result
|
||||
* from this function should later be closed with utrans_close().
|
||||
@ -179,6 +179,15 @@ utrans_openRules(const char* id,
|
||||
UTransDirection dir,
|
||||
UParseError* parseErr, /* may be NULL */
|
||||
UErrorCode* status);
|
||||
#endif
|
||||
|
||||
U_CAPI UTransliterator*
|
||||
utrans_open(const char* id,
|
||||
UTransDirection dir,
|
||||
const UChar* rules, /* may be Null */
|
||||
int32_t rulesLength, /* -1 if null-terminated */
|
||||
UParseError* parseError, /* may be Null */
|
||||
UErrorCode* status);
|
||||
|
||||
/**
|
||||
* Open an inverse of an existing transliterator. For this to work,
|
||||
@ -481,4 +490,31 @@ utrans_transIncrementalUChars(const UTransliterator* trans,
|
||||
UTransPosition* pos,
|
||||
UErrorCode* status);
|
||||
|
||||
|
||||
/********************* Deprecated API ************************************/
|
||||
/**
|
||||
*@deprecated Remove after Aug 2002
|
||||
*/
|
||||
|
||||
#ifdef U_USE_DEPRECATED_FORMAT_API
|
||||
|
||||
#if ((U_ICU_VERSION_MAJOR_NUM != 1) || (U_ICU_VERSION_MINOR_NUM !=9))
|
||||
# error "ICU version has changed. Please redefine the macros under U_USE_DEPRECATED_FORMAT_API pre-processor definition"
|
||||
#else
|
||||
U_CAPI UTransliterator*
|
||||
utrans_openRules(const char* id,
|
||||
const UChar* rules,
|
||||
int32_t rulesLength, /* -1 if null-terminated */
|
||||
UTransDirection dir,
|
||||
UParseError* parseErr, /* may be NULL */
|
||||
UErrorCode* status){
|
||||
return utrans_open(id,dir,rules,rulesLength,parseErr,status);
|
||||
}
|
||||
|
||||
# define utrans_open_1_9(id,dir,status) utrans_open(id,dir,NULL,0,NULL,status)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/********************* End **********************************************/
|
||||
|
||||
#endif
|
||||
|
@ -128,10 +128,12 @@ _utrans_copyUnicodeStringToChars(const UnicodeString& str,
|
||||
/********************************************************************
|
||||
* General API
|
||||
********************************************************************/
|
||||
#if 0
|
||||
|
||||
U_CAPI UTransliterator*
|
||||
utrans_open(const char* id,
|
||||
UTransDirection dir,
|
||||
UParseError* parseError,
|
||||
UErrorCode* status) {
|
||||
|
||||
utrans_ENTRY(status) NULL;
|
||||
@ -144,7 +146,7 @@ utrans_open(const char* id,
|
||||
UnicodeString ID(id, ""); // use invariant converter
|
||||
Transliterator *trans = NULL;
|
||||
|
||||
trans = Transliterator::createInstance(ID, dir, NULL);
|
||||
trans = Transliterator::createInstance(ID, dir, *parseError, *status);
|
||||
|
||||
if (trans == NULL) {
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
@ -192,6 +194,57 @@ utrans_openRules(const char* id,
|
||||
}
|
||||
return (UTransliterator*) trans;
|
||||
}
|
||||
#endif
|
||||
|
||||
U_CAPI UTransliterator*
|
||||
utrans_open(const char* id,
|
||||
UTransDirection dir,
|
||||
const UChar* rules, /* may be Null */
|
||||
int32_t rulesLength, /* -1 if null-terminated */
|
||||
UParseError* parseError, /* may be Null */
|
||||
UErrorCode* status) {
|
||||
|
||||
utrans_ENTRY(status) NULL;
|
||||
|
||||
if (id == NULL) {
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
UParseError temp;
|
||||
|
||||
if(parseError == NULL){
|
||||
parseError = &temp;
|
||||
}
|
||||
|
||||
UnicodeString ID(id, ""); // use invariant converter
|
||||
|
||||
if(rules==NULL){
|
||||
|
||||
Transliterator *trans = NULL;
|
||||
|
||||
trans = Transliterator::createInstance(ID, dir, *parseError, *status);
|
||||
|
||||
if(U_FAILURE(*status)){
|
||||
return NULL;
|
||||
}
|
||||
return (UTransliterator*) trans;
|
||||
}else{
|
||||
UnicodeString ruleStr(rulesLength < 0,
|
||||
rules,
|
||||
rulesLength); // r-o alias
|
||||
|
||||
RuleBasedTransliterator *trans = NULL;
|
||||
trans = new RuleBasedTransliterator(ID, ruleStr, dir,
|
||||
NULL, *parseError, *status);
|
||||
if (trans == NULL) {
|
||||
*status = U_MEMORY_ALLOCATION_ERROR;
|
||||
} else if (U_FAILURE(*status)) {
|
||||
delete trans;
|
||||
trans = NULL;
|
||||
}
|
||||
return (UTransliterator*) trans;
|
||||
}
|
||||
}
|
||||
|
||||
U_CAPI UTransliterator*
|
||||
utrans_openInverse(const UTransliterator* trans,
|
||||
@ -200,11 +253,7 @@ utrans_openInverse(const UTransliterator* trans,
|
||||
utrans_ENTRY(status) NULL;
|
||||
|
||||
UTransliterator* result =
|
||||
(UTransliterator*) ((Transliterator*) trans)->createInverse();
|
||||
|
||||
if (result == NULL) {
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
}
|
||||
(UTransliterator*) ((Transliterator*) trans)->createInverse(*status);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ static void TestAPI() {
|
||||
|
||||
/* Test open */
|
||||
utrans_getAvailableID(0, buf, BUF_CAP);
|
||||
trans = utrans_open(buf, UTRANS_FORWARD, &status);
|
||||
trans = utrans_open(buf, UTRANS_FORWARD,NULL,0,NULL, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
log_err("FAIL: utrans_open(%s) failed, error=%s\n",
|
||||
buf, u_errorName(status));
|
||||
@ -186,7 +186,7 @@ static void TestOpenInverse(){
|
||||
};
|
||||
|
||||
for(i=0; i<sizeof(TransID)/sizeof(TransID[0]); i=i+2){
|
||||
t1=utrans_open(TransID[i], UTRANS_FORWARD, &status);
|
||||
t1=utrans_open(TransID[i], UTRANS_FORWARD,NULL,0,NULL, &status);
|
||||
if(t1 == NULL || U_FAILURE(status)){
|
||||
log_err("FAIL: in instantiation for id=%s\n", TransID[i]);
|
||||
continue;
|
||||
@ -214,12 +214,12 @@ static void TestClone(){
|
||||
enum { BUF_CAP = 128 };
|
||||
char buf1[BUF_CAP], buf2[BUF_CAP], buf3[BUF_CAP];
|
||||
|
||||
t1=utrans_open("Latin-Devanagari", UTRANS_FORWARD, &status);
|
||||
t1=utrans_open("Latin-Devanagari", UTRANS_FORWARD, NULL,0,NULL,&status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("FAIL: construction\n");
|
||||
return;
|
||||
}
|
||||
t2=utrans_open("Latin-Hebrew", UTRANS_FORWARD, &status);
|
||||
t2=utrans_open("Latin-Hebrew", UTRANS_FORWARD, NULL,0,NULL,&status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("FAIL: construction\n");
|
||||
utrans_close(t1);
|
||||
@ -260,21 +260,21 @@ static void TestRegisterUnregister(){
|
||||
UChar rule[]={ 0x0061, 0x003c, 0x003e, 0x0063}; /*a<>b*/
|
||||
|
||||
/* Make sure it doesn't exist */
|
||||
t1=utrans_open("TestA-TestB", UTRANS_FORWARD, &status);
|
||||
t1=utrans_open("TestA-TestB", UTRANS_FORWARD,NULL,0,NULL, &status);
|
||||
if(t1 != NULL || U_SUCCESS(status)) {
|
||||
log_err("FAIL: TestA-TestB already registered\n");
|
||||
return;
|
||||
}
|
||||
status=U_ZERO_ERROR;
|
||||
/* Check inverse too */
|
||||
inverse1=utrans_open("TestA-TestB", UTRANS_REVERSE, &status);
|
||||
inverse1=utrans_open("TestA-TestB", UTRANS_REVERSE, NULL,0,NULL,&status);
|
||||
if(inverse1 != NULL || U_SUCCESS(status)) {
|
||||
log_err("FAIL: TestA-TestB already registered\n");
|
||||
return;
|
||||
}
|
||||
status=U_ZERO_ERROR;
|
||||
/* Create it */
|
||||
rules=utrans_openRules("TestA-TestB", rule, 4, UTRANS_FORWARD, NULL, &status);
|
||||
rules=utrans_open("TestA-TestB",UTRANS_FORWARD, rule, 4, NULL, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("FAIL: utrans_openRules(a<>B) failed with error=%s\n", myErrorName(status));
|
||||
return;
|
||||
@ -288,7 +288,7 @@ static void TestRegisterUnregister(){
|
||||
}
|
||||
status=U_ZERO_ERROR;
|
||||
/* Now check again -- should exist now*/
|
||||
t1= utrans_open("TestA-TestB", UTRANS_FORWARD, &status);
|
||||
t1= utrans_open("TestA-TestB", UTRANS_FORWARD, NULL,0,NULL,&status);
|
||||
if(U_FAILURE(status) || t1 == NULL){
|
||||
log_err("FAIL: TestA-TestB not registered\n");
|
||||
return;
|
||||
@ -299,7 +299,7 @@ static void TestRegisterUnregister(){
|
||||
status=U_ZERO_ERROR;
|
||||
utrans_unregister("TestA-TestB");
|
||||
/* now Make sure it doesn't exist */
|
||||
t1=utrans_open("TestA-TestB", UTRANS_FORWARD, &status);
|
||||
t1=utrans_open("TestA-TestB", UTRANS_FORWARD,NULL,0,NULL, &status);
|
||||
if(U_SUCCESS(status) || t1 != NULL) {
|
||||
log_err("FAIL: TestA-TestB isn't unregistered\n");
|
||||
return;
|
||||
@ -374,7 +374,7 @@ static void TestFilter() {
|
||||
int32_t DATA_length = sizeof(DATA) / sizeof(DATA[0]);
|
||||
int32_t i;
|
||||
|
||||
UTransliterator* hex = utrans_open("Any-Hex", UTRANS_FORWARD, &status);
|
||||
UTransliterator* hex = utrans_open("Any-Hex", UTRANS_FORWARD, NULL,0,NULL,&status);
|
||||
|
||||
if (hex == 0 || U_FAILURE(status)) {
|
||||
log_err("FAIL: utrans_open(Unicode-Hex) failed, error=%s\n",
|
||||
@ -432,7 +432,7 @@ static void _expectRules(const char* crules,
|
||||
|
||||
u_uastrcpy(rules, crules);
|
||||
|
||||
trans = utrans_openRules(crules /*use rules as ID*/, rules, -1, UTRANS_FORWARD,
|
||||
trans = utrans_open(crules /*use rules as ID*/, UTRANS_FORWARD, rules, -1,
|
||||
&parseErr, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
utrans_close(trans);
|
||||
|
Loading…
Reference in New Issue
Block a user