]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/bytestream.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 // Copyright (C) 2009-2011, International Business Machines
4 // Corporation and others. All Rights Reserved.
6 // Copyright 2007 Google Inc. All Rights Reserved.
7 // Author: sanjay@google.com (Sanjay Ghemawat)
9 #include "unicode/utypes.h"
10 #include "unicode/bytestream.h"
15 ByteSink::~ByteSink() {}
17 char* ByteSink::GetAppendBuffer(int32_t min_capacity
,
18 int32_t /*desired_capacity_hint*/,
19 char* scratch
, int32_t scratch_capacity
,
20 int32_t* result_capacity
) {
21 if (min_capacity
< 1 || scratch_capacity
< min_capacity
) {
25 *result_capacity
= scratch_capacity
;
29 void ByteSink::Flush() {}
31 CheckedArrayByteSink::CheckedArrayByteSink(char* outbuf
, int32_t capacity
)
32 : outbuf_(outbuf
), capacity_(capacity
< 0 ? 0 : capacity
),
33 size_(0), appended_(0), overflowed_(FALSE
) {
36 CheckedArrayByteSink::~CheckedArrayByteSink() {}
38 CheckedArrayByteSink
& CheckedArrayByteSink::Reset() {
39 size_
= appended_
= 0;
44 void CheckedArrayByteSink::Append(const char* bytes
, int32_t n
) {
49 int32_t available
= capacity_
- size_
;
54 if (n
> 0 && bytes
!= (outbuf_
+ size_
)) {
55 uprv_memcpy(outbuf_
+ size_
, bytes
, n
);
60 char* CheckedArrayByteSink::GetAppendBuffer(int32_t min_capacity
,
61 int32_t /*desired_capacity_hint*/,
63 int32_t scratch_capacity
,
64 int32_t* result_capacity
) {
65 if (min_capacity
< 1 || scratch_capacity
< min_capacity
) {
69 int32_t available
= capacity_
- size_
;
70 if (available
>= min_capacity
) {
71 *result_capacity
= available
;
72 return outbuf_
+ size_
;
74 *result_capacity
= scratch_capacity
;