27#include <fmt/format.h>
37 aOut->
Print(
"(%ls %s)", aKey.wc_str(), aValue ?
"yes" :
"no" );
49 aOut.
Print(
"(data" );
51 const wxString out = wxBase64Encode( aStream.GetBufferStart(), aStream.GetBufferSize() );
59 while( first < out.Length() )
89void Prettify( std::string& aSource,
bool aCompactSave )
92 const char quoteChar =
'"';
93 const char indentChar =
'\t';
94 const int indentSize = 1;
98 const int xySpecialCaseColumnLimit = 99;
103 const int consecutiveTokenWrapThreshold = 72;
105 std::string formatted;
106 formatted.reserve( aSource.length() );
108 auto cursor = aSource.begin();
112 char lastNonWhitespace = 0;
113 bool inQuote =
false;
114 bool hasInsertedSpace =
false;
115 bool inMultiLineList =
false;
117 bool inShortForm =
false;
118 int shortFormDepth = 0;
120 int backslashCount = 0;
122 auto isWhitespace = [](
const char aChar )
124 return ( aChar ==
' ' || aChar ==
'\t' || aChar ==
'\n' || aChar ==
'\r' );
127 auto nextNonWhitespace =
128 [&]( std::string::iterator aIt )
132 while( seek != aSource.end() && isWhitespace( *seek ) )
135 if( seek == aSource.end() )
142 [&]( std::string::iterator aIt )
146 if( ++seek == aSource.end() || *seek !=
'x' )
149 if( ++seek == aSource.end() || *seek !=
'y' )
152 if( ++seek == aSource.end() || *seek !=
' ' )
159 [&]( std::string::iterator aIt )
164 while( ++seek != aSource.end() && isalpha( *seek ) )
167 return token ==
"font" || token ==
"stroke" || token ==
"fill"
168 || token ==
"offset" || token ==
"rotate" || token ==
"scale";
171 while(
cursor != aSource.end() )
175 if( isWhitespace( *
cursor ) && !inQuote )
177 if( !hasInsertedSpace
179 && lastNonWhitespace !=
'('
183 if( inXY || column < consecutiveTokenWrapThreshold )
187 formatted.push_back(
' ' );
190 else if( inShortForm )
192 formatted.push_back(
' ' );
196 formatted += fmt::format(
"\n{}",
197 std::string( listDepth * indentSize, indentChar ) );
198 column = listDepth * indentSize;
199 inMultiLineList =
true;
202 hasInsertedSpace =
true;
207 hasInsertedSpace =
false;
209 if( *
cursor ==
'(' && !inQuote )
211 bool currentIsXY = isXY(
cursor );
212 bool currentIsShortForm = aCompactSave && isShortForm(
cursor );
214 if( formatted.empty() )
216 formatted.push_back(
'(' );
219 else if( inXY && currentIsXY && column < xySpecialCaseColumnLimit )
225 else if( inShortForm )
232 formatted += fmt::format(
"\n{}(",
233 std::string( listDepth * indentSize, indentChar ) );
234 column = listDepth * indentSize + 1;
239 if( currentIsShortForm )
242 shortFormDepth = listDepth;
247 else if( *
cursor ==
')' && !inQuote )
254 formatted.push_back(
')' );
257 else if( lastNonWhitespace ==
')' || inMultiLineList )
259 formatted += fmt::format(
"\n{})",
260 std::string( listDepth * indentSize, indentChar ) );
261 column = listDepth * indentSize + 1;
262 inMultiLineList =
false;
266 formatted.push_back(
')' );
270 if( shortFormDepth == listDepth )
283 else if( *
cursor == quoteChar && ( backslashCount & 1 ) == 0 )
289 formatted.push_back( *
cursor );
293 lastNonWhitespace = *
cursor;
302 aSource = std::move( formatted );
wxString AsString() const
#define MIME_BASE64_LENGTH
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.