quote_buffer 1.1.0 copy "quote_buffer: ^1.1.0" to clipboard
quote_buffer: ^1.1.0 copied to clipboard

Extension methods on StringBuffer for transforming objects and iterables into quoted strings.

Quote Buffer #

Dart

Introduction #

In the context of source code generation it is often 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 provides Quote an extension on Dart's StringBuffer that adds methods for transforming single objects and iterables into quoted strings.

Usage #

To use this library include 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: Writes quotationMark + obj + quotationMark to the buffer.

    import 'package:quote_buffer/quote_buffer.dart';
    
    final b = StringBuffer();
    b.writeQ(29);
    print(b.toString()); // Console output below
    
    '29'
    
  2. writelnQ: Writes quotationMark + obj + quotationMark + newline to the buffer.

    import 'package:quote_buffer/quote_buffer.dart';
    
    final b = StringBuffer();
    b.writelnQ('name', quotationMark: QuotationMark.double);
    print(b.toString()); // Console output below
    print('--- ---');
    
    "name"
    
    --- ---
    
  3. writeAllQ: Writes quotationMark + objects[0] + quotationMark + separator ..., to the buffer.

    import 'package:quote_buffer/quote_buffer.dart';
    
    final b = StringBuffer();
    b.writeAllQ(['one','two','three'], separator: ', ');
    print(b.toString()); // Console output below
    
    'one', 'two', 'three',
    
  4. writelnAllQ: Writes quotationMark + objects[0] + separator1 + quotationMark + separator2 + newline ... to the buffer.

    import 'package:quote_buffer/quote_buffer.dart';
    
    final b = StringBuffer();
    b.writelnAllQ(
      ['one','two','three'],
      separator1: '#',
      separator2: ',',
      quotationMark: QuotationMark.double,
    );
    print(b.toString()); // Console output below
    print('--- ---');
    
     "one#",
     "two#",
     "three#",
    
     --- ---
    
  5. writelnAll: Writes objects[0] + separator + newline ... to the buffer.

    import 'package:quote_buffer/quote_buffer.dart';
    final b = StringBuffer();
    b.writelnAll(['one','two','three'], separator: ',');
    print(b.toString()); // Console output below
    print('--- ---');
    
     one,
     two,
     three,
    
     --- ---
    

The methods writing an Iterable to the StringBuffer accept the parameter addTrailingSeparator. Its value may be set to false to prevent the addition of a trailing separator.

Examples #

The example located in the folder example shows how to use the extension 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.

1
likes
160
points
19.1k
downloads

Documentation

API reference

Publisher

verified publishersimphotonics.com

Weekly Downloads

Extension methods on StringBuffer for transforming objects and iterables into quoted strings.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

More

Packages that depend on quote_buffer