Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special charset support #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
experiments with win1251 support.
  • Loading branch information
podviaznikov committed Jun 12, 2011
commit 691b9be8150c7894ccfb6524cc423f5f6d21bd32
39 changes: 31 additions & 8 deletions dist/id3.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ var StringUtils = {
var string = new String(arr.join(""));
string.bytesReadCount = i;
return string;
},

readWin1251String: function(str) {
var charmap = unescape(
"%u0402%u0403%u201A%u0453%u201E%u2026%u2020%u2021%u20AC%u2030%u0409%u2039%u040A%u040C%u040B%u040F"+
"%u0452%u2018%u2019%u201C%u201D%u2022%u2013%u2014%u0000%u2122%u0459%u203A%u045A%u045C%u045B%u045F"+
"%u00A0%u040E%u045E%u0408%u00A4%u0490%u00A6%u00A7%u0401%u00A9%u0404%u00AB%u00AC%u00AD%u00AE%u0407"+
"%u00B0%u00B1%u0406%u0456%u0491%u00B5%u00B6%u00B7%u0451%u2116%u0454%u00BB%u0458%u0405%u0455%u0457")
var code2char = function(code) {
if(code >= 0xC0 && code <= 0xFF) return String.fromCharCode(code - 0xC0 + 0x0410)
if(code >= 0x80 && code <= 0xBF) return charmap.charAt(code - 0x80)
return String.fromCharCode(code)
}
var res = ""
for(var i = 0; i < str.length; i++) res = res + code2char(str.charCodeAt(i))
console.log('Win1251 result:',res);
return res
}
};
/**
Expand Down Expand Up @@ -357,9 +374,11 @@ function BinaryFile(strData, iDataOffset, iDataLength) {
// @aadsm
this.getStringWithCharsetAt = function(iOffset, iLength, iCharset) {
var bytes = this.getBytesAt(iOffset, iLength);
var originalString = this.getStringAt(iOffset, iLength);
var sString;

console.log('Charset:',iCharset,jschardet.detect(originalString));
switch( iCharset.toLowerCase() ) {

case 'utf-16':
case 'utf-16le':
case 'utf-16be':
Expand All @@ -369,7 +388,8 @@ function BinaryFile(strData, iDataOffset, iDataLength) {
case 'utf-8':
sString = StringUtils.readUTF8String(bytes);
break;

case 'iso-8859-1':
sString = StringUtils.readWin1251String(originalString);
default:
sString = StringUtils.readNullTerminatedString(bytes);
break;
Expand All @@ -393,15 +413,18 @@ function BinaryFile(strData, iDataOffset, iDataLength) {
};
}
/**
* Copyright (c) 2010 António Afonso, antonio.afonso gmail, http://www.aadsm.net/
* Copyright (c) 2011 Anton Podviaznikov, podviaznikov@gmail.com
* MIT License [http://www.opensource.org/licenses/mit-license.php]
*
*/
window.FileAPIReader = function(binaryData) {
return function(url, fncCallback, fncError) {
fncCallback(new BinaryFile(binaryData));
}
};
(function(ns) {
ns["FileAPIReader"] = function(binaryData) {
return function(url, fncCallback, fncError) {
fncCallback(new BinaryFile(binaryData));
}
};
})(this);

// Modified version of http://www.webtoolkit.info/javascript-base64.html
(function(ns) {
ns.Base64 = {
Expand Down
Loading