ICU-3517 implement countElements / getElement

X-SVN-Rev: 14588
This commit is contained in:
Alan Liu 2004-02-25 23:01:04 +00:00
parent c2ed656ba4
commit e9985abfd4
2 changed files with 59 additions and 3 deletions

View file

@ -19,7 +19,6 @@
#include "unicode/rep.h"
#include "unicode/resbund.h"
#include "unicode/unifilt.h"
#include "unicode/unifltlg.h"
#include "unicode/uniset.h"
#include "unicode/uscript.h"
#include "unicode/strenum.h"
@ -1090,6 +1089,28 @@ UnicodeString& Transliterator::toRules(UnicodeString& rulesSource,
return rulesSource;
}
int32_t Transliterator::countElements() const {
return (this->getDynamicClassID() ==
CompoundTransliterator::getStaticClassID()) ?
((const CompoundTransliterator*) this)->getCount() : 0;
}
const Transliterator& Transliterator::getElement(int32_t index, UErrorCode& ec) const {
if (U_FAILURE(ec)) {
return *this;
}
const CompoundTransliterator* cpd =
(this->getDynamicClassID() == CompoundTransliterator::getStaticClassID()) ?
(const CompoundTransliterator*) this : 0;
int32_t n = (cpd == NULL) ? 1 : cpd->getCount();
if (index < 0 || index >= n) {
ec = U_INDEX_OUTOFBOUNDS_ERROR;
return *this;
} else {
return (n == 1) ? *this : cpd->getTransliterator(index);
}
}
UnicodeSet& Transliterator::getSourceSet(UnicodeSet& result) const {
handleGetSourceSet(result);
if (filter != NULL) {

View file

@ -274,14 +274,14 @@ private:
/**
* Return a token containing an integer.
* @return a token containing an integer.
* @draft ICU 2.4
* @internal
*/
inline static Token integerToken(int32_t);
/**
* Return a token containing a pointer.
* @return a token containing a pointer.
* @draft ICU 2.4
* @internal
*/
inline static Token pointerToken(void*);
@ -871,6 +871,41 @@ public:
virtual UnicodeString& toRules(UnicodeString& result,
UBool escapeUnprintable) const;
/**
* Return the number of elements that make up this transliterator.
* For example, if the transliterator "NFD;Jamo-Latin;Latin-Greek"
* were created, the return value of this method would be 3.
*
* <p>If this transliterator is not composed of other
* transliterators, then this method returns 1.
* @return the number of transliterators that compose this
* transliterator, or 1 if this transliterator is not composed of
* multiple transliterators
* @draft ICU 3.0
*/
int32_t countElements() const;
/**
* Return an element that makes up this transliterator. For
* example, if the transliterator "NFD;Jamo-Latin;Latin-Greek"
* were created, the return value of this method would be one
* of the three transliterator objects that make up that
* transliterator: [NFD, Jamo-Latin, Latin-Greek].
*
* <p>If this transliterator is not composed of other
* transliterators, then this method will return a reference to
* this transliterator when given the index 0.
* @param index a value from 0..countElements()-1 indicating the
* transliterator to return
* @param ec input-output error code
* @return one of the transliterators that makes up this
* transliterator, if this transliterator is made up of multiple
* transliterators, otherwise a reference to this object if given
* an index of 0
* @draft ICU 3.0
*/
const Transliterator& getElement(int32_t index, UErrorCode& ec) const;
/**
* Returns the set of all characters that may be modified in the
* input text by this Transliterator. This incorporates this