Skip to content

telenko/string-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#General description Library which allows to work with strings as with streams. Allows to write parsers, tokenizers etc.

#API ..tbd

#Example Pseudo-code of writing html-parser

    function readNode () {
      var childs = [];
      var tag = stream.readNext('<');
      var tagName = stream.readNextWord();
      stream.startRecording();
      var endTag = stream.readNext('>');
      var nodeTemplate = stream.stopRecording();
      while (true) {
          stream.startRecording();
          stream.readNext('<');
          var textNode = stream.stopRecording();
          if (textNode.trim().length > 0) {
              childs.push({type: 'text', template: textNode});
          }
          if (stream.next() === '/') {
              break;
          } else {
              stream.moveBack(2);
              childs.push(readNode());
          }
      }
      var resp = {tagName: tagName, template: nodeTemplate, children: childs};
      return resp;
     }
    
     var nodes = [];
     while (!stream.isCompleted()) {
      nodes.push(readNode());
     }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published