{"action":"opened","issue":{"url":"https://api.github.com/repos/petitparser/dart-petitparser/issues/55","repository_url":"https://api.github.com/repos/petitparser/dart-petitparser","labels_url":"https://api.github.com/repos/petitparser/dart-petitparser/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/petitparser/dart-petitparser/issues/55/comments","events_url":"https://api.github.com/repos/petitparser/dart-petitparser/issues/55/events","html_url":"https://github.com/petitparser/dart-petitparser/issues/55","id":196513238,"number":55,"title":"Wrap input in Buffer","user":{"login":"renggli","id":131610,"avatar_url":"https://avatars.githubusercontent.com/u/131610?v=3","gravatar_id":"","url":"https://api.github.com/users/renggli","html_url":"https://github.com/renggli","followers_url":"https://api.github.com/users/renggli/followers","following_url":"https://api.github.com/users/renggli/following{/other_user}","gists_url":"https://api.github.com/users/renggli/gists{/gist_id}","starred_url":"https://api.github.com/users/renggli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renggli/subscriptions","organizations_url":"https://api.github.com/users/renggli/orgs","repos_url":"https://api.github.com/users/renggli/repos","events_url":"https://api.github.com/users/renggli/events{/privacy}","received_events_url":"https://api.github.com/users/renggli/received_events","type":"User","site_admin":false},"labels":[{"id":5820403,"url":"https://api.github.com/repos/petitparser/dart-petitparser/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-19T20:30:04Z","updated_at":"2016-12-19T20:30:04Z","closed_at":null,"body":"Currently code is scattered with type-checks on the parsed input being a `String` or a `List`. Having a buffer could avoid this problem and enable further extensibility on the data being parsed.\r\n\r\n    /// An immutable parse buffer.\r\n    abstract class Buffer<E, S> {\r\n    \r\n      ///\r\n      factory Buffer.from(Object input) {\r\n        if (input is String) {\r\n          return new _StringBuffer(input, input.length);\r\n        } else if (input is List) {\r\n          return new _ListBuffer(input, input.length);\r\n        }\r\n      }\r\n    \r\n      /// Return the underlying data structure.\r\n      S data;\r\n    \r\n      /// Return the size of the buffer.\r\n      int get size;\r\n    \r\n      /// Return the element at position [value].\r\n      E operator [](int index);\r\n    \r\n      /// Return the sequence from [start] to [stop].\r\n      S sequence(int start, int stop);\r\n    \r\n    }\r\n    \r\n    class _StringBuffer implements Buffer<int, String> {\r\n    \r\n      @override\r\n      final String data;\r\n    \r\n      @override\r\n      final int length;\r\n    \r\n      _StringBuffer(this.data, this.length);\r\n    \r\n      @override\r\n      int operator [](int index) => data.codeUnitAt(index);\r\n    \r\n      @override\r\n      String sequence(int startIndex, int stopIndex) => data.substring(startIndex, stopIndex);\r\n    \r\n    }\r\n    \r\n    class _ListBuffer<T> implements Buffer<T, List<T>> {\r\n    \r\n      @override\r\n      final List<T> data;\r\n    \r\n      @override\r\n      final int length;\r\n    \r\n      _ListBuffer(this.data, this.length);\r\n    \r\n      @override\r\n      T operator [](int index) => data[index];\r\n    \r\n      @override\r\n      List<T> sequence(int startIndex, int stopIndex) => data.sublist(startIndex, stopIndex);\r\n    \r\n    }"}}
{"actor":{"display_login":"renggli"}}