]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/bytestream.cpp
1 // Copyright (C) 2009-2010, International Business Machines
2 // Corporation and others. All Rights Reserved.
4 // Copyright 2007 Google Inc. All Rights Reserved.
5 // Author: sanjay@google.com (Sanjay Ghemawat)
7 #include "unicode/utypes.h"
8 #include "unicode/bytestream.h"
13 char* ByteSink::GetAppendBuffer(int32_t min_capacity
,
14 int32_t /*desired_capacity_hint*/,
15 char* scratch
, int32_t scratch_capacity
,
16 int32_t* result_capacity
) {
17 if (min_capacity
< 1 || scratch_capacity
< min_capacity
) {
21 *result_capacity
= scratch_capacity
;
25 void ByteSink::Flush() {}
27 CheckedArrayByteSink::CheckedArrayByteSink(char* outbuf
, int32_t capacity
)
28 : outbuf_(outbuf
), capacity_(capacity
< 0 ? 0 : capacity
),
29 size_(0), appended_(0), overflowed_(FALSE
) {
32 CheckedArrayByteSink
& CheckedArrayByteSink::Reset() {
33 size_
= appended_
= 0;
38 void CheckedArrayByteSink::Append(const char* bytes
, int32_t n
) {
43 int32_t available
= capacity_
- size_
;
48 if (n
> 0 && bytes
!= (outbuf_
+ size_
)) {
49 uprv_memcpy(outbuf_
+ size_
, bytes
, n
);
54 char* CheckedArrayByteSink::GetAppendBuffer(int32_t min_capacity
,
55 int32_t /*desired_capacity_hint*/,
57 int32_t scratch_capacity
,
58 int32_t* result_capacity
) {
59 if (min_capacity
< 1 || scratch_capacity
< min_capacity
) {
63 int32_t available
= capacity_
- size_
;
64 if (available
>= min_capacity
) {
65 *result_capacity
= available
;
66 return outbuf_
+ size_
;
68 *result_capacity
= scratch_capacity
;