Skip to content

Commit

Permalink
getChar uses getString(1). getChar now respects basic ascii
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeux committed Nov 30, 2011
1 parent e73f002 commit 870444a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
25 changes: 1 addition & 24 deletions src/jdataview.js
Expand Up @@ -147,30 +147,7 @@ jDataView.prototype = {
},

getChar: function (byteOffset) {
var value, size = 1;

// Handle the lack of byteOffset
if (byteOffset === undefined) {
byteOffset = this._offset;
}

if (this._isArrayBuffer || this._isNodeBuffer) {
// Use Int8Array and String.fromCharCode to extract a string
value = String.fromCharCode(this.getUint8(byteOffset));
} else {
// Error Checking
if (typeof byteOffset !== 'number') {
throw new TypeError('Type error');
}
if (byteOffset + size > this.byteLength) {
throw new Error('INDEX_SIZE_ERR: DOM Exception 1');
}

value = this.buffer.charAt(this._start + byteOffset);
this._offset = byteOffset + size;
}

return value;
return this.getString(1, byteOffset);
},

tell: function () {
Expand Down
12 changes: 6 additions & 6 deletions test/test.js
Expand Up @@ -63,13 +63,13 @@ function chr (x) {
}

test('Char', function () {
equal(view.getChar(0), chr(255));
equal(view.getChar(1), chr(254));
equal(view.getChar(2), chr(253));
equal(view.getChar(3), chr(252));
equal(view.getChar(4), chr(250));
equal(view.getChar(0), chr(65533));
equal(view.getChar(1), chr(65533));
equal(view.getChar(2), chr(65533));
equal(view.getChar(3), chr(65533));
equal(view.getChar(4), chr(65533));
equal(view.getChar(5), chr(0));
equal(view.getChar(6), chr(186));
equal(view.getChar(6), chr(65533));
equal(view.getChar(7), chr(1));
});

Expand Down

0 comments on commit 870444a

Please sign in to comment.