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