• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **********************************************************************
3 *   Copyright (C) 2008, International Business Machines
4 *   Corporation and others.  All Rights Reserved.
5 **********************************************************************
6 *   Date        Name        Description
7 *   05/11/2008  Andy Heninger  Ported from Java
8 **********************************************************************
9 */
10 #ifndef BRKTRANS_H
11 #define BRKTRANS_H
12 
13 #include "unicode/utypes.h"
14 
15 #if !UCONFIG_NO_TRANSLITERATION && !UCONFIG_NO_BREAK_ITERATION
16 
17 #include "unicode/translit.h"
18 
19 
20 U_NAMESPACE_BEGIN
21 
22 class UVector32;
23 
24 /**
25  * A transliterator that pInserts the specified characters at word breaks.
26  * To restrict it to particular characters, use a filter.
27  * TODO: this is an internal class, and only temporary.
28  * Remove it once we have \b notation in Transliterator.
29  */
30 class BreakTransliterator : public Transliterator {
31 public:
32 
33     BreakTransliterator(const UnicodeString &ID,
34                         UnicodeFilter *adoptedFilter,
35                         BreakIterator *bi,
36                         const UnicodeString &insertion);
37     /**
38      * Constructs a transliterator.
39      * @param adoptedFilter    the filter for this transliterator.
40      */
41     BreakTransliterator(UnicodeFilter* adoptedFilter = 0);
42 
43     /**
44      * Destructor.
45      */
46     virtual ~BreakTransliterator();
47 
48     /**
49      * Copy constructor.
50      */
51     BreakTransliterator(const BreakTransliterator&);
52 
53     /**
54      * Transliterator API.
55      * @return    A copy of the object.
56      */
57     virtual Transliterator* clone(void) const;
58 
59     virtual const UnicodeString &getInsertion() const;
60 
61     virtual void setInsertsion(const UnicodeString &insertion);
62 
63     /**
64       *  Return the break iterator used by this transliterator.
65       *  Caution, this is the live break iterator; it must not be used while
66       *     there is any possibility that this transliterator is using it.
67       */
68     virtual BreakIterator *getBreakIterator();
69 
70 
71     /**
72      * ICU "poor man's RTTI", returns a UClassID for the actual class.
73      */
74     virtual UClassID getDynamicClassID() const;
75 
76     /**
77      * ICU "poor man's RTTI", returns a UClassID for this class.
78      */
79     U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
80 
81  protected:
82 
83     /**
84      * Implements {@link Transliterator#handleTransliterate}.
85      * @param text          the buffer holding transliterated and
86      *                      untransliterated text
87      * @param offset        the start and limit of the text, the position
88      *                      of the cursor, and the start and limit of transliteration.
89      * @param incremental   if true, assume more text may be coming after
90      *                      pos.contextLimit. Otherwise, assume the text is complete.
91      */
92     virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
93                                      UBool isIncremental) const;
94 
95  private:
96      BreakIterator     *bi;
97      UnicodeString      fInsertion;
98      UVector32         *boundaries;
99      UnicodeString      sText;  // text from handleTransliterate().
100 
101      static UnicodeString replaceableAsString(Replaceable &r);
102 
103     /**
104      * Assignment operator.
105      */
106     BreakTransliterator& operator=(const BreakTransliterator&);
107 };
108 
109 U_NAMESPACE_END
110 
111 #endif /* #if !UCONFIG_NO_TRANSLITERATION */
112 
113 #endif
114