Skip to content

Commit

Permalink
Merge pull request #16 from Live2D/feature/fix_encode
Browse files Browse the repository at this point in the history
Fix encode.
  • Loading branch information
itoh-at-live2d-com authored Nov 8, 2018
2 parents b2b7dc3 + 46a8e08 commit 47e93ff
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions Framework/utils/cubismjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,28 @@ export namespace Live2DCubismFramework
*/
public arrayBufferToString(buffer: ArrayBuffer): string
{
let encodedString: string = String.fromCharCode.apply(null, new Uint8Array(buffer));
let decodedString: string = decodeURIComponent(escape(encodedString));
return decodedString;
let uint8Array: Uint8Array = new Uint8Array(buffer);
let str: string = "";

for(let i: number = 0, len: number = uint8Array.length; i < len; ++i)
{
str += ("%" + this.pad(uint8Array[i].toString(16)));
}

str = decodeURIComponent(str);
return str;
}

/**
* エンコード、パディング
*/
private pad(n: string): string
{
return n.length < 2
? "0" + n
: n;
};

/**
* JSONのパースを実行する
* @param buffer パース対象のデータバイト
Expand Down

0 comments on commit 47e93ff

Please sign in to comment.