quote_buffer 0.1.4 quote_buffer: ^0.1.4 copied to clipboard
Extension on StringBuffer providing methods for adding strings whose content is delimited by escaped quotation marks to the buffer.
Quote Buffer #
Introduction #
In order to add a string literal to generated source code, it is required to create strings whose content is delimited by escaped quotation marks.
In the following such strings are called quoted strings. QuoteBuffer
is an extension on Dart's StringBuffer
and providing methods that simplify
adding quoted strings to the buffer.
Usage #
To use this library include quote_buffer as dependency in your pubspec.yaml
file.
The section below lists the methods provided for writing quoted strings to the
buffer and shows the console output obtained by printing the buffer content.
It is assumed that buffer
is an instance of StringBuffer
.
-
writeQ(Object obj, {QuotationMark delimiter})
Writes delimiter, obj, delimiter to the buffer.
buffer.writeQ(29); print(buffer.toString()); // Console output below \/
'29'
-
writelnQ(Object obj, {QuotationMark delimiter})
Writes delimiter, obj, delimiter, newline symbol to the buffer.
final bufferS = QuoteBuffer(); buffer.writelnQ('name', delimiter: QuotationMark.DOUBLE); print(buffer.toString()); // Console output below \/ print('--- ---');
"name" --- ---
-
writeAllQ(Iterable objects, {String separator, QuotationMark delimiter})
Writes delimiter, sequence of objects, delimiter to the buffer.
buffer.writeAllQ( ['one','two','three','four'], separator: ',', ); print(buffer.toString()); // Console output below \/
"one, two, three, four"
-
writelnAllQ(Iterable objects, {String separator1, String separator2, QuoationMark delimiter})
Writes objects in sequence: delimiter, objects[0], separator1, delimiter, separator2, newline symbol, etc.
buffer.writelnAllQ( ['one','two','three','four'], separator1: ' #', separator2: ',', delimiter: QuotationMark.DOUBLE, ); print(buffer.toString()); // Console output below \/ print('--- ---');
"one #", "two #", "three #", "four" --- ---
Examples #
The example located in the folder example shows how to use the extension QuoteBuffer to simplify the generation of string literals whose content is enclosed by escaped quotation marks.
Features and bugs #
Please file feature requests and bugs at the issue tracker.