Coder Social home page Coder Social logo

string_scanner's People

Contributors

athomas avatar bcko avatar chalin avatar dependabot[bot] avatar devoncarew avatar franklinyow avatar jakemac53 avatar keertip avatar kevmoo avatar natebosch avatar nex3 avatar pq avatar srawlins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

string_scanner's Issues

chore: Release 1.0.4 or 1.1.0

master contains an @alwaysThrows fix for StringScanner.error (97cdbe2). Unfortunately, the CHANGELOG was updated to say 1.1.0, but the pubspec.yaml was updated to say 1.0.4. I think 1.0.4 is correct.

StringScanner does not find the corresponding data

StringScanner lost data with the code below:

var content = 'xxxx[fn=4][fn=37][fn=36][fn=12][fn=26]xxxx';

var _scanner = StringScanner(content);
    while (!_scanner.isDone) {
      if (_scanner.scan(RegExp('\\[fn=(\\d+)]'))) {
        print(content.substring(_scanner.lastMatch!.start + 1, _scanner.lastMatch!.end - 1));
      }
      if (!_scanner.isDone) {
        _scanner.position++;
      }
    }

the result is :

I/flutter (25050): fn=4
I/flutter (25050): fn=36
I/flutter (25050): fn=26

but If I use this method directly:

var allMatches = RegExp('\\[fn=(\\d+)]').allMatches(content);
    for (var element in allMatches) {
      print('--${element.start}');
    }

I got the right answer:

I/flutter (25050): [fn=4]
I/flutter (25050): [fn=37]
I/flutter (25050): [fn=36]
I/flutter (25050): [fn=12]
I/flutter (25050): [fn=26]

something lost when I use StringScanner.

[Proposal] Please add scanUntil and scanUntilAny

Please consider adding these methods

  /// Scans until [delimiter] matches [string] at the current position.
  ///
  /// Returns `true` if something is consumed, `false` otherwise.
  bool scanUntil(Pattern delimiter) {
    final oldPosition = position;
    while (!isDone && !matches(delimiter)) readChar();
    return oldPosition < position;
  }

  /// Scans until any of [delimiters] matches [string] at the current position.
  ///
  /// Returns `true` if something is consumed, `false` otherwise.
  scanUntilAny(List<Pattern> delimiters) {
    final oldPosition = position;
    while (!isDone && !delimiters.any(matches)) readChar();
    return oldPosition < position;
  }

SpanScanner doesn't handle UTF-16 surrogate pairs

The following example demonstrates the issue:

import 'package:string_scanner/string_scanner.dart';

void main() {
  final text = '\u{12345}';
  final scanner = new SpanScanner(text);
  final start = scanner.state;

  while (!scanner.isDone) {
    scanner.readChar();
  }

  print(scanner.spanFrom(start));
}

This code throws:

RangeError: End 2 must not be greater than the number of characters in the file, 1.

I believe the issue is that package:string_scanner operates on code units, whereas package:source_span operates on code points (runes), resulting in this index mismatch for surrogate pairs.

I found a workaround by decoding the string first:

import 'package:source_span/source_span.dart';
import 'package:string_scanner/string_scanner.dart';

void main() {
  final text = '\u{12345}';
  final file = new SourceFile.decoded(text.codeUnits);
  final scanner = new SpanScanner.within(file.span(0));
  final start = scanner.state;

  while (!scanner.isDone) {
    scanner.readChar();
  }

  print(scanner.spanFrom(start));
}

Is the code unit and code point distinction here intentional? If so is there a better way to ensure proper UTF-16 support? The workaround seems reasonable, although having to provide a span rather than the decoded file itself is clunky. Would adding a constructor to SpanScanner which accepts a decoded file or list of code units be a suitable solution? Or could SpanScanner optionally operate on code points instead of code units?

StringScanner.scan will stack overflow

here is my code

class _MyHomePageState extends State<MyHomePage> {
  StringScanner _scanner = StringScanner(testStr);
  @override
  Widget build(BuildContext context) {
    print('$_scanner');
    print('${_scanner.scan(RegExp(r'/\*(.|\n)*\*/'))}');
    return Container(
      child: Text('test'),
    );
  }
}

It works great on the emulator, but when I package the release version, it will cause a stack overflow.

Complete code here:Github code

and I build release apk

apk

img

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.