123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- #ifndef __APPENDABLE_H__
- #define __APPENDABLE_H__
- #include "unicode/utypes.h"
- #include "unicode/uobject.h"
- U_NAMESPACE_BEGIN
- class UnicodeString;
- /**
- * Base class for objects to which Unicode characters and strings can be appended.
- * Combines elements of Java Appendable and ICU4C ByteSink.
- *
- * This class can be used in APIs where it does not matter whether the actual destination is
- * a UnicodeString, a UChar[] array, a UnicodeSet, or any other object
- * that receives and processes characters and/or strings.
- *
- * Implementation classes must implement at least appendCodeUnit(UChar).
- * The base class provides default implementations for the other methods.
- *
- * The methods do not take UErrorCode parameters.
- * If an error occurs (e.g., out-of-memory),
- * in addition to returning FALSE from failing operations,
- * the implementation must prevent unexpected behavior (e.g., crashes)
- * from further calls and should make the error condition available separately
- * (e.g., store a UErrorCode, make/keep a UnicodeString bogus).
- * @stable ICU 4.8
- */
- class U_COMMON_API Appendable : public UObject {
- public:
-
- ~Appendable();
-
- virtual UBool appendCodeUnit(UChar c) = 0;
-
- virtual UBool appendCodePoint(UChar32 c);
-
- virtual UBool appendString(const UChar *s, int32_t length);
-
- virtual UBool reserveAppendCapacity(int32_t appendCapacity);
-
- virtual UChar *getAppendBuffer(int32_t minCapacity,
- int32_t desiredCapacityHint,
- UChar *scratch, int32_t scratchCapacity,
- int32_t *resultCapacity);
- };
- class U_COMMON_API UnicodeStringAppendable : public Appendable {
- public:
-
- explicit UnicodeStringAppendable(UnicodeString &s) : str(s) {}
-
- ~UnicodeStringAppendable();
-
- virtual UBool appendCodeUnit(UChar c);
-
- virtual UBool appendCodePoint(UChar32 c);
-
- virtual UBool appendString(const UChar *s, int32_t length);
-
- virtual UBool reserveAppendCapacity(int32_t appendCapacity);
-
- virtual UChar *getAppendBuffer(int32_t minCapacity,
- int32_t desiredCapacityHint,
- UChar *scratch, int32_t scratchCapacity,
- int32_t *resultCapacity);
- private:
- UnicodeString &str;
- };
- U_NAMESPACE_END
- #endif
|