2001-06-11 19:51:46 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Copyright (C) 2001, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 05/24/01 aliu Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
2001-11-16 23:51:15 +00:00
|
|
|
#include "toupptrn.h"
|
2001-11-30 00:57:29 +00:00
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "ustr_imp.h"
|
|
|
|
#include "cpputils.h"
|
2001-11-30 00:06:13 +00:00
|
|
|
#include "unicode/uchar.h"
|
2001-06-11 19:51:46 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2001-10-11 23:54:55 +00:00
|
|
|
const char UppercaseTransliterator::_ID[] = "Any-Upper";
|
2001-06-11 19:51:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a transliterator.
|
|
|
|
*/
|
2001-11-30 00:57:29 +00:00
|
|
|
UppercaseTransliterator::UppercaseTransliterator(const Locale& theLoc) :
|
|
|
|
Transliterator(_ID, 0),
|
|
|
|
loc(theLoc),
|
|
|
|
buffer(0) {
|
|
|
|
buffer = new UChar[u_getMaxCaseExpansion()];
|
2001-06-11 19:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2001-11-30 00:57:29 +00:00
|
|
|
UppercaseTransliterator::~UppercaseTransliterator() {
|
|
|
|
delete [] buffer;
|
|
|
|
}
|
2001-06-11 19:51:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
|
|
|
UppercaseTransliterator::UppercaseTransliterator(const UppercaseTransliterator& o) :
|
2001-11-30 00:57:29 +00:00
|
|
|
Transliterator(o),
|
|
|
|
loc(o.loc),
|
|
|
|
buffer(0){
|
|
|
|
buffer = new UChar[u_getMaxCaseExpansion()];
|
|
|
|
uprv_arrayCopy(o.buffer, 0, this->buffer, 0, u_getMaxCaseExpansion());
|
|
|
|
}
|
2001-06-11 19:51:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator.
|
|
|
|
*/
|
|
|
|
UppercaseTransliterator& UppercaseTransliterator::operator=(
|
|
|
|
const UppercaseTransliterator& o) {
|
2001-11-30 00:57:29 +00:00
|
|
|
Transliterator::operator=(o);
|
2001-06-11 19:51:46 +00:00
|
|
|
loc = o.loc;
|
2001-11-30 00:57:29 +00:00
|
|
|
uprv_arrayCopy(o.buffer, 0, this->buffer, 0, u_getMaxCaseExpansion());
|
2001-06-11 19:51:46 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transliterator API.
|
|
|
|
*/
|
|
|
|
Transliterator* UppercaseTransliterator::clone(void) const {
|
|
|
|
return new UppercaseTransliterator(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-11-30 00:57:29 +00:00
|
|
|
* Implements {@link Transliterator#handleTransliterate}.
|
2001-06-11 19:51:46 +00:00
|
|
|
*/
|
2001-11-30 00:57:29 +00:00
|
|
|
void UppercaseTransliterator::handleTransliterate(Replaceable& text,
|
|
|
|
UTransPosition& offsets,
|
|
|
|
UBool isIncremental) const {
|
|
|
|
int32_t textPos = offsets.start;
|
|
|
|
if (textPos >= offsets.limit) return;
|
2001-06-11 19:51:46 +00:00
|
|
|
|
2001-11-30 00:57:29 +00:00
|
|
|
// get string for context
|
|
|
|
|
|
|
|
UnicodeString original;
|
2002-02-26 17:50:59 +00:00
|
|
|
text.extractBetween(offsets.contextStart, offsets.contextLimit, original);
|
2002-03-19 22:09:07 +00:00
|
|
|
|
|
|
|
UCharIterator iter;
|
|
|
|
uiter_setReplaceable(&iter, &text);
|
|
|
|
iter.start = offsets.contextStart;
|
|
|
|
iter.limit = offsets.contextLimit;
|
2001-11-30 00:57:29 +00:00
|
|
|
|
|
|
|
// Walk through original string
|
|
|
|
// If there is a case change, modify corresponding position in replaceable
|
|
|
|
|
|
|
|
int32_t i = textPos - offsets.contextStart;
|
|
|
|
int32_t limit = offsets.limit - offsets.contextStart;
|
2002-03-19 22:09:07 +00:00
|
|
|
UChar32 cp;
|
2001-11-30 00:57:29 +00:00
|
|
|
int32_t oldLen;
|
|
|
|
|
|
|
|
for (; i < limit; ) {
|
|
|
|
UTF_GET_CHAR(original.getBuffer(), 0, i, original.length(), cp);
|
|
|
|
oldLen = UTF_CHAR_LENGTH(cp);
|
|
|
|
i += oldLen;
|
2002-03-19 22:09:07 +00:00
|
|
|
iter.index = i; // Point _past_ current char
|
|
|
|
int32_t newLen = u_internalToUpper(cp, &iter, buffer, u_getMaxCaseExpansion(), loc.getName());
|
|
|
|
if (newLen >= 0) {
|
|
|
|
UnicodeString temp(buffer, newLen);
|
2001-11-30 00:57:29 +00:00
|
|
|
text.handleReplaceBetween(textPos, textPos + oldLen, temp);
|
2002-03-19 22:09:07 +00:00
|
|
|
if (newLen != oldLen) {
|
|
|
|
textPos += newLen;
|
|
|
|
offsets.limit += newLen - oldLen;
|
|
|
|
offsets.contextLimit += newLen - oldLen;
|
2001-11-30 00:57:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
textPos += oldLen;
|
|
|
|
}
|
|
|
|
offsets.start = offsets.limit;
|
2001-06-11 19:51:46 +00:00
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|