Code coverage report for lib/word.js

Statements: 100% (96 / 96)      Branches: 100% (36 / 36)      Functions: 100% (10 / 10)      Lines: 100% (96 / 96)      Ignored: none     

All files » lib/ » word.js
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181    1 5   5 5   5 9     5         1 42   42   42 6     36 84 84 30   54 6 6   48       1 11   11   11 5     6 17 17 5   12 1 1   11       1 11   11 11 5     6   6 17 17 5   12 1 1   11         1 30   30 30 30 92       30 30   62       1 5   5 5 5 14       5 5   9       1 5   5 5 5 5 5 14       5 5 5   9       1 42   42 12     30   30     1 11   11 6     5   5     1 11   11 6     5   5     1          
'use strict';
 
function ArrayBuffer2string (ar) {
    var i, res, ar8;
 
    ar8 = new Uint8Array(ar);
    res = '';
 
    for (i = 0; i < ar8.length; i++) {
        res += String.fromCharCode(ar8[i]);
    }
 
    return res;
}
 
 
// Skip 'delimiters'
function skip (delimeter) {
    var last, char;
 
    last = this.last;
 
    if (this.ptr > last) { // end of buffer
        return;
    }
 
    while (true) {
        char = this.buf[this.ptr];
        if (char.search(delimeter) === -1) { // end of gap
            return true;
        }
        if (this.ptr === last) { // end of buffer
            this.ptr++;
            return;
        }
        this.ptr++;
    }
}
 
function skipBuffer (delimeter) {
    var last, char;
 
    last = this.last;
 
    if (this.ptr > last) { // end of buffer
        return;
    }
 
    while (true) {
        char = this.buf[this.ptr];
        if (String.fromCharCode(char).search(delimeter) === -1) { // end of gap
            return true;
        }
        if (this.ptr === last) { // end of buffer
            this.ptr++;
            return;
        }
        this.ptr++;
    }
}
 
function skipArrayBuffer (delimeter) {
    var last, char, buf8;
 
    last = this.last;
    if (this.ptr > last) { // end of buffer
        return;
    }
 
    buf8 = new Uint8Array(this.buf);
 
    while (true) {
        char = buf8[this.ptr];
        if (String.fromCharCode(char).search(delimeter) === -1) { // end of gap
            return true;
        }
        if (this.ptr === last) { // end of buffer
            this.ptr++;
            return;
        }
        this.ptr++;
    }
}
 
// Parse characters ccc delimited by 'delimeter'
function take (delimeter) {
    var start, last, res;
 
    last = this.last;
    start = this.ptr;
    while (true) {
        if (
            (this.ptr > last) ||
            (this.buf[this.ptr].search(delimeter) === 0)
        ) { // good part
            res = this.buf.slice(start, this.ptr);
            return res;
        }
        this.ptr++;
    }
}
 
function takeBuffer (delimeter) {
    var start, last, res;
 
    last = this.last;
    start = this.ptr;
    while (true) {
        if (
            (this.ptr > last) ||
            (String.fromCharCode(this.buf[this.ptr]).search(delimeter) === 0)
        ) { // good part
            res = this.buf.slice(start, this.ptr).toString();
            return res;
        }
        this.ptr++;
    }
}
 
function takeArrayBuffer (delimeter) {
    var start, res, last, buf, buf8;
 
    last = this.last;
    start = this.ptr;
    buf = this.buf;
    buf8 = new Uint8Array(buf);
    while (true) {
        if (
            (this.ptr > last) ||
            (String.fromCharCode(buf8[this.ptr]).search(delimeter) === 0)
        ) { // good part
            res = buf.slice(start, this.ptr);
            res = ArrayBuffer2string(res);
            return res;
        }
        this.ptr++;
    }
}
 
function str (delimeter) {
    var res;
 
    if (skip.call(this, delimeter) === undefined) {
        return;
    };
    // console.log('skip --> %s', this.ptr);
    res = take.call(this, delimeter);
    // console.log('take --> %s %s', this.ptr, res);
    return res;
}
 
function buf (delimeter) {
    var res;
 
    if (skipBuffer.call(this, delimeter) === undefined) {
        return;
    };
    // console.log('skip --> %s', this.ptr);
    res = takeBuffer.call(this, delimeter);
    // console.log('take --> %s %s', this.ptr, res);
    return res;
}
 
function arr (delimeter) {
    var res;
 
    if (skipArrayBuffer.call(this, delimeter) === undefined) {
        return;
    };
    // console.log('skip --> %s', this.ptr);
    res = takeArrayBuffer.call(this, delimeter);
    // console.log('take --> %s %s', this.ptr, res);
    return res;
}
 
module.exports = {
    str: str,
    buf: buf,
    arr: arr
};