File indexing completed on 2024-04-28 16:08:34

0001 /***************************************************************************
0002  *   Copyright (C) 2017 by Linuxstopmotion contributors;                   *
0003  *   see the AUTHORS file for details.                                     *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef STRINGWRITER_H_
0022 #define STRINGWRITER_H_
0023 
0024 #include <string>
0025 #include <stdint.h>
0026 
0027 class StringWriter {
0028     bool startOfLine;
0029     std::string buffer;
0030 public:
0031     StringWriter();
0032     /**
0033      * Returns the written string.
0034      * @return The null-terminated string written to.
0035      */
0036     const char* result() const;
0037     /**
0038      * Begins a new line, reusing the same buffer.
0039      */
0040     void reset();
0041     /**
0042      * Returns the number of characters that would have been written to the
0043      * buffer if it has been long enough. If it was long enough, this will be
0044      * the length of the string written into the buffer passed in SetBuffer.
0045      */
0046     int32_t length() const;
0047     /**
0048      * Writes a single character to the buffer.
0049      */
0050     void writeChar(char c);
0051     /**
0052      * Writes a space to the buffer, if we are not at the start of a line.
0053      */
0054     void beginArgument();
0055     /**
0056      * Writes a decimal (or octal!) digit.
0057      */
0058     void writeDigit(int32_t d);
0059     /**
0060      * Writes a string surrounded by double quotes.
0061      * @param s The null-terminated string to write.
0062      */
0063     void writeString(const char* s);
0064     /**
0065      * Writes a decimal integer to the buffer. Writes negative numbers preceded
0066      * with '-' and positive numbers without prefix.
0067      */
0068     void writeInteger(int32_t n);
0069     /**
0070      * Writes an identifier, which must not contain whitespace or backslashes.
0071      * @param id The null-terminated string to write.
0072      */
0073     void writeIdentifier(const char* id);
0074 };
0075 
0076 #endif