devexpress-richedit
Version:
DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.
25 lines (24 loc) • 933 B
JavaScript
export class DecoderBase {
static decode(str, specifiedSymbols) {
if (str == null)
return null;
else if (str.length == 1)
return DecoderBase.decodeByte(str, specifiedSymbols);
else {
const result = [];
for (let i = 0; i < str.length; i++) {
const sourceCharCode = str.charCodeAt(i);
const target = specifiedSymbols[sourceCharCode];
const targetCharCode = target !== undefined ? target : sourceCharCode;
result.push(String.fromCharCode(targetCharCode));
}
return result.join('');
}
}
static decodeByte(byte, specifiedSymbols) {
const ord = byte.charCodeAt(0);
const target = specifiedSymbols[ord];
const charCode = target !== undefined ? target : ord;
return String.fromCharCode(charCode);
}
}