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
18 U_NAMESPACE_BEGIN
19
20 UBool
appendCodePoint(UChar32 c)21 Appendable::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
29 UBool
appendString(const UChar * s,int32_t length)30 Appendable::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
49 UBool
reserveAppendCapacity(int32_t)50 Appendable::reserveAppendCapacity(int32_t /*appendCapacity*/) {
51 return TRUE;
52 }
53
54 UChar *
getAppendBuffer(int32_t minCapacity,int32_t,UChar * scratch,int32_t scratchCapacity,int32_t * resultCapacity)55 Appendable::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
67 UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(Appendable)
68
69 // UnicodeStringAppendable is implemented in unistr.cpp.
70
71 U_NAMESPACE_END
72