Skip to content

Commit

Permalink
added enable decoding to StringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
odahcam committed Feb 27, 2020
1 parent db94578 commit ee78b9f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/core/pdf417/decoder/DecodedBitStreamParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,18 @@ export default /*final*/ class DecodedBitStreamParser {
* @throws FormatException
*/
static decode(codewords: Int32Array, ecLevel: string): DecoderResult {
// pass encoding to result (will be used for decode symbols in byte mode)
let result: StringBuilder = new StringBuilder('');
// let encoding: Charset = StandardCharsets.ISO_8859_1;
let encoding = CharacterSetECI.ISO8859_1;
// pass encoding to result (will be used for decode symbols in byte mode)
let result: StringBuilder = new StringBuilder('', encoding);
/**
* @note the next command is specific from this TypeScript library
* because TS can't properly cast some values to char and
* convert it to string later correctlt due to encoding
* differences from Java version. As reported here:
* https://github.com/zxing-js/library/pull/264/files#r382831593
*/
result.enableDecoding(encoding);
// Get compaction mode
let codeIndex: int = 1;
let code: int = codewords[codeIndex++];
Expand Down
16 changes: 13 additions & 3 deletions src/core/util/StringBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import CharacterSetECI from '../common/CharacterSetECI';
import StringEncoding from './StringEncoding';


export default class StringBuilder {

public constructor(private value: string = '', private format = null) {}
private encoding: CharacterSetECI;

public constructor(private value: string = '') {}

public enableDecoding(encoding: CharacterSetECI): StringBuilder {
this.encoding = encoding
return this;
}

public append(s: string | number): StringBuilder {
if (typeof s === 'string') {
this.value += s.toString();
} else if (this.format) {
} else if (this.encoding) {
// use passed format (fromCharCode will return UTF8 encoding)
this.value += StringEncoding.decode(new Uint8Array([s]), this.format);
this.value += StringEncoding.decode(new Uint8Array([s]), this.encoding);
} else {
// correctly converts from UTF-8, but not other encodings
this.value += String.fromCharCode(s);
}
return this;
Expand Down

0 comments on commit ee78b9f

Please sign in to comment.