blob: 51a18a7d8a9f8ff926e332b58150fa4ccf52099d [file] [log] [blame]
Adam Lesinskiefeb7af2017-08-02 14:57:43 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "io/StringInputStream.h"
18
19using ::android::StringPiece;
20
21namespace aapt {
22namespace io {
23
24StringInputStream::StringInputStream(const StringPiece& str) : str_(str), offset_(0u) {
25}
26
27bool StringInputStream::Next(const void** data, size_t* size) {
28 if (offset_ == str_.size()) {
29 return false;
30 }
31
32 *data = str_.data() + offset_;
33 *size = str_.size() - offset_;
34 offset_ = str_.size();
35 return true;
36}
37
38void StringInputStream::BackUp(size_t count) {
39 if (count > offset_) {
40 count = offset_;
41 }
42 offset_ -= count;
43}
44
45size_t StringInputStream::ByteCount() const {
46 return offset_;
47}
48
49} // namespace io
50} // namespace aapt