1/*
2*******************************************************************************
3*   Copyright (C) 2011, International Business Machines
4*   Corporation and others.  All Rights Reserved.
5*******************************************************************************
6*   file name:  appendable.cpp
7*   encoding:   US-ASCII
8*   tab size:   8 (not used)
9*   indentation:4
10*
11*   created on: 2010dec07
12*   created by: Markus W. Scherer
13*/
14
15#include "unicode/utypes.h"
16#include "unicode/appendable.h"
17
18U_NAMESPACE_BEGIN
19
20UBool
21Appendable::appendCodePoint(UChar32 c) {
22    if(c<=0xffff) {
23        return appendCodeUnit((UChar)c);
24    } else {
25        return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c));
26    }
27}
28
29UBool
30Appendable::appendString(const UChar *s, int32_t length) {
31    if(length<0) {
32        UChar c;
33        while((c=*s++)!=0) {
34            if(!appendCodeUnit(c)) {
35                return FALSE;
36            }
37        }
38    } else if(length>0) {
39        const UChar *limit=s+length;
40        do {
41            if(!appendCodeUnit(*s++)) {
42                return FALSE;
43            }
44        } while(s<limit);
45    }
46    return TRUE;
47}
48
49UBool
50Appendable::reserveAppendCapacity(int32_t /*appendCapacity*/) {
51    return TRUE;
52}
53
54UChar *
55Appendable::getAppendBuffer(int32_t minCapacity,
56                            int32_t /*desiredCapacityHint*/,
57                            UChar *scratch, int32_t scratchCapacity,
58                            int32_t *resultCapacity) {
59    if(minCapacity<1 || scratchCapacity<minCapacity) {
60        *resultCapacity=0;
61        return NULL;
62    }
63    *resultCapacity=scratchCapacity;
64    return scratch;
65}
66
67UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(Appendable)
68
69// UnicodeStringAppendable is implemented in unistr.cpp.
70
71U_NAMESPACE_END
72