ICU-276 added Position constructors

X-SVN-Rev: 750
This commit is contained in:
Alan Liu 2000-02-11 22:32:11 +00:00
parent 81ed01173b
commit e7209482d2
4 changed files with 46 additions and 16 deletions

View File

@ -155,12 +155,7 @@ Transliterator& Transliterator::operator=(const Transliterator& other) {
int32_t Transliterator::transliterate(Replaceable& text,
int32_t start, int32_t limit) const {
Position offsets; /* Broken HPUX compiler cannot handle this */
offsets.start = start;
offsets.limit = limit;
offsets.cursor = start;
Position offsets(start, limit);
handleTransliterate(text, offsets, FALSE);
return offsets.limit;
}

View File

@ -251,6 +251,30 @@ public:
* 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:
@ -871,4 +895,15 @@ inline int32_t Transliterator::getMaximumContextLength(void) const {
return maximumContextLength;
}
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

@ -377,7 +377,7 @@ void TransliteratorAPITest::TestSimpleKeyboardTransliterator(){
Transliterator* t=Transliterator::createInstance("Unicode-Hex");
if(t == 0)
errln("FAIL : construction");
Transliterator::Position index={19,20,20};
Transliterator::Position index(19,20,20);
UnicodeString rs= "Transliterate this-''";
UnicodeString insertion="abc";
UnicodeString expected="Transliterate this-'\\u0061\\u0062\\u0063'";
@ -391,10 +391,10 @@ void TransliteratorAPITest::TestSimpleKeyboardTransliterator(){
logln("try calling transliterate with invalid index values");
Transliterator::Position index1[]={
//START, LIMIT, CURSOR
{10, 10, 12}, //invalid since CURSOR>LIMIT valid:-START <= CURSOR <= LIMIT
{17, 16, 17}, //invalid since START>LIMIT valid:-0<=START<=LIMIT
{-1, 16, 14}, //invalid since START<0
{3, 50, 2 } //invalid since LIMIT>text.length()
Transliterator::Position(10, 10, 12), //invalid since CURSOR>LIMIT valid:-START <= CURSOR <= LIMIT
Transliterator::Position(17, 16, 17), //invalid since START>LIMIT valid:-0<=START<=LIMIT
Transliterator::Position(-1, 16, 14), //invalid since START<0
Transliterator::Position(3, 50, 2 ) //invalid since LIMIT>text.length()
};
for(int i=0; i<sizeof(index1)/sizeof(index1[0]); i++){
status=U_ZERO_ERROR;
@ -424,7 +424,7 @@ void TransliteratorAPITest::TestKeyboardTransliterator1(){
};
Transliterator* t=Transliterator::createInstance("Unicode-Hex");
//keyboardAux(t, Data);
Transliterator::Position index = {0, 0, 0};
Transliterator::Position index(0, 0);
UErrorCode status=U_ZERO_ERROR;
UnicodeString s;
int i;
@ -522,7 +522,7 @@ void TransliteratorAPITest::TestKeyboardTransliterator3(){
};
UErrorCode status=U_ZERO_ERROR;
Transliterator::Position index={0, 0, 0};
Transliterator::Position index(0, 0);
logln("Testing transliterate(Replaceable, int32_t, UErrorCode)");
Transliterator *t=Transliterator::createInstance("Unicode-Hex");
if(t == 0)
@ -655,7 +655,7 @@ void TransliteratorAPITest::TestGetAdoptFilter(){
void TransliteratorAPITest::keyboardAux(Transliterator *t, UnicodeString DATA[], UnicodeString& s, int32_t begin, int32_t end) {
Transliterator::Position index = {0, 0, 0};
Transliterator::Position index(0, 0);
UErrorCode status=U_ZERO_ERROR;
for (int32_t i=begin; i<end; i=i+5) {
UnicodeString log;

View File

@ -302,7 +302,7 @@ void TransliteratorTest::TestKeyboard3(void) {
void TransliteratorTest::keyboardAux(const Transliterator& t,
const char* DATA[], int32_t DATA_length) {
UErrorCode status = U_ZERO_ERROR;
Transliterator::Position index = {0, 0, 0};
Transliterator::Position index(0, 0);
UnicodeString s;
for (int32_t i=0; i<DATA_length; i+=2) {
UnicodeString log;
@ -506,7 +506,7 @@ void TransliteratorTest::expect(const Transliterator& t,
// Test keyboard (incremental) transliteration -- this result
// must be the same after we finalize (see below).
rsource.remove();
Transliterator::Position index = { 0, 0, 0 };
Transliterator::Position index(0, 0);
UnicodeString log;
for (int32_t i=0; i<source.length(); ++i) {