Path: blob/master/thirdparty/icu4c/common/appendable.cpp
9903 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3*******************************************************************************4* Copyright (C) 2011-2012, International Business Machines5* Corporation and others. All Rights Reserved.6*******************************************************************************7* file name: appendable.cpp8* encoding: UTF-89* tab size: 8 (not used)10* indentation:411*12* created on: 2010dec0713* created by: Markus W. Scherer14*/1516#include "unicode/utypes.h"17#include "unicode/appendable.h"18#include "unicode/utf16.h"1920U_NAMESPACE_BEGIN2122Appendable::~Appendable() {}2324UBool25Appendable::appendCodePoint(UChar32 c) {26if(c<=0xffff) {27return appendCodeUnit(static_cast<char16_t>(c));28} else {29return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c));30}31}3233UBool34Appendable::appendString(const char16_t *s, int32_t length) {35if(length<0) {36char16_t c;37while((c=*s++)!=0) {38if(!appendCodeUnit(c)) {39return false;40}41}42} else if(length>0) {43const char16_t *limit=s+length;44do {45if(!appendCodeUnit(*s++)) {46return false;47}48} while(s<limit);49}50return true;51}5253UBool54Appendable::reserveAppendCapacity(int32_t /*appendCapacity*/) {55return true;56}5758char16_t *59Appendable::getAppendBuffer(int32_t minCapacity,60int32_t /*desiredCapacityHint*/,61char16_t *scratch, int32_t scratchCapacity,62int32_t *resultCapacity) {63if(minCapacity<1 || scratchCapacity<minCapacity) {64*resultCapacity=0;65return nullptr;66}67*resultCapacity=scratchCapacity;68return scratch;69}7071// UnicodeStringAppendable is implemented in unistr.cpp.7273U_NAMESPACE_END747576