|
|
@ -19,8 +19,15 @@ |
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
function assertEncoding(encoding) { |
|
|
|
if (encoding && !Buffer.isEncoding(encoding)) { |
|
|
|
throw new Error('Unknown encoding: ' + encoding); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var StringDecoder = exports.StringDecoder = function(encoding) { |
|
|
|
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); |
|
|
|
assertEncoding(encoding); |
|
|
|
switch (this.encoding) { |
|
|
|
case 'utf8': |
|
|
|
// CESU-8 represents each of Surrogate Pair by 3-bytes
|
|
|
|