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#ifndef AAPT_TEXT_PRINTER_H 18#define AAPT_TEXT_PRINTER_H 19 20#include "android-base/macros.h" 21#include "androidfw/StringPiece.h" 22 23#include "io/Io.h" 24 25namespace aapt { 26namespace text { 27 28// An indenting Printer that helps write formatted text to the OutputStream. 29class Printer { 30 public: 31 explicit Printer(::aapt::io::OutputStream* out) : out_(out) { 32 } 33 34 Printer& Print(const ::android::StringPiece& str); 35 Printer& Println(const ::android::StringPiece& str); 36 Printer& Println(); 37 38 void Indent(); 39 void Undent(); 40 41 private: 42 DISALLOW_COPY_AND_ASSIGN(Printer); 43 44 ::aapt::io::OutputStream* out_; 45 int indent_level_ = 0; 46 bool needs_indent_ = false; 47 bool error_ = false; 48}; 49 50} // namespace text 51} // namespace aapt 52 53#endif // AAPT_TEXT_PRINTER_H 54