ICU-450 change ParseError, Transliterator::Direction, Transliterator::Position to C structs

X-SVN-Rev: 1655
This commit is contained in:
Alan Liu 2000-06-27 19:00:38 +00:00
parent 1dea4931f1
commit 76de7c04e3
21 changed files with 111 additions and 249 deletions

View file

@ -40,7 +40,7 @@ CompoundTransliterator::CompoundTransliterator(
* takes the inverse of each ID.
*/
CompoundTransliterator::CompoundTransliterator(const UnicodeString& ID,
Transliterator::Direction direction,
UTransDirection direction,
UnicodeFilter* adoptedFilter,
UErrorCode& status) :
Transliterator(ID, 0), // set filter to 0 here!
@ -52,18 +52,18 @@ CompoundTransliterator::CompoundTransliterator(const UnicodeString& ID,
UErrorCode& status) :
Transliterator(ID, 0), // set filter to 0 here!
filters(0), trans(0) {
init(ID, FORWARD, 0, status);
init(ID, UTRANS_FORWARD, 0, status);
}
void CompoundTransliterator::init(const UnicodeString& ID,
Transliterator::Direction direction,
UTransDirection direction,
UnicodeFilter* adoptedFilter,
UErrorCode& status) {
if (U_FAILURE(status)) return;
UnicodeString* list = split(ID, ID_DELIM, count);
trans = new Transliterator*[count];
for (int32_t i = 0; i < count; ++i) {
trans[i] = createInstance(list[direction==FORWARD ? i : (count-1-i)],
trans[i] = createInstance(list[direction==UTRANS_FORWARD ? i : (count-1-i)],
direction);
if (trans[i] == NULL) {
while (++i < count) trans[i] = 0;
@ -285,7 +285,7 @@ void CompoundTransliterator::adoptFilter(UnicodeFilter* f) {
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
void CompoundTransliterator::handleTransliterate(Replaceable& text, Position& index,
void CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPosition& index,
UBool incremental) const {
/* Call each transliterator with the same start value and
* initial cursor index, but with the limit index as modified

View file

@ -62,7 +62,7 @@ Transliterator* HangulJamoTransliterator::clone(void) const {
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
void HangulJamoTransliterator::handleTransliterate(Replaceable& text, Position& offsets,
void HangulJamoTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const {
int32_t cursor = offsets.cursor;
int32_t limit = offsets.limit;

View file

@ -237,7 +237,7 @@ const UnicodeString& HexToUnicodeTransliterator::toPattern(void) const {
return pattern;
}
void HexToUnicodeTransliterator::handleTransliterate(Replaceable& text, Position& offsets,
void HexToUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const {
int32_t cursor = offsets.cursor;
int32_t limit = offsets.limit;

View file

@ -51,7 +51,7 @@ Transliterator* JamoHangulTransliterator::clone(void) const {
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
void JamoHangulTransliterator::handleTransliterate(Replaceable& text, Position& offsets,
void JamoHangulTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const {
/**
* Performs transliteration changing Jamo to Hangul

View file

@ -20,7 +20,7 @@ int32_t NullTransliterator::transliterate(Replaceable&, int32_t,
return limit;
}
void NullTransliterator::handleTransliterate(Replaceable& text, Position& offsets,
void NullTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const {
offsets.cursor = offsets.limit;
}

View file

@ -14,9 +14,9 @@
#include "unicode/rep.h"
void RuleBasedTransliterator::_construct(const UnicodeString& rules,
Direction direction,
UTransDirection direction,
UErrorCode& status,
ParseError* parseError) {
UParseError* parseError) {
data = 0;
isDataOwned = TRUE;
if (U_SUCCESS(status)) {
@ -71,7 +71,7 @@ RuleBasedTransliterator::clone(void) const {
* Implements {@link Transliterator#handleTransliterate}.
*/
void
RuleBasedTransliterator::handleTransliterate(Replaceable& text, Position& index,
RuleBasedTransliterator::handleTransliterate(Replaceable& text, UTransPosition& index,
UBool isIncremental) const {
/* We keep start and limit fixed the entire time,
* relative to the text -- limit may move numerically if text is

View file

@ -462,8 +462,8 @@ int32_t* RuleHalf::createSegments() const {
TransliterationRuleData*
TransliterationRuleParser::parse(const UnicodeString& rules,
RuleBasedTransliterator::Direction direction,
ParseError* parseError) {
UTransDirection direction,
UParseError* parseError) {
TransliterationRuleParser parser(rules, direction, parseError);
parser.parseRules();
if (U_FAILURE(parser.status)) {
@ -480,8 +480,8 @@ TransliterationRuleParser::parse(const UnicodeString& rules,
*/
TransliterationRuleParser::TransliterationRuleParser(
const UnicodeString& theRules,
RuleBasedTransliterator::Direction theDirection,
ParseError* theParseError) :
UTransDirection theDirection,
UParseError* theParseError) :
rules(theRules), direction(theDirection), data(0), parseError(theParseError) {
parseData = new ParseData(0, &setVariablesVector);
}
@ -650,13 +650,13 @@ int32_t TransliterationRuleParser::parseRule(int32_t pos, int32_t limit) {
// If the direction we want doesn't match the rule
// direction, do nothing.
if (op != FWDREV_RULE_OP &&
((direction == Transliterator::FORWARD) != (op == FORWARD_RULE_OP))) {
((direction == UTRANS_FORWARD) != (op == FORWARD_RULE_OP))) {
return pos;
}
// Transform the rule into a forward rule by swapping the
// sides if necessary.
if (direction == Transliterator::REVERSE) {
if (direction == UTRANS_REVERSE) {
left = &_right;
right = &_left;
}
@ -735,10 +735,13 @@ int32_t TransliterationRuleParser::syntaxError(int32_t parseErrorCode,
if (end < 0) {
end = rule.length();
}
if (end > (start + 80)) { // In case end wasn't found
end = start + 80;
}
rule.extractBetween(start, end, parseError->context); // Current rule
int32_t len = uprv_max(end - start, U_PARSE_CONTEXT_LEN-1);
// Extract everything into the preContext and leave the postContext
// blank, since we don't have precise error position.
// TODO: Fix this.
rule.extract(start, len, parseError->preContext); // Current rule
parseError->preContext[len] = 0;
parseError->postContext[0] = 0;
}
status = U_ILLEGAL_ARGUMENT_ERROR;
return start;

View file

@ -26,7 +26,7 @@ class TransliterationRuleParser {
*/
const UnicodeString& rules;
RuleBasedTransliterator::Direction direction;
UTransDirection direction;
TransliterationRuleData* data;
@ -40,7 +40,7 @@ class TransliterationRuleParser {
* Pointer to user structure in which to return parse error information.
* May be NULL.
*/
ParseError* parseError;
UParseError* parseError;
/**
* Temporary symbol table used during parsing.
@ -84,8 +84,8 @@ public:
static TransliterationRuleData*
parse(const UnicodeString& rules,
RuleBasedTransliterator::Direction direction,
ParseError* parseError = 0);
UTransDirection direction,
UParseError* parseError = 0);
private:
@ -95,8 +95,8 @@ private:
* rules
*/
TransliterationRuleParser(const UnicodeString& rules,
RuleBasedTransliterator::Direction direction,
ParseError* parseError = 0);
UTransDirection direction,
UParseError* parseError = 0);
/**
* Destructor.

View file

@ -158,7 +158,7 @@ Transliterator& Transliterator::operator=(const Transliterator& other) {
int32_t Transliterator::transliterate(Replaceable& text,
int32_t start, int32_t limit) const {
Position offsets(start, limit);
UTransPosition offsets = { start, limit, start, limit };
handleTransliterate(text, offsets, FALSE);
return offsets.limit;
}
@ -236,7 +236,7 @@ void Transliterator::transliterate(Replaceable& text) const {
* is invalid
*/
void Transliterator::transliterate(Replaceable& text,
Position& index,
UTransPosition& index,
const UnicodeString& insertion,
UErrorCode &status) const {
_transliterate(text, index, &insertion, status);
@ -258,7 +258,7 @@ void Transliterator::transliterate(Replaceable& text,
* @see #transliterate(Replaceable, int[], String)
*/
void Transliterator::transliterate(Replaceable& text,
Position& index,
UTransPosition& index,
UChar insertion,
UErrorCode& status) const {
UnicodeString str(insertion);
@ -277,7 +277,7 @@ void Transliterator::transliterate(Replaceable& text,
* @see #transliterate(Replaceable, int[], String)
*/
void Transliterator::transliterate(Replaceable& text,
Position& index,
UTransPosition& index,
UErrorCode& status) const {
_transliterate(text, index, 0, status);
}
@ -293,7 +293,7 @@ void Transliterator::transliterate(Replaceable& text,
* #transliterate}
*/
void Transliterator::finishTransliteration(Replaceable& text,
Position& index) const {
UTransPosition& index) const {
transliterate(text, index.start, index.limit);
}
@ -305,7 +305,7 @@ void Transliterator::finishTransliteration(Replaceable& text,
* work.
*/
void Transliterator::_transliterate(Replaceable& text,
Position& index,
UTransPosition& index,
const UnicodeString* insertion,
UErrorCode &status) const {
if (U_FAILURE(status)) {
@ -528,7 +528,7 @@ void Transliterator::adoptFilter(UnicodeFilter* filterToAdopt) {
* @see #registerInstance
*/
Transliterator* Transliterator::createInverse(void) const {
return Transliterator::createInstance(ID, REVERSE);
return Transliterator::createInstance(ID, UTRANS_REVERSE);
}
/**
@ -543,8 +543,8 @@ Transliterator* Transliterator::createInverse(void) const {
* @see #getID
*/
Transliterator* Transliterator::createInstance(const UnicodeString& ID,
Transliterator::Direction dir,
ParseError* parseError) {
UTransDirection dir,
UParseError* parseError) {
Transliterator* t = 0;
if (ID.indexOf(ID_DELIM) >= 0) {
UErrorCode status = U_ZERO_ERROR;
@ -554,7 +554,7 @@ Transliterator* Transliterator::createInstance(const UnicodeString& ID,
t = 0;
}
} else {
if (dir == REVERSE) {
if (dir == UTRANS_REVERSE) {
int32_t i = ID.indexOf(ID_SEP);
if (i >= 0) {
UnicodeString inverseID, right;
@ -624,7 +624,7 @@ const char* Transliterator::getDataDirectory(void) {
* this method returns null if it cannot make use of the given ID.
*/
Transliterator* Transliterator::_createInstance(const UnicodeString& ID,
ParseError* parseError) {
UParseError* parseError) {
UErrorCode status = U_ZERO_ERROR;
if (!cacheInitialized) {
@ -689,8 +689,8 @@ Transliterator* Transliterator::_createInstance(const UnicodeString& ID,
if (rules.length() != 0 && U_SUCCESS(status)) {
data = TransliterationRuleParser::parse(rules, isReverse
? RuleBasedTransliterator::REVERSE
: RuleBasedTransliterator::FORWARD,
? UTRANS_REVERSE
: UTRANS_FORWARD,
parseError);
// Double check to see if someone has modified the entry

View file

@ -32,7 +32,7 @@
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Alan Liu
* @version $RCSfile: cpdtrans.h,v $ $Revision: 1.9 $ $Date: 2000/05/20 04:34:20 $
* @version $RCSfile: cpdtrans.h,v $ $Revision: 1.10 $ $Date: 2000/06/27 19:00:38 $
* @draft
*/
class U_I18N_API CompoundTransliterator : public Transliterator {
@ -74,7 +74,7 @@ public:
* @draft
*/
CompoundTransliterator(const UnicodeString& ID,
Direction dir,
UTransDirection dir,
UnicodeFilter* adoptedFilter,
UErrorCode& status);
@ -149,13 +149,13 @@ public:
* Implements {@link Transliterator#handleTransliterate}.
* @draft
*/
virtual void handleTransliterate(Replaceable& text, Position& index,
virtual void handleTransliterate(Replaceable& text, UTransPosition& index,
UBool incremental) const;
private:
void init(const UnicodeString& ID,
Direction dir,
UTransDirection dir,
UnicodeFilter* adoptedFilter,
UErrorCode& status);

View file

@ -16,7 +16,7 @@
* A transliterator that converts Hangul to Jamo.
*
* @author Mark Davis
* @version $RCSfile: hangjamo.h,v $ $Revision: 1.4 $ $Date: 2000/05/18 22:08:27 $
* @version $RCSfile: hangjamo.h,v $ $Revision: 1.5 $ $Date: 2000/06/27 19:00:38 $
*/
class U_I18N_API HangulJamoTransliterator : public Transliterator {
@ -55,7 +55,7 @@ public:
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
virtual void handleTransliterate(Replaceable& text, Position& offsets,
virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const;
private:

View file

@ -22,7 +22,7 @@
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Alan Liu
* @version $RCSfile: hextouni.h,v $ $Revision: 1.6 $ $Date: 2000/05/18 22:08:27 $
* @version $RCSfile: hextouni.h,v $ $Revision: 1.7 $ $Date: 2000/06/27 19:00:38 $
* @draft
*/
class U_I18N_API HexToUnicodeTransliterator : public Transliterator {
@ -148,7 +148,7 @@ public:
* Implements {@link Transliterator#handleTransliterate}.
* @draft
*/
virtual void handleTransliterate(Replaceable& text, Position& offset,
virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
UBool isIncremental) const;
};

View file

@ -16,7 +16,7 @@
* A transliterator that converts Jamo to Hangul.
*
* @author Mark Davis
* @version $RCSfile: jamohang.h,v $ $Revision: 1.5 $ $Date: 2000/05/18 22:08:27 $
* @version $RCSfile: jamohang.h,v $ $Revision: 1.6 $ $Date: 2000/06/27 19:00:38 $
*/
class U_I18N_API JamoHangulTransliterator : public Transliterator {
@ -55,7 +55,7 @@ public:
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
virtual void handleTransliterate(Replaceable& text, Position& offsets,
virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const;
private:

View file

@ -55,7 +55,7 @@ public:
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
virtual void handleTransliterate(Replaceable& text, Position& offset,
virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
UBool isIncremental) const;
};

View file

@ -1,24 +1,26 @@
/*
**********************************************************************
* Copyright (C) 1999, International Business Machines
* Copyright (C) 1999-2000, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
* 03/14/00 aliu Creation.
* 06/27/00 aliu Change from C++ class to C struct
**********************************************************************
*/
#ifndef PARSEERR_H
#define PARSEERR_H
#include "unicode/utypes.h"
#include "unicode/umachine.h"
#ifdef XP_CPLUSPLUS
#include "unicode/unistr.h"
/**
* A ParseError struct is used to returned detailed information about
* The capacity of the context strings in UParseError.
*/
enum { U_PARSE_CONTEXT_LEN = 16 };
/**
* A UParseError struct is used to returned detailed information about
* parsing errors. It is used by ICU parsing engines that parse long
* rules, patterns, or programs, where the text being parsed is long
* enough that more information than a UErrorCode is needed to
@ -29,61 +31,9 @@
* possible values. The line, offset, and context fields are
* optional; parsing engines may choose not to use to use them.
*
* <p>Examples of engines which use ParseError (or may use it in the
* <p>Examples of engines which use UParseError (or may use it in the
* future) are RuleBasedTransliterator and RuleBasedBreakIterator.
*/
struct ParseError {
/**
* An integer indicating the type of error. If no error was
* encountered, the parse engine sets this to zero, and the
* other fields' values should be ignored.
*
* <p>Each parse engine should use a range of codes from
* 0xNNNN0001 to 0xNNNNFFFF, where NNNN is a 16-bit integer
* between 0x0001 and 0xFFFF unique to each parse engine.
* Parse engines should define the enum PARSE_ERROR_BASE
* to be 0xNNNN0000.
*/
int32_t code;
/**
* The line on which the error occured. If the parse engine
* is not using this field, it should set it to zero. Otherwise
* it should be a positive integer.
*/
int32_t line;
/**
* The character offset to the error. If the line field is
* being used, then this offset is from the start of the line.
* If the line field is not being used, then this offset is from
* the start of the text.
*/
UTextOffset offset;
/**
* Textual context showing the error. For example, this field
* may contain a copy of the line on which the error occurs. If
* line numbers are not being used, this field may contain a copy
* of the substring offset - 8 to offset + 8 (or some other
* range).
*/
UnicodeString context;
};
#endif
/**
* The capacity of the context string in UParseError.
*/
enum { U_PARSE_ERROR_CONTEXT_LEN = 16 };
/**
* Parsing error information. For user rules the UParseError struct
* will be filled with the location of the parsing error.
*
* Related to the C++ class ParseError.
*/
typedef struct _UParseError {
/**
@ -115,18 +65,16 @@ typedef struct _UParseError {
UTextOffset offset;
/**
* Textual context showing the error. For example, this field
* may contain a copy of the line on which the error occurs. If
* line numbers are not being used, this field may contain a copy
* of the substring offset - 8 to offset + 8 (or some other
* range).
*
* Null-terminated.
*
* TODO
* Separate into left and right context
* Textual context before the error. Null-terminated.
* May be the empty string if not implemented by parser.
*/
UChar context[U_PARSE_ERROR_CONTEXT_LEN];
UChar preContext[U_PARSE_CONTEXT_LEN];
/**
* Textual context after the error. Null-terminated.
* May be the empty string if not implemented by parser.
*/
UChar postContext[U_PARSE_CONTEXT_LEN];
} UParseError;

View file

@ -276,9 +276,9 @@ public:
*/
RuleBasedTransliterator(const UnicodeString& ID,
const UnicodeString& rules,
Direction direction,
UTransDirection direction,
UnicodeFilter* adoptedFilter,
ParseError& parseError,
UParseError& parseError,
UErrorCode& status);
/**
@ -290,7 +290,7 @@ public:
*/
RuleBasedTransliterator(const UnicodeString& ID,
const UnicodeString& rules,
Direction direction,
UTransDirection direction,
UnicodeFilter* adoptedFilter,
UErrorCode& status);
@ -300,7 +300,7 @@ public:
*/
RuleBasedTransliterator(const UnicodeString& ID,
const UnicodeString& rules,
Direction direction,
UTransDirection direction,
UErrorCode& status);
/**
@ -346,7 +346,7 @@ public:
* Implements {@link Transliterator#handleTransliterate}.
* @draft
*/
virtual void handleTransliterate(Replaceable& text, Position& offsets,
virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const;
/**
@ -379,9 +379,9 @@ public:
private:
void _construct(const UnicodeString& rules,
Direction direction,
UTransDirection direction,
UErrorCode& status,
ParseError* parseError = 0);
UParseError* parseError = 0);
};
/**
@ -394,9 +394,9 @@ private:
inline RuleBasedTransliterator::RuleBasedTransliterator(
const UnicodeString& ID,
const UnicodeString& rules,
Direction direction,
UTransDirection direction,
UnicodeFilter* adoptedFilter,
ParseError& parseError,
UParseError& parseError,
UErrorCode& status) :
Transliterator(ID, adoptedFilter) {
_construct(rules, direction, status, &parseError);
@ -412,7 +412,7 @@ inline RuleBasedTransliterator::RuleBasedTransliterator(
inline RuleBasedTransliterator::RuleBasedTransliterator(
const UnicodeString& ID,
const UnicodeString& rules,
Direction direction,
UTransDirection direction,
UnicodeFilter* adoptedFilter,
UErrorCode& status) :
Transliterator(ID, adoptedFilter) {
@ -425,7 +425,7 @@ inline RuleBasedTransliterator::RuleBasedTransliterator(
inline RuleBasedTransliterator::RuleBasedTransliterator(
const UnicodeString& ID,
const UnicodeString& rules,
Direction direction,
UTransDirection direction,
UErrorCode& status) :
Transliterator(ID, 0) {
_construct(rules, direction, status);
@ -439,7 +439,7 @@ inline RuleBasedTransliterator::RuleBasedTransliterator(
const UnicodeString& rules,
UErrorCode& status) :
Transliterator(ID, 0) {
_construct(rules, FORWARD, status);
_construct(rules, UTRANS_FORWARD, status);
}
/**
@ -451,7 +451,7 @@ inline RuleBasedTransliterator::RuleBasedTransliterator(
UnicodeFilter* adoptedFilter,
UErrorCode& status) :
Transliterator(ID, adoptedFilter) {
_construct(rules, FORWARD, status);
_construct(rules, UTRANS_FORWARD, status);
}
#endif

View file

@ -10,6 +10,7 @@
#include "unicode/unistr.h"
#include "unicode/parseerr.h"
#include "unicode/utrans.h" // UTransPosition, UTransDirection
class Replaceable;
class UnicodeFilter;
@ -223,65 +224,6 @@ class CompoundTransliterator;
*/
class U_I18N_API Transliterator {
public:
/**
* Direction constant indicating the direction in a transliterator, e.g.,
* the forward or reverse rules of a RuleBasedTransliterator. An "A-B"
* transliterator transliterates A to B when operating in the forward
* direction, and B to A when operating in the reverse direction.
* @draft
*/
enum Direction {
FORWARD,
REVERSE
};
/**
* @draft
*/
class Position {
public:
/**
* In <code>transliterate()</code>, the beginning index, inclusive
*/
int32_t start;
/**
* In <code>transliterate()</code>, the ending index, exclusive
*/
int32_t limit;
/**
* In <code>transliterate()</code>, the next character to be
* considered for transliteration
*/
int32_t cursor;
/**
* In <code>transliterate()</code>, the limit character to be
* considered for transliteration
*/
int32_t end;
/**
* Constructor from start, limit. Sets cursor to start and
* end to limit.
*/
Position(int32_t start, int32_t limit);
/**
* Constructor from start, limit, cursor. Sets
* end to limit.
*/
Position(int32_t start, int32_t limit, int32_t cursor);
/**
* Constructor from start, limit, cursor, end.
*/
Position(int32_t start, int32_t limit,
int32_t cursor, int32_t end);
};
private:
/**
@ -540,7 +482,7 @@ public:
* is invalid
* @draft
*/
virtual void transliterate(Replaceable& text, Position& index,
virtual void transliterate(Replaceable& text, UTransPosition& index,
const UnicodeString& insertion,
UErrorCode& status) const;
@ -560,7 +502,7 @@ public:
* @see #transliterate(Replaceable, int[], String)
* @draft
*/
virtual void transliterate(Replaceable& text, Position& index,
virtual void transliterate(Replaceable& text, UTransPosition& index,
UChar insertion,
UErrorCode& status) const;
@ -576,7 +518,7 @@ public:
* @see #transliterate(Replaceable, int[], String)
* @draft
*/
virtual void transliterate(Replaceable& text, Position& index,
virtual void transliterate(Replaceable& text, UTransPosition& index,
UErrorCode& status) const;
/**
@ -591,7 +533,7 @@ public:
* @draft
*/
virtual void finishTransliteration(Replaceable& text,
Position& index) const;
UTransPosition& index) const;
private:
@ -603,7 +545,7 @@ private:
* work.
*/
void _transliterate(Replaceable& text,
Position& index,
UTransPosition& index,
const UnicodeString* insertion,
UErrorCode &status) const;
@ -633,7 +575,7 @@ protected:
* @see #transliterate
*/
virtual void handleTransliterate(Replaceable& text,
Position& index,
UTransPosition& index,
UBool incremental) const = 0;
// C++ requires this friend declaration so CompoundTransliterator
@ -774,8 +716,8 @@ public:
* @draft
*/
static Transliterator* createInstance(const UnicodeString& ID,
Direction dir = FORWARD,
ParseError* parseError = 0);
UTransDirection dir = UTRANS_FORWARD,
UParseError* parseError = 0);
private:
@ -805,7 +747,7 @@ private:
* this method returns null if it cannot make use of the given ID.
*/
static Transliterator* _createInstance(const UnicodeString& ID,
ParseError* parseError = 0);
UParseError* parseError = 0);
public:
@ -937,15 +879,4 @@ inline void Transliterator::setID(const UnicodeString& id) {
ID = id;
}
inline Transliterator::Position::Position(int32_t aStart, int32_t aLimit) :
start(aStart), limit(aLimit), cursor(aStart), end(aLimit) {}
inline Transliterator::Position::Position(int32_t aStart, int32_t aLimit,
int32_t aCursor) :
start(aStart), limit(aLimit), cursor(aCursor), end(aLimit) {}
inline Transliterator::Position::Position(int32_t aStart, int32_t aLimit,
int32_t aCursor, int32_t anEnd) :
start(aStart), limit(aLimit), cursor(aCursor), end(anEnd) {}
#endif

View file

@ -190,7 +190,7 @@ public:
* Implements {@link Transliterator#handleTransliterate}.
* @draft
*/
virtual void handleTransliterate(Replaceable& text, Position& offsets,
virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const;
};

View file

@ -45,12 +45,14 @@
typedef void* UTransliterator;
/**
* Direction of transliteration, specified when a transliterator is
* opened. Related to the C++ enum Transliterator::Direction.
* Direction constant indicating the direction in a transliterator,
* e.g., the forward or reverse rules of a RuleBasedTransliterator.
* Specified when a transliterator is opened. An "A-B" transliterator
* transliterates A to B when operating in the forward direction, and
* B to A when operating in the reverse direction.
* @draft
*/
typedef enum _UTransDirection {
/* IMPORTANT: MUST MATCH Transliterator::Direction */
/**
* UTRANS_FORWARD means from <source> to <target> for a
@ -67,6 +69,7 @@ typedef enum _UTransDirection {
* "A < B".
*/
UTRANS_REVERSE
} UTransDirection;
/**
@ -76,8 +79,6 @@ typedef enum _UTransDirection {
* text. There are two sets of indices to accomodate users that wish
* to transliterate a substring but make surrounding text available as
* context.
*
* Related to the C++ class Transliterator::Position.
* TODO FIX:
* doc that this is input/output

View file

@ -219,7 +219,7 @@ void UnicodeToHexTransliterator::setUppercase(UBool outputUppercase) {
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
void UnicodeToHexTransliterator::handleTransliterate(Replaceable& text, Position& offsets,
void UnicodeToHexTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const {
/**
* Performs transliteration changing all characters to

View file

@ -103,20 +103,6 @@ void ReplaceableGlue::copy(int32_t start, int32_t limit, int32_t dest) {
* PRIVATE Implementation
********************************************************************/
/**
* Copy a ParseError into a UParseError.
*/
static void
_utrans_copyParseError(const ParseError& err, UParseError* parseErr) {
parseErr->code = err.code;
parseErr->line = err.line;
parseErr->offset = err.offset;
int32_t len = uprv_min(err.context.length(),
U_PARSE_ERROR_CONTEXT_LEN-1);
err.context.extractBetween(0, len, parseErr->context);
parseErr->context[len] = 0;
}
/**
* Extract a UnicodeString to a char* buffer using the invariant
* converter and return the actual length.
@ -154,8 +140,7 @@ utrans_open(const char* id,
UnicodeString ID(id, ""); // use invariant converter
Transliterator *trans = NULL;
trans = Transliterator::createInstance(ID,
(Transliterator::Direction) dir, NULL);
trans = Transliterator::createInstance(ID, dir, NULL);
if (trans == NULL) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
@ -188,13 +173,11 @@ utrans_openRules(const char* id,
// Use if() to avoid construction of ParseError object on stack
// unless it is called for by user.
if (parseErr != NULL) {
ParseError err;
trans = new RuleBasedTransliterator(ID, ruleStr,
(Transliterator::Direction) dir, NULL, err, *status);
_utrans_copyParseError(err, parseErr);
trans = new RuleBasedTransliterator(ID, ruleStr, dir,
NULL, *parseErr, *status);
} else {
trans = new RuleBasedTransliterator(ID, ruleStr,
(Transliterator::Direction) dir, NULL, *status);
trans = new RuleBasedTransliterator(ID, ruleStr, dir,
NULL, *status);
}
if (trans == NULL) {
@ -340,9 +323,7 @@ utrans_transIncremental(const UTransliterator* trans,
ReplaceableGlue r(rep, repFunc);
Transliterator::Position p(pos->start, pos->limit, pos->cursor, pos->end);
((Transliterator*) trans)->transliterate(r, p, *status);
((Transliterator*) trans)->transliterate(r, *pos, *status);
}
U_CAPI void
@ -393,9 +374,7 @@ utrans_transIncrementalUChars(const UTransliterator* trans,
// writeable alias: for this ct, len CANNOT be -1 (why?)
UnicodeString str(text, textLen, textCapacity);
Transliterator::Position p(pos->start, pos->limit, pos->cursor, pos->end);
((Transliterator*) trans)->transliterate(str, p, *status);
((Transliterator*) trans)->transliterate(str, *pos, *status);
// Copy the string buffer back to text (only if necessary)
// and fill in *neededCapacity (if neededCapacity != NULL).