blob: 4dd4816b65adc8ca5bf30d8b53e9886932191f27 [file] [log] [blame]
/*
*******************************************************************************
* Copyright (C) 1996-2000, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/UppercaseTransliterator.java,v $
* $Date: 2002/10/31 22:36:49 $
* $Revision: 1.12 $
*
*****************************************************************************************
*/
package com.ibm.icu.text;
import java.util.*;
import com.ibm.icu.impl.UCharacterProperty;
/**
* A transliterator that performs locale-sensitive toUpper()
* case mapping.
*/
class UppercaseTransliterator extends Transliterator {
/**
* Package accessible ID.
*/
static final String _ID = "Any-Upper";
// TODO: Add variants for tr, az, lt, default = default locale
/**
* System registration hook.
*/
static void register() {
Transliterator.registerFactory(_ID, new Transliterator.Factory() {
public Transliterator getInstance(String ID) {
return new UppercaseTransliterator(Locale.US);
}
});
}
private Locale loc;
/**
* Constructs a transliterator.
*/
public UppercaseTransliterator(Locale loc) {
super(_ID, null);
this.loc = loc;
}
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
protected void handleTransliterate(Replaceable text,
Position offsets, boolean isIncremental) {
int textPos = offsets.start;
if (textPos >= offsets.limit) return;
// get string for context
// TODO: add convenience method to do this, since we do it all over
UCharacterIterator original = UCharacterIterator.getInstance(text);
// Walk through original string
// If there is a case change, modify corresponding position in replaceable
int limit = offsets.limit;
int cp;
int oldLen;
while (textPos < limit) {
original.setIndex(textPos);
cp = original.currentCodePoint();
oldLen = UTF16.getCharCount(cp);
int newLen = m_charppty_.toUpperOrTitleCase(loc, cp, original, true, buffer);
if (newLen >= 0) {
text.replace(textPos, textPos + oldLen, buffer, 0, newLen);
if (newLen != oldLen) {
textPos += newLen;
offsets.limit += newLen - oldLen;
offsets.contextLimit += newLen - oldLen;
continue;
}
}
textPos += oldLen;
}
offsets.start = offsets.limit;
}
private char buffer[] = new char[UCharacterProperty.MAX_CASE_MAP_SIZE];
/**
* Character property database
*/
private static final UCharacterProperty m_charppty_ =
UCharacterProperty.getInstance();
}