| 1 | // © 2016 and later: Unicode, Inc. and others. |
| 2 | // License & terms of use: http://www.unicode.org/copyright.html |
| 3 | /* |
| 4 | ********************************************************************** |
| 5 | * Copyright (c) 2001-2011, International Business Machines |
| 6 | * Corporation and others. All Rights Reserved. |
| 7 | ********************************************************************** |
| 8 | * Date Name Description |
| 9 | * 04/02/2001 aliu Creation. |
| 10 | ********************************************************************** |
| 11 | */ |
| 12 | |
| 13 | #include "unicode/utypes.h" |
| 14 | |
| 15 | #if !UCONFIG_NO_TRANSLITERATION |
| 16 | |
| 17 | #include "remtrans.h" |
| 18 | #include "unicode/unifilt.h" |
| 19 | |
| 20 | static const UChar CURR_ID[] = {65, 110, 121, 45, 0x52, 0x65, 0x6D, 0x6F, 0x76, 0x65, 0x00}; /* "Any-Remove" */ |
| 21 | |
| 22 | U_NAMESPACE_BEGIN |
| 23 | |
| 24 | UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RemoveTransliterator) |
| 25 | |
| 26 | /** |
| 27 | * Factory method |
| 28 | */ |
| 29 | static Transliterator* RemoveTransliterator_create(const UnicodeString& /*ID*/, |
| 30 | Transliterator::Token /*context*/) { |
| 31 | /* We don't need the ID or context. We just remove data */ |
| 32 | return new RemoveTransliterator(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * System registration hook. |
| 37 | */ |
| 38 | void RemoveTransliterator::registerIDs() { |
| 39 | |
| 40 | Transliterator::_registerFactory(UnicodeString(TRUE, ::CURR_ID, -1), |
| 41 | RemoveTransliterator_create, integerToken(0)); |
| 42 | |
| 43 | Transliterator::_registerSpecialInverse(UNICODE_STRING_SIMPLE("Remove" ), |
| 44 | UNICODE_STRING_SIMPLE("Null" ), FALSE); |
| 45 | } |
| 46 | |
| 47 | RemoveTransliterator::RemoveTransliterator() : Transliterator(UnicodeString(TRUE, ::CURR_ID, -1), 0) {} |
| 48 | |
| 49 | RemoveTransliterator::~RemoveTransliterator() {} |
| 50 | |
| 51 | RemoveTransliterator* RemoveTransliterator::clone() const { |
| 52 | RemoveTransliterator* result = new RemoveTransliterator(); |
| 53 | if (result != NULL && getFilter() != 0) { |
| 54 | result->adoptFilter(getFilter()->clone()); |
| 55 | } |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | void RemoveTransliterator::handleTransliterate(Replaceable& text, UTransPosition& index, |
| 60 | UBool /*isIncremental*/) const { |
| 61 | // Our caller (filteredTransliterate) has already narrowed us |
| 62 | // to an unfiltered run. Delete it. |
| 63 | UnicodeString empty; |
| 64 | text.handleReplaceBetween(index.start, index.limit, empty); |
| 65 | int32_t len = index.limit - index.start; |
| 66 | index.contextLimit -= len; |
| 67 | index.limit -= len; |
| 68 | } |
| 69 | U_NAMESPACE_END |
| 70 | |
| 71 | #endif /* #if !UCONFIG_NO_TRANSLITERATION */ |
| 72 | |