StringUtils

This library was meant to be used with Jacob Seidelin's BinaryAjax library.
The necessity for reading UTF-8 and UTF-16 strings was risen while developing the ID3 reader [ID3 Reader] since the input is only an array of bytes that must be read in a specific charset.

Source Code

Repository, stringutils.js

How To Use It

>StringUtils.readUTF8String([0xe6,0xac,0xa1,0xe5,0xb8,0xb8,0xe7,0x94,0xa8,0xe5,
                             0x9c,0x8b,0xe5,0xad,0x97,0xe6,0xa8,0x99,0xe6,0xba, 
                             0x96,0xe5,0xad,0x97,0xe9,0xab,0x94,0xe8,0xa1,0xa8])
""

>StringUtils.readUTF16String([0xff,0xfe,0x34,0xd8,0x1e,0xdd])
""

Documentation

StringUtils.readUTF8String(bytes, [maxBytes])
StringUtils.readUTF16String(bytes, [bigEndian], [maxBytes])