platform/packages/code_buffer
thomashii@dukefirehawk.com 01bab10c02 Fixed AUTHORS.md
2021-05-14 11:20:01 +08:00
..
example Publish angel3_code_buffer 2021-05-14 11:06:32 +08:00
lib Publish angel3_code_buffer 2021-05-14 11:06:32 +08:00
test Publish angel3_code_buffer 2021-05-14 11:06:32 +08:00
.gitignore Publish angel3_code_buffer 2021-05-14 11:06:32 +08:00
.travis.yml Added package code_buffer 2021-03-16 08:14:28 +08:00
analysis_options.yaml Added package code_buffer 2021-03-16 08:14:28 +08:00
AUTHORS.md Fixed AUTHORS.md 2021-05-14 11:20:01 +08:00
CHANGELOG.md Publish angel3_code_buffer 2021-05-14 11:06:32 +08:00
LICENSE Publish angel3_code_buffer 2021-05-14 11:06:32 +08:00
pubspec.yaml Publish angel3_code_buffer 2021-05-14 11:06:32 +08:00
README.md Publish angel3_code_buffer 2021-05-14 11:06:32 +08:00

angel3_code_buffer

version Null Safety

License

An advanced StringBuffer geared toward generating code, and source maps.

Installation

In your pubspec.yaml:

dependencies:
  angel3_code_buffer: ^2.0.0

Usage

Use a CodeBuffer just like any regular StringBuffer:

String someFunc() {
    var buf = CodeBuffer();
    buf
      ..write('hello ')
      ..writeln('world!');
    return buf.toString();
}

However, a CodeBuffer supports indentation.

void someOtherFunc() {
  var buf = CodeBuffer();
  // Custom options...
  var buf = CodeBuffer(newline: '\r\n', space: '\t', trailingNewline: true);
  
  // Any following lines will have an incremented indentation level...
  buf.indent();
  
  // And vice-versa:
  buf.outdent();
}

CodeBuffer instances keep track of every SourceSpan they create. This makes them useful for codegen tools, or to-JS compilers.

void someFunc(CodeBuffer buf) {
  buf.write('hello');
  expect(buf.lastLine.text, 'hello');
  
  buf.writeln('world');
  expect(buf.lastLine.lastSpan.start.column, 5);
}

You can copy a CodeBuffer into another, heeding indentation rules:

void yetAnotherFunc(CodeBuffer a, CodeBuffer b) {
  b.copyInto(a);
}