diff --git a/icu4c/source/i18n/Makefile.in b/icu4c/source/i18n/Makefile.in index 16544f838b7..63c4256fc64 100644 --- a/icu4c/source/i18n/Makefile.in +++ b/icu4c/source/i18n/Makefile.in @@ -70,7 +70,7 @@ ucol.o ucol_bld.o ucol_elm.o ucol_cnt.o ucol_tok.o ucol_wgt.o ucoleitr.o \ udat.o umsg.o \ unifltlg.o unirange.o uniset.o unitohex.o unum.o \ dbbi.o dbbi_tbl.o rbbi.o rbbi_tbl.o brkdict.o nultrans.o jamohang.o hangjamo.o \ - utrans.o +remtrans.o utrans.o STATIC_OBJECTS = $(OBJECTS:.o=.$(STATIC_O)) diff --git a/icu4c/source/i18n/i18n.dsp b/icu4c/source/i18n/i18n.dsp index 0ef3801d985..77ec936ee80 100644 --- a/icu4c/source/i18n/i18n.dsp +++ b/icu4c/source/i18n/i18n.dsp @@ -466,6 +466,10 @@ SOURCE=.\rbt_set.cpp # End Source File # Begin Source File +SOURCE=.\remtrans.cpp +# End Source File +# Begin Source File + SOURCE=.\simpletz.cpp !IF "$(CFG)" == "i18n - Win32 Release" @@ -1413,6 +1417,10 @@ SOURCE=.\rbt_set.h # End Source File # Begin Source File +SOURCE=.\unicode\remtrans.h +# End Source File +# Begin Source File + SOURCE=.\unicode\simpletz.h !IF "$(CFG)" == "i18n - Win32 Release" diff --git a/icu4c/source/i18n/remtrans.cpp b/icu4c/source/i18n/remtrans.cpp new file mode 100644 index 00000000000..63a29ae5c32 --- /dev/null +++ b/icu4c/source/i18n/remtrans.cpp @@ -0,0 +1,54 @@ +/* +********************************************************************** +* Copyright (c) 2001, International Business Machines +* Corporation and others. All Rights Reserved. +********************************************************************** +* Date Name Description +* 04/02/2001 aliu Creation. +********************************************************************** +*/ +#include "unicode/remtrans.h" + +const UnicodeString RemoveTransliterator::ID = UnicodeString("Remove", ""); + +Transliterator* RemoveTransliterator::clone(void) const { + return new RemoveTransliterator(); +} + +void RemoveTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets, + UBool /*isIncremental*/) const { + // Find runs of unfiltered characters and replace them with the + // empty string. This loop has been optimized to what is probably + // an unnecessary degree. + UnicodeString empty; + int32_t start = offsets.start; + for (;;) { + // Find first unfiltered character, if any + while (start < offsets.limit && + filteredCharAt(text, start) == 0xFFFE) { + ++start; + } + if (start >= offsets.limit) { + break; + } + + // assert(start < offsets.limit && + // filteredCharAt(text, start) != 0xFFFE); + + // Find last unfiltered character + int32_t limit = start+1; // sic: +1 + while (limit < offsets.limit && + filteredCharAt(text, limit) != 0xFFFE) { + ++limit; + } + + // assert(start < limit); + + // Remove characters + text.handleReplaceBetween(start, limit, empty); + limit -= start; // limit <= deleted length + offsets.contextLimit -= limit; + offsets.limit -= limit; + } + offsets.start = start; +} diff --git a/icu4c/source/i18n/unicode/remtrans.h b/icu4c/source/i18n/unicode/remtrans.h new file mode 100644 index 00000000000..d53752b7f13 --- /dev/null +++ b/icu4c/source/i18n/unicode/remtrans.h @@ -0,0 +1,54 @@ +/* +********************************************************************** +* Copyright (c) 2001, International Business Machines +* Corporation and others. All Rights Reserved. +********************************************************************** +* Date Name Description +* 04/02/2001 aliu Creation. +********************************************************************** +*/ +#ifndef REMTRANS_H +#define REMTRANS_H + +#include "unicode/translit.h" + +/** + * A transliterator that removes text. + * @author Alan Liu + */ +class U_I18N_API RemoveTransliterator : public Transliterator { + +public: + + /** + * ID for this transliterator. + */ + static const UnicodeString ID; // public for Transliterator + + /** + * Constructs a transliterator. + */ + RemoveTransliterator(); + + /** + * Destructor. + */ + virtual ~RemoveTransliterator(); + + /** + * Transliterator API. + */ + Transliterator* clone(void) const; + + /** + * Implements {@link Transliterator#handleTransliterate}. + */ + virtual void handleTransliterate(Replaceable& text, UTransPosition& offset, + UBool isIncremental) const; +}; + +inline RemoveTransliterator::RemoveTransliterator() : Transliterator(ID, 0) {} + +inline RemoveTransliterator::~RemoveTransliterator() {} + +#endif