| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef __UNISTRAPPENDER_H__ |
| 14 |
#define __UNISTRAPPENDER_H__ |
| 15 |
|
| 16 |
#include "unicode/unistr.h" |
| 17 |
#include "unicode/uobject.h" |
| 18 |
#include "unicode/utf16.h" |
| 19 |
#include "unicode/utypes.h" |
| 20 |
#include "cmemory.h" |
| 21 |
|
| 22 |
U_NAMESPACE_BEGIN |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
class UnicodeStringAppender : public UMemory { |
| 40 |
public: |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
UnicodeStringAppender(UnicodeString &dest) : fDest(&dest), fIdx(0) { } |
| 47 |
|
| 48 |
inline void append(char16_t x) { |
| 49 |
if (fIdx == UPRV_LENGTHOF(fBuffer)) { |
| 50 |
fDest->append(fBuffer, 0, fIdx); |
| 51 |
fIdx = 0; |
| 52 |
} |
| 53 |
fBuffer[fIdx++] = x; |
| 54 |
} |
| 55 |
|
| 56 |
inline void append(UChar32 x) { |
| 57 |
if (fIdx >= UPRV_LENGTHOF(fBuffer) - 1) { |
| 58 |
fDest->append(fBuffer, 0, fIdx); |
| 59 |
fIdx = 0; |
| 60 |
} |
| 61 |
U16_APPEND_UNSAFE(fBuffer, fIdx, x); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
inline void flush() { |
| 68 |
if (fIdx) { |
| 69 |
fDest->append(fBuffer, 0, fIdx); |
| 70 |
} |
| 71 |
fIdx = 0; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
~UnicodeStringAppender() { |
| 78 |
flush(); |
| 79 |
} |
| 80 |
private: |
| 81 |
UnicodeString *fDest; |
| 82 |
int32_t fIdx; |
| 83 |
char16_t fBuffer[32]; |
| 84 |
UnicodeStringAppender(const UnicodeStringAppender &other); |
| 85 |
UnicodeStringAppender &operator=(const UnicodeStringAppender &other); |
| 86 |
}; |
| 87 |
|
| 88 |
U_NAMESPACE_END |
| 89 |
|
| 90 |
#endif |