Adam Lesinski | efeb7af | 2017-08-02 14:57:43 -0700 | [diff] [blame^] | 1 | /* |
| 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 | |
| 19 | using ::android::StringPiece; |
| 20 | |
| 21 | namespace aapt { |
| 22 | namespace io { |
| 23 | |
| 24 | StringInputStream::StringInputStream(const StringPiece& str) : str_(str), offset_(0u) { |
| 25 | } |
| 26 | |
| 27 | bool 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 | |
| 38 | void StringInputStream::BackUp(size_t count) { |
| 39 | if (count > offset_) { |
| 40 | count = offset_; |
| 41 | } |
| 42 | offset_ -= count; |
| 43 | } |
| 44 | |
| 45 | size_t StringInputStream::ByteCount() const { |
| 46 | return offset_; |
| 47 | } |
| 48 | |
| 49 | } // namespace io |
| 50 | } // namespace aapt |