/* Copyright (C) 2018-2019 de4dot@gmail.com This file is part of Iced. Iced is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Iced is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Iced. If not, see . */ #if (!NO_GAS_FORMATTER || !NO_INTEL_FORMATTER || !NO_MASM_FORMATTER || !NO_NASM_FORMATTER) && !NO_FORMATTER using System; using System.Text; namespace Iced.Intel { /// /// Formatter output that stores the formatted text in a /// public sealed class StringBuilderFormatterOutput : FormatterOutput { readonly StringBuilder sb; /// /// Constructor /// public StringBuilderFormatterOutput() => sb = new StringBuilder(); /// /// Constructor /// /// String builder public StringBuilderFormatterOutput(StringBuilder sb) => this.sb = sb ?? throw new ArgumentNullException(nameof(sb)); /// /// Writes text and text kind /// /// Text, can be an empty string /// Text kind. This value can be identical to the previous value passed to this method. It's /// the responsibility of the implementer to merge any such strings if needed. public override void Write(string text, FormatterOutputTextKind kind) => sb.Append(text); /// /// Clears the instance so this class can be reused to format the next instruction /// public void Reset() => sb.Clear(); /// /// Returns the current formatted text and clears the instance so this class can be reused to format the next instruction /// /// public string ToStringAndReset() { var result = ToString(); Reset(); return result; } /// /// Gets the current output /// /// public override string ToString() => sb.ToString(); } } #endif