1 2 /* Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved 3 * http://www.digitalmars.com 4 * Distributed under the Boost Software License, Version 1.0. 5 * http://www.boost.org/LICENSE_1_0.txt 6 * https://github.com/dlang/dmd/blob/master/src/dmd/root/outbuffer.h 7 */ 8 9 #pragma once 10 11 #include "dsystem.h" 12 #include "port.h" 13 #include "rmem.h" 14 15 class RootObject; 16 17 struct OutBuffer 18 { 19 unsigned char *data; 20 size_t offset; 21 size_t size; 22 23 int level; 24 bool doindent; 25 private: 26 bool notlinehead; 27 public: 28 OutBufferOutBuffer29 OutBuffer() 30 { 31 data = NULL; 32 offset = 0; 33 size = 0; 34 35 doindent = 0; 36 level = 0; 37 notlinehead = 0; 38 } ~OutBufferOutBuffer39 ~OutBuffer() 40 { 41 mem.xfree(data); 42 } 43 char *extractData(); 44 45 void reserve(size_t nbytes); 46 void setsize(size_t size); 47 void reset(); 48 void write(const void *data, d_size_t nbytes); 49 void writebstring(utf8_t *string); 50 void writestring(const char *string); 51 void prependstring(const char *string); 52 void writenl(); // write newline 53 void writeByte(unsigned b); 54 void writeUTF8(unsigned b); 55 void prependbyte(unsigned b); 56 void writewchar(unsigned w); 57 void writeword(unsigned w); 58 void writeUTF16(unsigned w); 59 void write4(unsigned w); 60 void write(OutBuffer *buf); 61 void write(RootObject *obj); 62 void fill0(size_t nbytes); 63 void vprintf(const char *format, va_list args); 64 void printf(const char *format, ...); 65 void print(unsigned long long u); 66 void bracket(char left, char right); 67 size_t bracket(size_t i, const char *left, size_t j, const char *right); 68 void spread(size_t offset, size_t nbytes); 69 size_t insert(size_t offset, const void *data, size_t nbytes); 70 void remove(size_t offset, size_t nbytes); 71 // Append terminating null if necessary and get view of internal buffer 72 char *peekString(); 73 // Append terminating null if necessary and take ownership of data 74 char *extractString(); 75 }; 76