all files / lib/stream/ stringstream.js

100% Statements 11/11
100% Branches 0/0
100% Functions 5/5
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                              182×         276316×       265811×     182×      
/*
 * Parsec
 * https://github.com/d-plaindoux/parsec
 *
 * Copyright (c) 2016 Didier Plaindoux
 * Licensed under the LGPL2 license.
 */
 
 module.exports = (function() {
     
     'use strict';
     
     var stream = require('./stream.js');
     
     /**
      * String stream class
      */
     function StringStream(source) {
         this.source = source;
     }
     
     StringStream.prototype = stream();
     
     // StringStream 'a => unit -> boolean
     StringStream.prototype.endOfStream = function(index) {
         return this.source.length <= index;
     };
     
     // StringStream 'a => number -> 'a <+> error
     StringStream.prototype.unsafeGet = function(index) {
         return this.source.charAt(index);
     };
 
     return function(source) {
         return new StringStream(source);
     };
     
 }());