blob: 44f0fc546c7c1faea3a7ae78b226147dd5611d32 [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"
Jeremy Meyerb4f83ff2023-11-30 19:29:50 +000021#include "androidfw/Streams.h"
Adam Lesinski93190b72017-11-03 15:20:17 -070022#include "androidfw/StringPiece.h"
23
Adam Lesinski93190b72017-11-03 15:20:17 -070024namespace aapt {
25namespace text {
26
27// An indenting Printer that helps write formatted text to the OutputStream.
28class Printer {
29 public:
Jeremy Meyerb4f83ff2023-11-30 19:29:50 +000030 explicit Printer(android::OutputStream* out) : out_(out) {
Adam Lesinski93190b72017-11-03 15:20:17 -070031 }
32
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070033 Printer& Print(android::StringPiece str);
34 Printer& Println(android::StringPiece str);
Adam Lesinskia693c4a2017-11-09 11:29:39 -080035 Printer& Println();
Adam Lesinski93190b72017-11-03 15:20:17 -070036
37 void Indent();
38 void Undent();
39
40 private:
41 DISALLOW_COPY_AND_ASSIGN(Printer);
42
Jeremy Meyerb4f83ff2023-11-30 19:29:50 +000043 android::OutputStream* out_;
Adam Lesinski93190b72017-11-03 15:20:17 -070044 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