Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/icu4c/common/appendable.cpp
9903 views
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(static_cast<char16_t>(c));
29
} else {
30
return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c));
31
}
32
}
33
34
UBool
35
Appendable::appendString(const char16_t *s, int32_t length) {
36
if(length<0) {
37
char16_t c;
38
while((c=*s++)!=0) {
39
if(!appendCodeUnit(c)) {
40
return false;
41
}
42
}
43
} else if(length>0) {
44
const char16_t *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
char16_t *
60
Appendable::getAppendBuffer(int32_t minCapacity,
61
int32_t /*desiredCapacityHint*/,
62
char16_t *scratch, int32_t scratchCapacity,
63
int32_t *resultCapacity) {
64
if(minCapacity<1 || scratchCapacity<minCapacity) {
65
*resultCapacity=0;
66
return nullptr;
67
}
68
*resultCapacity=scratchCapacity;
69
return scratch;
70
}
71
72
// UnicodeStringAppendable is implemented in unistr.cpp.
73
74
U_NAMESPACE_END
75
76