34#include <wx/translation.h>
38#if !defined( HAVE_FGETC_NOLOCK )
41#define getc_unlocked fgetc
43#define getc_unlocked getc
48static int vprint( std::string* result,
const char* format, va_list ap )
59 size_t len = vsnprintf( msg,
sizeof(msg), format, ap );
61 if( len <
sizeof(msg) )
63 result->append( msg, msg + len );
70 std::vector<char> buf;
73 len = vsnprintf( &buf[0], len+1, format, tmp );
75 result->append( &buf[0], &buf[0] + len );
84int StrPrintf( std::string* result,
const char* format, ... )
88 va_start( args, format );
89 int ret =
vprint( result, format, args );
101 va_start( args, format );
112 m_length( 0 ), m_lineNum( 0 ), m_line( nullptr ),
113 m_capacity( 0 ), m_maxLineLength( aMaxLineLength )
115 if( aMaxLineLength != 0 )
168 unsigned aMaxLineLength ):
171 m_fp = wxFopen( aFileName, wxT(
"rt" ) );
176 aFileName.GetData() );
187 unsigned aStartingLineNumber,
188 unsigned aMaxLineLength ) :
189 LINE_READER( aMaxLineLength ), m_iOwn( doOwn ), m_fp( aFile )
205 fseek(
m_fp, 0, SEEK_END );
206 long int fileLength = ftell(
m_fp );
215 return ftell(
m_fp );
255 m_lines( aString ), m_ndx( 0 )
265 m_lines( aStartingPoint.m_lines ),
266 m_ndx( aStartingPoint.m_ndx )
281 if( nlOffset == std::string::npos )
284 new_length = nlOffset -
m_ndx + 1;
309 const wxString& aSource ) :
364 if( strlen( wrapee ) == 0 )
369 for( ; *wrapee; ++wrapee, isFirst = false )
371 static const char quoteThese[] =
"\t ()"
378 if( strchr( quoteThese, *wrapee ) )
381 if( !isFirst &&
'-' == *wrapee )
425 va_start( args, fmt );
426 int ret =
vprint( fmt, args);
439 va_start( args, fmt );
444 for(
int i = 0; i < nestLevel; ++i )
453 result =
vprint( fmt, args );
466 ret.reserve( aWrapee.size() * 2 + 2 );
470 for( std::string::const_iterator it = aWrapee.begin(); it != aWrapee.end(); ++it )
508 return Quotes( (
const char*) aWrapee.utf8_str() );
525 for( std::string::iterator i =
copy.begin(); i !=
copy.end(); ++i )
527 if( !isspace( *i ) && *i !=
')' && *i !=
'(' && *i !=
'"' )
538 m_filename( aFileName )
540 m_fp = wxFopen( aFileName, aMode );
556 if( fwrite( aOutBuf, (
unsigned) aCount, 1,
m_fp ) != 1 )
567 for(
int total = 0; total<aCount; total += lastWrite )
569 lastWrite =
m_os.Write( aOutBuf, aCount ).LastWrite();
~FILE_LINE_READER()
May or may not close the open file, depending on doOwn in constructor.
FILE_LINE_READER(const wxString &aFileName, unsigned aStartingLineNumber=0, unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX)
Take aFileName and the size of the desired line buffer and opens the file and assumes the obligation ...
FILE * m_fp
I may own this file, but might not.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
bool m_iOwn
if I own the file, I'll promise to close it, else not.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
LINE_READER(unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX)
Build a line reader and fixes the length of the maximum supported line length to aMaxLineLength.
unsigned m_maxLineLength
maximum allowed capacity using resizing.
unsigned m_length
no. bytes in line before trailing nul.
unsigned m_capacity
no. bytes allocated for line.
void expandCapacity(unsigned aNewsize)
Will expand the capacity of line up to maxLineLength but not greater, so be careful about making assu...
char * m_line
the read line of UTF8 text
wxString m_source
origin of text lines, e.g. filename or "clipboard"
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
STRING_LINE_READER(const std::string &aString, const wxString &aSource)
Construct a string line reader.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
void ignore_unused(const T &)
#define THROW_IO_ERROR(msg)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
static int vprint(std::string *result, const char *format, va_list ap)
int StrPrintf(std::string *result, const char *format,...)
This is like sprintf() but the output is appended to a std::string instead of to a character array.
#define OUTPUTFMTBUFZ
default buffer size for any OUTPUT_FORMATTER
#define LINE_READER_LINE_INITIAL_SIZE
#define LINE_READER_LINE_DEFAULT_MAX