Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simphotonics/quote_buffer
Extension methods for transforming single objects and iterables into quoted strings and writing them to a string buffer.
https://github.com/simphotonics/quote_buffer
dart generation generator quoted-strings quotes source-code string-buffer
Last synced: about 1 month ago
JSON representation
Extension methods for transforming single objects and iterables into quoted strings and writing them to a string buffer.
- Host: GitHub
- URL: https://github.com/simphotonics/quote_buffer
- Owner: simphotonics
- License: bsd-3-clause
- Created: 2020-01-18T19:30:50.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-04T17:33:26.000Z (10 months ago)
- Last Synced: 2024-11-06T17:37:11.762Z (3 months ago)
- Topics: dart, generation, generator, quoted-strings, quotes, source-code, string-buffer
- Language: Dart
- Homepage: https://pub.dev/packages/quote_buffer
- Size: 111 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Quote Buffer
[![Dart](https://github.com/simphotonics/quote_buffer/actions/workflows/dart.yml/badge.svg)](https://github.com/simphotonics/quote_buffer/actions/workflows/dart.yml)## Introduction
In the context of source code generation it is required to enclose emitted strings with
(escaped) quotation marks. In the following, such strings are called *quoted strings*.
Manually delimiting strings with quotation marks is error-prone
and repetitive especially when dealing with a collection of string-items.The package [`quote_buffer`][quote_buffer] provides [`Quote`][Quote]
an extension on Dart's [`StringBuffer`][StringBuffer] that adds methods for
transforming single objects and lists of objects into *quoted strings*.## Usage
To use this library include [`quote_buffer`][quote_buffer] as dependency in your `pubspec.yaml` file.
The section below lists the methods provided
and shows the console output obtained by printing the buffer content.1. **writeQ**(Object obj, {QuotationMark delimiter})
Writes *delimiter*, *obj*, *delimiter* to the buffer.
```Dart
import 'package:quote_buffer/quote_buffer.dart';final b = StringBuffer();
b.writeQ(29);
expect(b.toString(),'\'29\'');
print(b.toString()); // Console output below
```
```Console
'29'
```2. **writelnQ**(Object obj, {QuotationMark delimiter})
Writes *delimiter*, *obj*, *delimiter*, *newline symbol* to the buffer.
```Dart
import 'package:quote_buffer/quote_buffer.dart';final b = StringBuffer();
b.writelnQ('name', delimiter: QuotationMark.double);
expect(b.toString(), '\"name\"\n');
print(b.toString()); // Console output below
print('--- ---');
```
```Console
"name"--- ---
```
3. **writeAllQ**(Iterable objects, {String separator, QuotationMark delimiter})Writes *delimiter*, *first object*, *delimiter*, etc. to the buffer.
```Dart
import 'package:quote_buffer/quote_buffer.dart';final b = StringBuffer();
b.writeAllQ(
['one','two','three'],
separator: ', ',
);
expect(b.toString(), '\'one\', \'two\', \'three\'' );
print(b.toString()); // Console output below
```
```Console
'one', 'two', 'three'
```4. **writelnAllQ**(Iterable objects, {String separator1, String separator2, QuoationMark delimiter})
Writes *objects* in sequence: *delimiter*, *objects[0]*, *separator1*, *delimiter*, *separator2*, *newline symbol*, etc.
```Dart
import 'package:quote_buffer/quote_buffer.dart';final b = StringBuffer();
b.writelnAllQ(
['one','two','three'],
separator1: ' #',
separator2: ',',
delimiter: QuotationMark.double,
);
expect(b.toString(), '\"one #\",\n\"two #\",\n\"three\#');
print(b.toString()); // Console output below
print('--- ---');
```
```Console
"one #",
"two #",
"three"--- ---
```## Examples
The example located in the folder [example] shows how to use the extension
[`Quote`][Quote] 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].
[issue tracker]: https://github.com/simphotonics/quote_buffer/issues
[example]: https://github.com/simphotonics/quote_buffer/tree/main/example
[quote_buffer]: https://pub.dev/packages/quote_buffer
[Quote]: https://pub.dev/documentation/quote_buffer/latest/quote_buffer/Quote.html
[StringBuffer]: https://api.dart.dev/stable/dart-core/StringBuffer-class.html