#ifdefined(move32) // System can define move32 intrinsics, but the char iters define move32 method // using same undef trick in headers, so undef here to re-enable the method. #undef move32 #endif
U_NAMESPACE_BEGIN
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Normalizer)
//------------------------------------------------------------------------- // Constructors and other boilerplate //-------------------------------------------------------------------------
if(&right!=&result) {
dest=&result;
} else { // the right and result strings are the same object, use a temporary one
dest=&localDest;
}
*dest=left; const Normalizer2 *n2=Normalizer2Factory::getInstance(mode, errorCode); if(U_SUCCESS(errorCode)) { if(options&UNORM_UNICODE_3_2) {
FilteredNormalizer2(*n2, *uniset_getUnicode32Instance(errorCode)).
append(*dest, right, errorCode);
} else {
n2->append(*dest, right, errorCode);
}
} if(dest==&localDest && U_SUCCESS(errorCode)) {
result=*dest;
}
} return result;
}
//------------------------------------------------------------------------- // Iteration API //-------------------------------------------------------------------------
/** * Return the current character in the normalized text.
*/
UChar32 Normalizer::current() { if(bufferPos<buffer.length() || nextNormalize()) { return buffer.char32At(bufferPos);
} else { return DONE;
}
}
/** * Return the next character in the normalized text and advance * the iteration position by one. If the end * of the text has already been reached, {@link #DONE} is returned.
*/
UChar32 Normalizer::next() { if(bufferPos<buffer.length() || nextNormalize()) {
UChar32 c=buffer.char32At(bufferPos);
bufferPos+=U16_LENGTH(c); return c;
} else { return DONE;
}
}
/** * Return the previous character in the normalized text and decrement * the iteration position by one. If the beginning * of the text has already been reached, {@link #DONE} is returned.
*/
UChar32 Normalizer::previous() { if(bufferPos>0 || previousNormalize()) {
UChar32 c=buffer.char32At(bufferPos-1);
bufferPos-=U16_LENGTH(c); return c;
} else { return DONE;
}
}
/** * Return the first character in the normalized text. This resets * the <tt>Normalizer's</tt> position to the beginning of the text.
*/
UChar32 Normalizer::first() {
reset(); return next();
}
/** * Return the last character in the normalized text. This resets * the <tt>Normalizer's</tt> position to be just before the * the input text corresponding to that normalized character.
*/
UChar32 Normalizer::last() {
currentIndex=nextIndex=text->setToEnd();
clearBuffer(); return previous();
}
/** * Retrieve the current iteration position in the input text that is * being normalized. This method is useful in applications such as * searching, where you need to be able to determine the position in * the input text that corresponds to a given normalized output character. * <p> * <b>Note:</b> This method sets the position in the <em>input</em>, while * {@link #next} and {@link #previous} iterate through characters in the * <em>output</em>. This means that there is not necessarily a one-to-one * correspondence between characters returned by <tt>next</tt> and * <tt>previous</tt> and the indices passed to and returned from * <tt>setIndex</tt> and {@link #getIndex}. *
*/
int32_t Normalizer::getIndex() const { if(bufferPos<buffer.length()) { return currentIndex;
} else { return nextIndex;
}
}
/** * Retrieve the index of the start of the input text. This is the begin index * of the <tt>CharacterIterator</tt> or the start (i.e. 0) of the <tt>String</tt> * over which this <tt>Normalizer</tt> is iterating
*/
int32_t Normalizer::startIndex() const { return text->startIndex();
}
/** * Retrieve the index of the end of the input text. This is the end index * of the <tt>CharacterIterator</tt> or the length of the <tt>String</tt> * over which this <tt>Normalizer</tt> is iterating
*/
int32_t Normalizer::endIndex() const { return text->endIndex();
}
/** * Set the input text over which this <tt>Normalizer</tt> will iterate. * The iteration position is set to the beginning of the input text.
*/ void
Normalizer::setText(const UnicodeString& newText,
UErrorCode &status)
{ if (U_FAILURE(status)) { return;
}
CharacterIterator *newIter = new StringCharacterIterator(newText); if (newIter == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; return;
} delete text;
text = newIter;
reset();
}
/** * Set the input text over which this <tt>Normalizer</tt> will iterate. * The iteration position is set to the beginning of the string.
*/ void
Normalizer::setText(const CharacterIterator& newText,
UErrorCode &status)
{ if (U_FAILURE(status)) { return;
}
CharacterIterator *newIter = newText.clone(); if (newIter == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; return;
} delete text;
text = newIter;
reset();
}
void
Normalizer::setText(ConstChar16Ptr newText,
int32_t length,
UErrorCode &status)
{ if (U_FAILURE(status)) { return;
}
CharacterIterator *newIter = new UCharCharacterIterator(newText, length); if (newIter == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; return;
} delete text;
text = newIter;
reset();
}
/** * Copies the text under iteration into the UnicodeString referred to by "result". * @param result Receives a copy of the text under iteration.
*/ void
Normalizer::getText(UnicodeString& result)
{
text->getText(result);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.