2011-02-03 05:28:01 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2012-11-08 23:31:20 +00:00
|
|
|
* Copyright (C) 2011-2012, International Business Machines
|
2011-02-03 05:28:01 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: appendable.cpp
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2010dec07
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/appendable.h"
|
2011-07-27 05:53:56 +00:00
|
|
|
#include "unicode/utf16.h"
|
2011-02-03 05:28:01 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2011-07-26 05:32:25 +00:00
|
|
|
Appendable::~Appendable() {}
|
|
|
|
|
2011-02-03 05:28:01 +00:00
|
|
|
UBool
|
2011-02-03 22:07:22 +00:00
|
|
|
Appendable::appendCodePoint(UChar32 c) {
|
2011-02-03 05:28:01 +00:00
|
|
|
if(c<=0xffff) {
|
|
|
|
return appendCodeUnit((UChar)c);
|
|
|
|
} else {
|
|
|
|
return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool
|
2011-02-03 22:07:22 +00:00
|
|
|
Appendable::appendString(const UChar *s, int32_t length) {
|
2011-02-03 05:28:01 +00:00
|
|
|
if(length<0) {
|
|
|
|
UChar c;
|
|
|
|
while((c=*s++)!=0) {
|
|
|
|
if(!appendCodeUnit(c)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(length>0) {
|
|
|
|
const UChar *limit=s+length;
|
|
|
|
do {
|
|
|
|
if(!appendCodeUnit(*s++)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} while(s<limit);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool
|
2011-02-03 22:07:22 +00:00
|
|
|
Appendable::reserveAppendCapacity(int32_t /*appendCapacity*/) {
|
2011-02-03 05:28:01 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar *
|
2011-02-03 22:07:22 +00:00
|
|
|
Appendable::getAppendBuffer(int32_t minCapacity,
|
|
|
|
int32_t /*desiredCapacityHint*/,
|
|
|
|
UChar *scratch, int32_t scratchCapacity,
|
|
|
|
int32_t *resultCapacity) {
|
2011-02-03 05:28:01 +00:00
|
|
|
if(minCapacity<1 || scratchCapacity<minCapacity) {
|
|
|
|
*resultCapacity=0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*resultCapacity=scratchCapacity;
|
|
|
|
return scratch;
|
|
|
|
}
|
|
|
|
|
2011-02-03 22:07:22 +00:00
|
|
|
// UnicodeStringAppendable is implemented in unistr.cpp.
|
2011-02-03 05:28:01 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|