blob: f7ad98bfd9812d97e9c7d17a56e60f59afffdb07 [file] [log] [blame]
Adam Lesinski93190b72017-11-03 15:20:17 -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#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
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070034 Printer& Print(android::StringPiece str);
35 Printer& Println(android::StringPiece str);
Adam Lesinskia693c4a2017-11-09 11:29:39 -080036 Printer& Println();
Adam Lesinski93190b72017-11-03 15:20:17 -070037
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