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