]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/bytestream.cpp
1 // Copyright (C) 2009-2011, 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 ByteSink::~ByteSink() {}
15 char* ByteSink::GetAppendBuffer(int32_t min_capacity
,
16 int32_t /*desired_capacity_hint*/,
17 char* scratch
, int32_t scratch_capacity
,
18 int32_t* result_capacity
) {
19 if (min_capacity
< 1 || scratch_capacity
< min_capacity
) {
23 *result_capacity
= scratch_capacity
;
27 void ByteSink::Flush() {}
29 CheckedArrayByteSink::CheckedArrayByteSink(char* outbuf
, int32_t capacity
)
30 : outbuf_(outbuf
), capacity_(capacity
< 0 ? 0 : capacity
),
31 size_(0), appended_(0), overflowed_(FALSE
) {
34 CheckedArrayByteSink::~CheckedArrayByteSink() {}
36 CheckedArrayByteSink
& CheckedArrayByteSink::Reset() {
37 size_
= appended_
= 0;
42 void CheckedArrayByteSink::Append(const char* bytes
, int32_t n
) {
47 int32_t available
= capacity_
- size_
;
52 if (n
> 0 && bytes
!= (outbuf_
+ size_
)) {
53 uprv_memcpy(outbuf_
+ size_
, bytes
, n
);
58 char* CheckedArrayByteSink::GetAppendBuffer(int32_t min_capacity
,
59 int32_t /*desired_capacity_hint*/,
61 int32_t scratch_capacity
,
62 int32_t* result_capacity
) {
63 if (min_capacity
< 1 || scratch_capacity
< min_capacity
) {
67 int32_t available
= capacity_
- size_
;
68 if (available
>= min_capacity
) {
69 *result_capacity
= available
;
70 return outbuf_
+ size_
;
72 *result_capacity
= scratch_capacity
;