/src/icu/source/common/appendable.cpp
Line  | Count  | Source (jump to first uncovered line)  | 
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  | 0  | Appendable::~Appendable() {} | 
24  |  |  | 
25  |  | UBool  | 
26  | 0  | Appendable::appendCodePoint(UChar32 c) { | 
27  | 0  |     if(c<=0xffff) { | 
28  | 0  |         return appendCodeUnit((UChar)c);  | 
29  | 0  |     } else { | 
30  | 0  |         return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c));  | 
31  | 0  |     }  | 
32  | 0  | }  | 
33  |  |  | 
34  |  | UBool  | 
35  | 0  | Appendable::appendString(const UChar *s, int32_t length) { | 
36  | 0  |     if(length<0) { | 
37  | 0  |         UChar c;  | 
38  | 0  |         while((c=*s++)!=0) { | 
39  | 0  |             if(!appendCodeUnit(c)) { | 
40  | 0  |                 return FALSE;  | 
41  | 0  |             }  | 
42  | 0  |         }  | 
43  | 0  |     } else if(length>0) { | 
44  | 0  |         const UChar *limit=s+length;  | 
45  | 0  |         do { | 
46  | 0  |             if(!appendCodeUnit(*s++)) { | 
47  | 0  |                 return FALSE;  | 
48  | 0  |             }  | 
49  | 0  |         } while(s<limit);  | 
50  | 0  |     }  | 
51  | 0  |     return TRUE;  | 
52  | 0  | }  | 
53  |  |  | 
54  |  | UBool  | 
55  | 0  | Appendable::reserveAppendCapacity(int32_t /*appendCapacity*/) { | 
56  | 0  |     return TRUE;  | 
57  | 0  | }  | 
58  |  |  | 
59  |  | UChar *  | 
60  |  | Appendable::getAppendBuffer(int32_t minCapacity,  | 
61  |  |                             int32_t /*desiredCapacityHint*/,  | 
62  |  |                             UChar *scratch, int32_t scratchCapacity,  | 
63  | 0  |                             int32_t *resultCapacity) { | 
64  | 0  |     if(minCapacity<1 || scratchCapacity<minCapacity) { | 
65  | 0  |         *resultCapacity=0;  | 
66  | 0  |         return NULL;  | 
67  | 0  |     }  | 
68  | 0  |     *resultCapacity=scratchCapacity;  | 
69  | 0  |     return scratch;  | 
70  | 0  | }  | 
71  |  |  | 
72  |  | // UnicodeStringAppendable is implemented in unistr.cpp.  | 
73  |  |  | 
74  |  | U_NAMESPACE_END  |