@magic-xpa/utils
Version:
magic utils package
1,346 lines (1,342 loc) • 799 kB
JavaScript
import { Encoding, StringBuilder, Hashtable, NChar, NNumber, Stack, NString, RefParam, DateTime, ApplicationException, ISO_8859_1_Encoding, Int32, Exception, Debug, Thread, List } from '@magic-xpa/mscorelib';
import { parseString } from 'xml2js';
import { isNullOrUndefined } from 'util';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class UtilStrByteMode {
/**
* @return {?}
*/
static isLocaleDefLangDBCS() {
return UtilStrByteMode._bLocaleDefLangJPN || UtilStrByteMode._bLocaleDefLangCHN || UtilStrByteMode._bLocaleDefLangKOR;
}
/**
* @return {?}
*/
static isLocaleDefLangJPN() {
return UtilStrByteMode._bLocaleDefLangJPN;
}
/**
* @return {?}
*/
static isLocaleDefLangKOR() {
return UtilStrByteMode._bLocaleDefLangKOR;
}
/**
* @param {?} c
* @return {?}
*/
static isKoreanCharacter(c) {
return (44032 <= /*'가'*/ c && c <= 55203 /*'힣'*/) || (4352 <= /*'ᄀ'*/ c && c <= 4607 /*'ᇿ'*/) || (12592 <= /*''*/ c && c <= 12687 /*''*/) || (43360 <= /*'ꥠ'*/ c && c <= 43391 /*''*/) || (55216 <= /*'ힰ'*/ c && c <= 55295 /*''*/);
}
/**
* @param {?} strVal
* @return {?}
*/
static lenB(strVal) {
// convert to byte[] by default-encoding
return UtilStrByteMode.Encoding.GetByteCount(strVal);
}
/**
* @param {?} strVal
* @param {?} ofs
* @param {?} len
* @return {?}
*/
static midB(strVal, ofs, len) {
/** @type {?} */
let intValidMaxIndex = -1;
/** @type {?} */
let intValidMinIndex = -1;
/** @type {?} */
let bHeadSpace = false;
/** @type {?} */
let bEndSpace = false;
/** @type {?} */
let strRet;
// check and modify ofs & len
if (len <= 0)
return "";
if (ofs <= 0) {
ofs = 0;
intValidMinIndex = 0;
bHeadSpace = false;
}
/** @type {?} */
let intByteLength = UtilStrByteMode.lenB(strVal);
if (intByteLength < ofs)
return "";
/** @type {?} */
let LenMax = intByteLength - ofs;
if (LenMax < len)
len = LenMax;
// set MinIndex and MaxIndex for substring
intByteLength = 0;
for (let intIndex = 0; intIndex < strVal.length; intIndex = intIndex + 1) {
/** @type {?} */
let s = strVal.substr(intIndex, 1);
intByteLength = intByteLength + UtilStrByteMode.Encoding.GetByteCount(s);
if (intValidMinIndex === -1) {
if (intByteLength === ofs) {
intValidMinIndex = intIndex + 1;
bHeadSpace = false;
}
else if (intByteLength > ofs) {
intValidMinIndex = intIndex + 1;
bHeadSpace = true;
}
}
if (intValidMaxIndex === -1) {
if (intByteLength === ofs + len) {
intValidMaxIndex = intIndex;
bEndSpace = false;
break;
}
else if (intByteLength > ofs + len) {
intValidMaxIndex = intIndex - 1;
bEndSpace = true;
break;
}
}
}
/** @type {?} */
let strbufAddingBuf = new StringBuilder(len);
// execute Mid
if (bHeadSpace) {
strbufAddingBuf.Append(' ');
}
if (intValidMinIndex <= intValidMaxIndex) {
strbufAddingBuf.Append(strVal.substr(intValidMinIndex, intValidMaxIndex + 1 - intValidMinIndex));
}
if (bEndSpace) {
strbufAddingBuf.Append(' ');
}
strRet = strbufAddingBuf.ToString();
strbufAddingBuf = null;
return strRet;
}
/**
* @param {?} strVal
* @param {?} len
* @return {?}
*/
static leftB(strVal, len) {
return UtilStrByteMode.midB(strVal, 0, len);
}
/**
* @param {?} strVal
* @param {?} len
* @return {?}
*/
static rightB(strVal, len) {
/** @type {?} */
let byteFldsValLen = UtilStrByteMode.lenB(strVal);
if (len < 0) {
len = 0;
}
/** @type {?} */
let ofs = byteFldsValLen - len;
if (ofs < 0) {
ofs = 0;
}
return UtilStrByteMode.midB(strVal, ofs, len);
}
/**
* @param {?} strTarget
* @param {?} strSource
* @param {?} ofs
* @param {?} len
* @return {?}
*/
static insB(strTarget, strSource, ofs, len) {
if (ofs < 0) {
ofs = 0;
}
else {
if (ofs >= 1) {
ofs = ofs - 1;
}
}
if (len < 0) {
len = 0;
}
/** @type {?} */
let intTargetLenB = UtilStrByteMode.lenB(strTarget);
/** @type {?} */
let intSourceLenB = UtilStrByteMode.lenB(strSource);
/** @type {?} */
let strbufRetVal = new StringBuilder(ofs + len);
strbufRetVal.Append(UtilStrByteMode.leftB(strTarget, ofs));
for (let intAddSpaceLen = ofs - intTargetLenB; intAddSpaceLen > 0; intAddSpaceLen = intAddSpaceLen - 1) {
strbufRetVal.Append(' ');
}
strbufRetVal.Append(UtilStrByteMode.leftB(strSource, len));
for (let i = len - intSourceLenB; i > 0; i = i - 1) {
strbufRetVal.Append(' ');
}
strbufRetVal.Append(UtilStrByteMode.rightB(strTarget, intTargetLenB - ofs));
return strbufRetVal.ToString();
}
/**
* @param {?} strVal
* @param {?} ofs
* @param {?} len
* @return {?}
*/
static delB(strVal, ofs, len) {
if (ofs < 0) {
ofs = 0;
}
else {
if (ofs >= 1) {
ofs = ofs - 1;
}
}
/** @type {?} */
let intValLenB = UtilStrByteMode.lenB(strVal);
if (ofs + len > intValLenB) {
len = intValLenB - ofs;
}
/** @type {?} */
let strRet;
if (len <= 0) {
strRet = strVal;
}
else {
/** @type {?} */
let intRightSideLenB = intValLenB - ofs - len;
if (intRightSideLenB < 0) {
strRet = strVal;
}
else {
/** @type {?} */
let strbufRetVal = new StringBuilder(ofs + intRightSideLenB);
strbufRetVal.Append(UtilStrByteMode.leftB(strVal, ofs));
strbufRetVal.Append(UtilStrByteMode.rightB(strVal, intRightSideLenB));
strRet = strbufRetVal.ToString();
}
}
return strRet;
}
/**
* @param {?} strTarget
* @param {?} strSearch
* @return {?}
*/
static instrB(strTarget, strSearch) {
if (strSearch.length === 0) {
// nothing to look for
return 0;
}
/** @type {?} */
let ofs = strTarget.indexOf(strSearch);
if (ofs < 0) {
// not found
return 0;
}
return UtilStrByteMode.lenB(strTarget.substr(0, ofs)) + 1;
}
/**
* @param {?} strTarget
* @param {?} strOrigin
* @param {?} ofs
* @param {?} len
* @return {?}
*/
static repB(strTarget, strOrigin, ofs, len) {
/** @type {?} */
let strbufAddingBuf = new StringBuilder();
if (ofs < 0) {
ofs = 0;
}
else {
if (ofs >= 1) {
ofs = ofs - 1;
}
}
if (len < 0) {
len = 0;
}
strbufAddingBuf.Append(UtilStrByteMode.leftB(strTarget, ofs));
/** @type {?} */
let intAddSpaceLen = ofs - UtilStrByteMode.lenB(strTarget);
for (; intAddSpaceLen > 0; intAddSpaceLen--)
strbufAddingBuf.Append(' ');
strbufAddingBuf.Append(UtilStrByteMode.leftB(strOrigin, len));
/** @type {?} */
let intRightLen = UtilStrByteMode.lenB(strTarget) - (ofs + len);
if (intRightLen > 0) {
strbufAddingBuf.Append(UtilStrByteMode.rightB(strTarget, intRightLen));
}
// add blanks to the end
intAddSpaceLen = len - UtilStrByteMode.lenB(strOrigin);
for (; intAddSpaceLen > 0; intAddSpaceLen--) {
strbufAddingBuf.Append(' ');
}
return strbufAddingBuf.ToString();
}
/**
* @param {?} strTarget
* @param {?} strOrigin
* @param {?} ofs
* @param {?} len
* @return {?}
*/
static repC(strTarget, strOrigin, ofs, len) {
/** @type {?} */
let strbufAddingBuf = new StringBuilder();
if (ofs < 0) {
ofs = 0;
}
else {
if (ofs >= 1) {
ofs = ofs - 1;
}
}
if (len < 0) {
len = 0;
}
strbufAddingBuf.Append(strTarget.substr(0, ofs));
/** @type {?} */
let intAddSpaceLen = ofs - strTarget.length;
for (; intAddSpaceLen > 0; intAddSpaceLen--)
strbufAddingBuf.Append(' ');
strbufAddingBuf.Append(strOrigin.substr(0, len));
/** @type {?} */
let intRightLen = strTarget.length - (ofs + len);
if (intRightLen > 0) {
strbufAddingBuf.Append(strTarget.substr(ofs + len));
}
for (let i = len - strOrigin.length; i > 0; i = i - 1) {
strbufAddingBuf.Append(' ');
}
return strbufAddingBuf.ToString();
}
/**
* @param {?} str
* @return {?}
*/
static isHalfWidth(str) {
/** @type {?} */
let letter = str.charCodeAt(0);
if (32 <= /*' '*/ letter && letter <= 126 /*'~'*/) {
return true;
}
else {
/** @type {?} */
let len = UtilStrByteMode.lenB(str);
if (len === 1)
return true;
}
return false;
}
/**
* @param {?} letter
* @return {?}
*/
static isDigit(letter) {
return 48 <= /*'0'*/ /*'0'*/ letter.charCodeAt(0) && letter.charCodeAt(0) <= 57 /*'9'*/;
}
/**
* @param {?} letter
* @return {?}
*/
static asNumeric(letter) {
/** @type {?} */
let result;
switch (letter.charCodeAt(0)) {
case 42: /*'*'*/
case 43: /*'+'*/
case 44: /*','*/
case 45: /*'-'*/
case 46: /*'.'*/
case 47:
/*'/'*/
result = true;
break;
default:
result = false;
break;
}
return result;
}
/**
* @param {?} strSource
* @param {?} strDest
* @param {?} pos
* @param {?} isAdvance
* @return {?}
*/
static convPos(strSource, strDest, pos, isAdvance) {
/** @type {?} */
let retPos;
if (pos < 0)
return 0;
if (pos > strSource.length)
pos = strSource.length;
/** @type {?} */
let diffLen = UtilStrByteMode.lenB(strSource) - UtilStrByteMode.lenB(strDest);
if (diffLen > 0) {
/** @type {?} */
let stringBuilder = new StringBuilder(strDest);
for (; diffLen > 0; diffLen--)
stringBuilder.Append(' ');
strDest = stringBuilder.ToString();
}
/** @type {?} */
let byteSource = UtilStrByteMode.Encoding.GetBytes(strSource.substr(0, pos));
/** @type {?} */
let strLeftB = UtilStrByteMode.leftB(strDest, byteSource.length);
retPos = strLeftB.length;
if (!isAdvance && retPos > 0 && strLeftB.charCodeAt(retPos - 1) === 32 /*' '*/ && strDest.charCodeAt(retPos - 1) !== 32 /*' '*/) {
retPos = retPos - 1;
}
return retPos;
}
/**
* @param {?} str
* @param {?} picture
* @return {?}
*/
static getMinLenPicture(str, picture) {
/** @type {?} */
let len = 0;
if (UtilStrByteMode.lenB(picture) - UtilStrByteMode.lenB(str) > 0) {
len = UtilStrByteMode.convPos(str, picture, str.length, false);
}
else
len = picture.length;
return len;
}
/**
* @param {?} str1
* @param {?} str2
* @return {?}
*/
static strcmp(str1, str2) {
/** @type {?} */
let array1 = UtilStrByteMode.Encoding.GetBytes(str1);
/** @type {?} */
let array2 = UtilStrByteMode.Encoding.GetBytes(str2);
for (let i = 0; i < array1.length && i < array2.length; i++) {
if (array1[i] > array2[i]) {
return 1;
}
else if (array1[i] < array2[i]) {
return -1;
}
}
if (array1.length > array2.length)
return 1;
if (array1.length < array2.length)
return -1;
else
return 0;
}
}
UtilStrByteMode.Encoding = Encoding.UTF8;
// TODO : need to check what to do with CultureInfo
UtilStrByteMode.twoLetterISOLanguageName = " ";
UtilStrByteMode._bLocaleDefLangJPN = (UtilStrByteMode.twoLetterISOLanguageName === "ja");
UtilStrByteMode._bLocaleDefLangCHN = (UtilStrByteMode.twoLetterISOLanguageName === "zh");
UtilStrByteMode._bLocaleDefLangKOR = (UtilStrByteMode.twoLetterISOLanguageName === "ko");
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class Rtf_SYMBOL {
/**
* @param {?} keyWord
* @param {?} kwd
* @param {?} idxInRgprop
*/
constructor(keyWord, kwd, idxInRgprop) {
this.szKeyword = null;
/* RTF keyword */
this.kwd = null;
/* base action to take */
this.idxInRgprop = null;
this.szKeyword = keyWord;
this.kwd = kwd;
this.idxInRgprop = idxInRgprop;
}
}
class Rtf_PROP {
/**
* @param {?} actn
* @param {?} prop
*/
constructor(actn, prop) {
this.actn = null;
/* size of value */
this.prop = null;
this.actn = actn;
this.prop = prop;
}
}
class Rtf_StackSave {
constructor() {
this.rds = null;
this.ris = null;
}
}
/** @enum {number} */
const Rtf_KWD = {
CHAR: 0,
DEST: 1,
PROP: 2,
SPEC: 3,
};
Rtf_KWD[Rtf_KWD.CHAR] = 'CHAR';
Rtf_KWD[Rtf_KWD.DEST] = 'DEST';
Rtf_KWD[Rtf_KWD.PROP] = 'PROP';
Rtf_KWD[Rtf_KWD.SPEC] = 'SPEC';
/** @enum {number} */
const Rtf_PROPTYPE = {
CHP: 0,
PAP: 1,
SEP: 2,
DOP: 3,
};
Rtf_PROPTYPE[Rtf_PROPTYPE.CHP] = 'CHP';
Rtf_PROPTYPE[Rtf_PROPTYPE.PAP] = 'PAP';
Rtf_PROPTYPE[Rtf_PROPTYPE.SEP] = 'SEP';
Rtf_PROPTYPE[Rtf_PROPTYPE.DOP] = 'DOP';
/** @enum {number} */
const Rtf_ACTN = {
SPEC: 0,
BYTE: 1,
WORD: 2,
};
Rtf_ACTN[Rtf_ACTN.SPEC] = 'SPEC';
Rtf_ACTN[Rtf_ACTN.BYTE] = 'BYTE';
Rtf_ACTN[Rtf_ACTN.WORD] = 'WORD';
/** @enum {number} */
const Rtf_IPFN = {
BIN: 0,
HEX: 1,
SKIP_DEST: 2,
BREAK: 3,
NEW: 4,
FONT: 5,
CHARSET: 6,
UNICODE: 7,
};
Rtf_IPFN[Rtf_IPFN.BIN] = 'BIN';
Rtf_IPFN[Rtf_IPFN.HEX] = 'HEX';
Rtf_IPFN[Rtf_IPFN.SKIP_DEST] = 'SKIP_DEST';
Rtf_IPFN[Rtf_IPFN.BREAK] = 'BREAK';
Rtf_IPFN[Rtf_IPFN.NEW] = 'NEW';
Rtf_IPFN[Rtf_IPFN.FONT] = 'FONT';
Rtf_IPFN[Rtf_IPFN.CHARSET] = 'CHARSET';
Rtf_IPFN[Rtf_IPFN.UNICODE] = 'UNICODE';
/** @enum {number} */
const Rtf_IDEST = {
PICT: 0,
COLOR: 1,
SKIP: 2,
};
Rtf_IDEST[Rtf_IDEST.PICT] = 'PICT';
Rtf_IDEST[Rtf_IDEST.COLOR] = 'COLOR';
Rtf_IDEST[Rtf_IDEST.SKIP] = 'SKIP';
/** @enum {number} */
const Rtf_IPROP = {
BOLD: 0,
ITALIC: 1,
UNDERLINE: 2,
FONT: 3,
SIZE: 4,
COLOR: 5,
RED: 6,
GREEN: 7,
BLUE: 8,
LEFT_IND: 9,
RIGHT_IND: 10,
FIRST_IND: 11,
COLS: 12,
PGN_X: 13,
PGN_Y: 14,
XA_PAGE: 15,
YA_PAGE: 16,
XA_LEFT: 17,
XA_RIGHT: 18,
YA_TOP: 19,
YA_BOTTOM: 20,
PGN_START: 21,
SBK: 22,
PGN_FORMAT: 23,
FACING_P: 24,
LANDSCAPE: 25,
JUST: 26,
PARD: 27,
PLAIN: 28,
SECTD: 29,
BULLET: 30,
XA_BULLET: 31,
MAX: 32,
};
Rtf_IPROP[Rtf_IPROP.BOLD] = 'BOLD';
Rtf_IPROP[Rtf_IPROP.ITALIC] = 'ITALIC';
Rtf_IPROP[Rtf_IPROP.UNDERLINE] = 'UNDERLINE';
Rtf_IPROP[Rtf_IPROP.FONT] = 'FONT';
Rtf_IPROP[Rtf_IPROP.SIZE] = 'SIZE';
Rtf_IPROP[Rtf_IPROP.COLOR] = 'COLOR';
Rtf_IPROP[Rtf_IPROP.RED] = 'RED';
Rtf_IPROP[Rtf_IPROP.GREEN] = 'GREEN';
Rtf_IPROP[Rtf_IPROP.BLUE] = 'BLUE';
Rtf_IPROP[Rtf_IPROP.LEFT_IND] = 'LEFT_IND';
Rtf_IPROP[Rtf_IPROP.RIGHT_IND] = 'RIGHT_IND';
Rtf_IPROP[Rtf_IPROP.FIRST_IND] = 'FIRST_IND';
Rtf_IPROP[Rtf_IPROP.COLS] = 'COLS';
Rtf_IPROP[Rtf_IPROP.PGN_X] = 'PGN_X';
Rtf_IPROP[Rtf_IPROP.PGN_Y] = 'PGN_Y';
Rtf_IPROP[Rtf_IPROP.XA_PAGE] = 'XA_PAGE';
Rtf_IPROP[Rtf_IPROP.YA_PAGE] = 'YA_PAGE';
Rtf_IPROP[Rtf_IPROP.XA_LEFT] = 'XA_LEFT';
Rtf_IPROP[Rtf_IPROP.XA_RIGHT] = 'XA_RIGHT';
Rtf_IPROP[Rtf_IPROP.YA_TOP] = 'YA_TOP';
Rtf_IPROP[Rtf_IPROP.YA_BOTTOM] = 'YA_BOTTOM';
Rtf_IPROP[Rtf_IPROP.PGN_START] = 'PGN_START';
Rtf_IPROP[Rtf_IPROP.SBK] = 'SBK';
Rtf_IPROP[Rtf_IPROP.PGN_FORMAT] = 'PGN_FORMAT';
Rtf_IPROP[Rtf_IPROP.FACING_P] = 'FACING_P';
Rtf_IPROP[Rtf_IPROP.LANDSCAPE] = 'LANDSCAPE';
Rtf_IPROP[Rtf_IPROP.JUST] = 'JUST';
Rtf_IPROP[Rtf_IPROP.PARD] = 'PARD';
Rtf_IPROP[Rtf_IPROP.PLAIN] = 'PLAIN';
Rtf_IPROP[Rtf_IPROP.SECTD] = 'SECTD';
Rtf_IPROP[Rtf_IPROP.BULLET] = 'BULLET';
Rtf_IPROP[Rtf_IPROP.XA_BULLET] = 'XA_BULLET';
Rtf_IPROP[Rtf_IPROP.MAX] = 'MAX';
/** @enum {number} */
const Rtf_RDS = {
NORM: 0,
COLOR: 1,
SKIP: 2,
NEW: 3,
};
Rtf_RDS[Rtf_RDS.NORM] = 'NORM';
Rtf_RDS[Rtf_RDS.COLOR] = 'COLOR';
Rtf_RDS[Rtf_RDS.SKIP] = 'SKIP';
Rtf_RDS[Rtf_RDS.NEW] = 'NEW';
/** @enum {number} */
const Rtf_ErrorRtf = {
OK: 0,
STACK_UNDERFLOW: 1,
STACK_OVERFLOW: 2,
UNMATCHED_BRACE: 3,
INVALID_HEX: 4,
BAD_TABLE: 5,
ASSERTION: 6,
END_OF_FILE: 7,
BUFFER_TOO_SMALL: 8,
};
Rtf_ErrorRtf[Rtf_ErrorRtf.OK] = 'OK';
Rtf_ErrorRtf[Rtf_ErrorRtf.STACK_UNDERFLOW] = 'STACK_UNDERFLOW';
Rtf_ErrorRtf[Rtf_ErrorRtf.STACK_OVERFLOW] = 'STACK_OVERFLOW';
Rtf_ErrorRtf[Rtf_ErrorRtf.UNMATCHED_BRACE] = 'UNMATCHED_BRACE';
Rtf_ErrorRtf[Rtf_ErrorRtf.INVALID_HEX] = 'INVALID_HEX';
Rtf_ErrorRtf[Rtf_ErrorRtf.BAD_TABLE] = 'BAD_TABLE';
Rtf_ErrorRtf[Rtf_ErrorRtf.ASSERTION] = 'ASSERTION';
Rtf_ErrorRtf[Rtf_ErrorRtf.END_OF_FILE] = 'END_OF_FILE';
Rtf_ErrorRtf[Rtf_ErrorRtf.BUFFER_TOO_SMALL] = 'BUFFER_TOO_SMALL';
class Rtf_RtfChar {
}
Rtf_RtfChar.CR = String.fromCharCode(0x0d);
Rtf_RtfChar.LF = String.fromCharCode(0x0A);
Rtf_RtfChar.TAB = String.fromCharCode(0x09);
Rtf_RtfChar.BULLET = String.fromCharCode(0x95);
Rtf_RtfChar.TILDA = String.fromCharCode(0xA0);
Rtf_RtfChar.DASH = String.fromCharCode(0xAD);
Rtf_RtfChar.DASH_CHAR = '-';
Rtf_RtfChar.QUOTE = '\'';
Rtf_RtfChar.DBLQUOTE = '"';
Rtf_RtfChar.OPENINGBRACE = '{';
Rtf_RtfChar.CLOSINGBRACE = '}';
Rtf_RtfChar.BACKSLASH = '\\';
/** @enum {number} */
const Rtf_RIS = {
NORM: 0,
BIN: 1,
HEX: 2,
UNICODE: 3,
};
Rtf_RIS[Rtf_RIS.NORM] = 'NORM';
Rtf_RIS[Rtf_RIS.BIN] = 'BIN';
Rtf_RIS[Rtf_RIS.HEX] = 'HEX';
Rtf_RIS[Rtf_RIS.UNICODE] = 'UNICODE';
class Rtf {
constructor() {
this._group = 0;
this._cbBin = 0;
this._lParam = 0;
this._skipDestIfUnk = false;
this._outputOnce = false;
this._processCrlfSpecial = false;
this._destState = null;
this._internalState = null;
this._stack = null;
this._index = 0;
this._fontNum = 0;
this._charsetTable = new Hashtable();
this._codePageTable = new Hashtable();
this._stack = new Stack();
this._group = 0;
this._cbBin = 0;
this._lParam = 0;
this._outputOnce = false;
this._skipDestIfUnk = false;
this._processCrlfSpecial = false;
this._destState = Rtf_RDS.NORM;
this._internalState = Rtf_RIS.NORM;
this._fontNum = 0;
if (UtilStrByteMode.isLocaleDefLangDBCS()) {
this.setCodePageTable();
}
}
/**
* @param {?} str
* @return {?}
*/
static isRtf(str) {
/** @type {?} */
let isRtf = false;
if (str !== null && str.startsWith(this.RTF_PREFIX)) {
isRtf = true;
}
return isRtf;
}
/**
* @param {?} rtfTxt
* @param {?} outputTxt
* @return {?}
*/
toTxt(rtfTxt, outputTxt) {
/** @type {?} */
let cNibble = 2;
/** @type {?} */
let b = 0;
/** @type {?} */
let currPos = 0;
/** @type {?} */
let skipNewline = false;
/** @type {?} */
let blobStrLen;
/** @type {?} */
let blobChar;
/** @type {?} */
let ec;
/** @type {?} */
let dbcsBytes = new Uint8Array(2);
/** @type {?} */
let skipParseChar = false;
/** @type {?} */
let charset = 0;
/** @type {?} */
let codePage = 0;
this._outputOnce = false;
this._processCrlfSpecial = false;
blobStrLen = rtfTxt.length;
this._index = 0;
this._destState = Rtf_RDS.NORM;
if (rtfTxt === null || blobStrLen === 0 || !Rtf.isRtf(rtfTxt)) {
return Rtf_ErrorRtf.OK;
}
while (this._index < blobStrLen) {
blobChar = rtfTxt[this._index];
this._index++;
if (this._group < 0)
return Rtf_ErrorRtf.STACK_UNDERFLOW;
/* if we're parsing binary data, handle it directly */
if (this._internalState === Rtf_RIS.BIN) {
if ((ec = this.ParseChar(blobChar, outputTxt)) !== Rtf_ErrorRtf.OK)
return ec;
}
else {
switch (blobChar) {
case Rtf_RtfChar.OPENINGBRACE:
skipNewline = false;
if ((ec = this.PushState()) !== Rtf_ErrorRtf.OK)
return ec;
break;
case Rtf_RtfChar.CLOSINGBRACE:
skipNewline = true;
if ((ec = this.PopState()) !== Rtf_ErrorRtf.OK)
return ec;
break;
case Rtf_RtfChar.BACKSLASH:
skipNewline = false;
if ((ec = this.ParseKeyword(rtfTxt, outputTxt)) !== Rtf_ErrorRtf.OK)
return ec;
break;
case Rtf_RtfChar.LF:
case Rtf_RtfChar.CR:
/* cr and lf are noise characters... */
if (this._processCrlfSpecial) {
/* Once we reach the 0x0a while ProcessCRLFSpecial_, reset the ProcessCRLFSpecial_ */
if (blobChar === Rtf_RtfChar.LF) {
this._processCrlfSpecial = false;
}
}
else {
/*---------------------------------------------------------------*/
/* skip new lines coming only from the RTF header 1/1/98 - #2390 */
/*---------------------------------------------------------------*/
/* Skip the LF (0x0a) if we are not in the ProcessCRLFSpecial_ */
if (blobChar === Rtf_RtfChar.LF || (blobChar === Rtf_RtfChar.CR && skipNewline && !this._outputOnce))
break;
}
/* falls through */
default:
if (blobChar !== Rtf_RtfChar.CR)
skipNewline = false;
if (this._internalState === Rtf_RIS.NORM) {
if ((ec = this.ParseChar(blobChar, outputTxt)) !== Rtf_ErrorRtf.OK)
return ec;
}
else if (this._internalState === Rtf_RIS.UNICODE) {
if ((ec = this.ParseChar(String.fromCharCode(this._lParam), outputTxt)) !== Rtf_ErrorRtf.OK)
return ec;
this._internalState = Rtf_RIS.NORM;
}
else {
/* parsing hex data */
if (this._internalState !== Rtf_RIS.HEX)
return Rtf_ErrorRtf.ASSERTION;
b = b << 4;
if (NChar.IsDigit(blobChar))
b += blobChar.charCodeAt(0) - '0'.charCodeAt(0);
else {
if (NChar.IsLower(blobChar)) {
if (blobChar < 'a' || blobChar > 'f')
return Rtf_ErrorRtf.INVALID_HEX;
b += 10 + blobChar.charCodeAt(0) - 'a'.charCodeAt(0);
}
else {
if (blobChar < 'A' || blobChar > 'F')
return Rtf_ErrorRtf.INVALID_HEX;
b += 10 + blobChar.charCodeAt(0) - 'A'.charCodeAt(0);
}
}
cNibble--;
if (cNibble === 0) {
if (UtilStrByteMode.isLocaleDefLangDBCS()) {
charset = this.getCharset(this._fontNum);
// leading byte of a double-byte character
if (!skipParseChar && Rtf.is1stByte(b, charset)) {
dbcsBytes[0] = b;
dbcsBytes[1] = 0;
skipParseChar = true;
}
else {
// trailing byte of a double-byte character
if (skipParseChar && Rtf.is2ndByte(b, charset))
dbcsBytes[1] = b;
else {
dbcsBytes[0] = b;
dbcsBytes[1] = 0;
}
// convert DBCS to Unicode
codePage = this.getCodePage(charset);
/** @type {?} */
let workStr = Encoding.GetEncoding(codePage).GetString(dbcsBytes, 0, 2);
b = workStr.charCodeAt(0);
skipParseChar = false;
}
}
if (!skipParseChar) {
if ((ec = this.ParseChar(String.fromCharCode(b), outputTxt)) !== Rtf_ErrorRtf.OK)
return ec;
}
cNibble = 2;
b = 0;
this._internalState = Rtf_RIS.NORM;
}
}
/* end else (ris != risNorm) */
break;
}
/* switch */
}
/* else (ris != risBin) */
}
/* while */
if (this._group < 0)
return Rtf_ErrorRtf.STACK_UNDERFLOW;
if (this._group > 0)
return Rtf_ErrorRtf.UNMATCHED_BRACE;
/*-------------------------------------------------------------------*/
/* Eliminate suffix of carrige return + line feed */
/* (Check last characters - just in case format is not the expected) */
/*-------------------------------------------------------------------*/
currPos = outputTxt.Length;
if (currPos >= 3 && (outputTxt.get_Item(currPos - 3) === Rtf_RtfChar.CR && outputTxt.get_Item(currPos - 2) === Rtf_RtfChar.LF && outputTxt.get_Item(currPos - 1) === Rtf_RtfChar.CR || outputTxt.get_Item(currPos - 3) === Rtf_RtfChar.LF && outputTxt.get_Item(currPos - 2) === Rtf_RtfChar.CR && outputTxt.get_Item(currPos - 1) === Rtf_RtfChar.CR))
outputTxt.Remove(currPos - 3, 3);
return Rtf_ErrorRtf.OK;
}
/**
* @param {?} ch
* @param {?} outputTxt
* @return {?}
*/
ParseChar(ch, outputTxt) {
/** @type {?} */
let ret = Rtf_ErrorRtf.OK;
if (this._internalState === Rtf_RIS.BIN && --this._cbBin <= 0) {
this._internalState = Rtf_RIS.NORM;
}
if (this._destState === Rtf_RDS.SKIP) ;
else if (this._destState === Rtf_RDS.NORM) {
/* Output a character. Properties are valid at this point. */
ret = this.PrintChar(ch, outputTxt);
}
return ret;
}
/**
* @param {?} ch
* @param {?} outputTxt
* @return {?}
*/
PrintChar(ch, outputTxt) {
/* Allow carrige return + line feed in text, but remove bullet sign */
/*------------------------------------------------------------------*/
if ((ch >= ' ' || ch === Rtf_RtfChar.CR || ch === Rtf_RtfChar.LF) && ch !== String.fromCharCode(183)) {
outputTxt.Append(ch);
}
if (ch >= ' ') {
this._outputOnce = true;
}
return Rtf_ErrorRtf.OK;
}
/**
* @return {?}
*/
PushState() {
/** @type {?} */
let stackSave = new Rtf_StackSave();
if (stackSave === null) {
return Rtf_ErrorRtf.STACK_OVERFLOW;
}
stackSave.rds = this._destState;
stackSave.ris = this._internalState;
this._internalState = Rtf_RIS.NORM;
this._stack.push(stackSave);
this._group++;
return Rtf_ErrorRtf.OK;
}
/**
* @return {?}
*/
PopState() {
/** @type {?} */
let savedPop = this._stack.pop();
if (savedPop === null) {
return Rtf_ErrorRtf.STACK_UNDERFLOW;
}
this._destState = savedPop.rds;
this._internalState = savedPop.ris;
this._group--;
return Rtf_ErrorRtf.OK;
}
/**
* @param {?} rtfTxt
* @param {?} outputTxt
* @return {?}
*/
ParseKeyword(rtfTxt, outputTxt) {
/** @type {?} */
let ch;
/** @type {?} */
let fNeg = false;
/** @type {?} */
let szKeyword = "";
/** @type {?} */
let szParameter = "";
if ((ch = rtfTxt[this._index++]) === String.fromCharCode(0)) {
return Rtf_ErrorRtf.END_OF_FILE;
}
/* a control symbol; no delimiter. */
if (!NChar.IsLetter(ch)) {
szKeyword = szKeyword + ch;
return this.TranslateKeyword(szKeyword, outputTxt);
}
for (; NChar.IsLetter(ch); ch = rtfTxt[this._index++])
szKeyword = szKeyword + ch;
if (ch === '-') {
fNeg = true;
if ((ch = rtfTxt[this._index++]) === String.fromCharCode(0))
return Rtf_ErrorRtf.END_OF_FILE;
}
if (NChar.IsDigit(ch)) {
for (; NChar.IsDigit(ch); ch = rtfTxt[this._index++])
szParameter = szParameter + ch;
this._lParam = NNumber.Parse(szParameter);
if (fNeg)
this._lParam = -this._lParam;
}
if (ch !== ' ')
this._index--;
if (szKeyword === Rtf.CHAR_PAR) {
/* if we get a RTF sequence of \par[0xd][0xa], ie a \par kwd followed */
/* immidiately by the CR and LF, then ignore the \par kwd. otherwise */
/* we will translate the \par - which translates to a LF (0xa) and also */
/* the following 0x0d is translated to 0x0a, thus resulting in TWO LF's */
/* being inserted instead of just one LF. So by skipping [\par] and */
/* translating only the [0xd 0xa] will result in only one LF appearing */
/* - which is the desired behaviour */
if (rtfTxt[this._index] === Rtf_RtfChar.CR && rtfTxt[this._index + 1] === Rtf_RtfChar.LF)
this._processCrlfSpecial = true;
}
if (this._processCrlfSpecial) {
return Rtf_ErrorRtf.OK;
}
else {
return this.TranslateKeyword(szKeyword, outputTxt);
}
}
/**
* @param {?} szKeyword
* @param {?} outputTxt
* @return {?}
*/
TranslateKeyword(szKeyword, outputTxt) {
/** @type {?} */
let result = Rtf_ErrorRtf.OK;
/** @type {?} */
let isym;
/* search for szKeyword in rgsymRtf */
for (isym = 0; isym < Rtf.rgsymRtf.length; isym++) {
if (szKeyword === Rtf.rgsymRtf[isym].szKeyword) {
break;
}
}
/* control word not found */
if (isym === Rtf.rgsymRtf.length) {
if (this._skipDestIfUnk) {
/* if this is a new destination */
this._destState = Rtf_RDS.SKIP;
/* skip the destination */
}
/* else just discard it */
this._skipDestIfUnk = false;
}
else {
result = Rtf_ErrorRtf.BAD_TABLE;
/* found it! use kwd and idxInRgprop to determine what to do with it. */
this._skipDestIfUnk = false;
if (Rtf.rgsymRtf[isym].kwd === Rtf_KWD.PROP) {
result = this.validateProp(/** @type {?} */ (Rtf.rgsymRtf[isym].idxInRgprop));
}
else if (Rtf.rgsymRtf[isym].kwd === Rtf_KWD.CHAR) {
result = this.ParseChar((Rtf.rgsymRtf[isym].idxInRgprop), outputTxt);
}
else if (Rtf.rgsymRtf[isym].kwd === Rtf_KWD.DEST) {
result = this.changeDestState();
}
else if (Rtf.rgsymRtf[isym].kwd === Rtf_KWD.SPEC) {
result = this.ParseSpecialKeyword(/** @type {?} */ (Rtf.rgsymRtf[isym].idxInRgprop));
}
}
return result;
}
/**
* @param {?} iprop
* @return {?}
*/
validateProp(iprop) {
/** @type {?} */
let ret = Rtf_ErrorRtf.OK;
if (this._destState === Rtf_RDS.SKIP) {
/* If we're skipping text, */
return ret;
/* don't do anything. */
}
/* validate prop */
if (Rtf.rgprop[iprop].prop !== Rtf_PROPTYPE.DOP && Rtf.rgprop[iprop].prop !== Rtf_PROPTYPE.SEP &&
Rtf.rgprop[iprop].prop !== Rtf_PROPTYPE.PAP && Rtf.rgprop[iprop].prop !== Rtf_PROPTYPE.CHP &&
Rtf.rgprop[iprop].actn !== Rtf_ACTN.SPEC) {
ret = Rtf_ErrorRtf.BAD_TABLE;
}
if (Rtf.rgprop[iprop].actn !== Rtf_ACTN.BYTE && Rtf.rgprop[iprop].actn !== Rtf_ACTN.WORD && Rtf.rgprop[iprop].actn !== Rtf_ACTN.SPEC) {
ret = Rtf_ErrorRtf.BAD_TABLE;
}
return ret;
}
/**
* @return {?}
*/
changeDestState() {
if (this._destState === Rtf_RDS.SKIP) {
/* if we're skipping text, */
return Rtf_ErrorRtf.OK;
/* don't do anything */
}
this._destState = Rtf_RDS.SKIP;
/* when in doubt, skip it... */
return Rtf_ErrorRtf.OK;
}
/**
* @param {?} ipfn
* @return {?}
*/
ParseSpecialKeyword(ipfn) {
/** @type {?} */
let ret = Rtf_ErrorRtf.OK;
if (!UtilStrByteMode.isLocaleDefLangDBCS()) {
if (this._destState === Rtf_RDS.SKIP && ipfn !== Rtf_IPFN.BIN) {
/* if we're skipping, and it's not */
return ret;
/* the \bin keyword, ignore it. */
}
if (ipfn === Rtf_IPFN.FONT || ipfn === Rtf_IPFN.CHARSET || ipfn === Rtf_IPFN.UNICODE) {
return ret;
}
}
else {
if (this._destState === Rtf_RDS.SKIP && ipfn !== Rtf_IPFN.BIN && ipfn !== Rtf_IPFN.FONT &&
ipfn !== Rtf_IPFN.CHARSET && ipfn !== Rtf_IPFN.UNICODE) {
return ret;
}
}
if (ipfn === Rtf_IPFN.BIN) {
this._internalState = Rtf_RIS.BIN;
this._cbBin = this._lParam;
}
else if (ipfn === Rtf_IPFN.SKIP_DEST) {
this._skipDestIfUnk = true;
}
else if (ipfn === Rtf_IPFN.HEX) {
this._internalState = Rtf_RIS.HEX;
}
else if (ipfn === Rtf_IPFN.FONT) {
this._fontNum = /** @type {?} */ (this._lParam);
}
else if (ipfn === Rtf_IPFN.CHARSET) {
this._charsetTable.set_Item(this._fontNum, /** @type {?} */ (this._lParam));
}
else if (ipfn === Rtf_IPFN.UNICODE) {
this._internalState = Rtf_RIS.UNICODE;
}
else {
ret = Rtf_ErrorRtf.BAD_TABLE;
}
return ret;
}
/**
* @param {?} dbcsBytes
* @param {?} charset
* @return {?}
*/
static is1stByte(dbcsBytes, charset) {
/** @type {?} */
let ret = false;
if (dbcsBytes > 255)
return ret;
switch (charset) {
case 128:
ret = (129 <= dbcsBytes && dbcsBytes <= 159) || (224 <= dbcsBytes && dbcsBytes <= 254);
break;
case 129:
case 134:
case 136:
ret = (129 <= dbcsBytes);
break;
default:
break;
}
return ret;
}
/**
* @param {?} dbcsBytes
* @param {?} charset
* @return {?}
*/
static is2ndByte(dbcsBytes, charset) {
/** @type {?} */
let ret = false;
if (dbcsBytes > 255)
return ret;
switch (charset) {
case 128:
ret = (dbcsBytes !== 127) && (64 <= dbcsBytes && dbcsBytes <= 252);
break;
case 129:
case 134:
case 136:
ret = (64 <= dbcsBytes);
break;
default:
break;
}
return ret;
}
/**
* @return {?}
*/
setCodePageTable() {
// add elements with key (charset) and value (codepage) into the table.
this._codePageTable.set_Item(0, 1252); // ANSI_CHARSET
this._codePageTable.set_Item(128, 932); // SHIFTJIS_CHARSET
this._codePageTable.set_Item(129, 949); // HANGUL_CHARSET
this._codePageTable.set_Item(134, 936); // GB2312_CHARSET
this._codePageTable.set_Item(136, 950); // CHINESEBIG5_CHARSET
this._codePageTable.set_Item(161, 1253); // GREEK_CHARSET
this._codePageTable.set_Item(162, 1254); // TURKISH_CHARSET
this._codePageTable.set_Item(177, 1255); // HEBREW_CHARSET
this._codePageTable.set_Item(178, 1256); // ARABIC _CHARSET
this._codePageTable.set_Item(186, 1257); // BALTIC_CHARSET
this._codePageTable.set_Item(204, 1251); // RUSSIAN_CHARSET
this._codePageTable.set_Item(222, 874); // THAI_CHARSET
this._codePageTable.set_Item(238, 1250); // EASTEUROPE_CHARSET
}
/**
* @param {?} charset
* @return {?}
*/
getCodePage(charset) {
/** @type {?} */
let codePage = 0;
if (this._codePageTable.ContainsKey(charset)) {
codePage = this._codePageTable.get_Item(charset);
}
return codePage;
}
/**
* @param {?} font
* @return {?}
*/
getCharset(font) {
/** @type {?} */
let charset = 0;
if (this._charsetTable.ContainsKey(font)) {
charset = this._charsetTable.get_Item(font);
}
return charset;
}
}
Rtf.RTF_PREFIX = "{\\rtf";
Rtf.CHAR_PAR = "par";
Rtf.rgprop = [
new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.CHP), new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.CHP),
new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.CHP), new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.CHP),
new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.CHP), new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.CHP),
new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.CHP), new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.CHP),
new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.CHP), new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.PAP),
new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.PAP), new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.PAP),
new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.SEP), new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.SEP),
new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.SEP), new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.DOP),
new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.DOP), new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.DOP),
new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.DOP), new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.DOP),
new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.DOP), new Rtf_PROP(Rtf_ACTN.WORD, Rtf_PROPTYPE.DOP),
new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.SEP), new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.SEP),
new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.DOP), new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.DOP),
new Rtf_PROP(Rtf_ACTN.BYTE, Rtf_PROPTYPE.PAP), new Rtf_PROP(Rtf_ACTN.SPEC, Rtf_PROPTYPE.PAP),
new Rtf_PROP(Rtf_ACTN.SPEC, Rtf_PROPTYPE.CHP), new Rtf_PROP(Rtf_ACTN.SPEC, Rtf_PROPTYPE.SEP)
];
Rtf.rgsymRtf = [
new Rtf_SYMBOL("b", Rtf_KWD.PROP, Rtf_IPROP.BOLD), new Rtf_SYMBOL("ul", Rtf_KWD.PROP, Rtf_IPROP.UNDERLINE),
new Rtf_SYMBOL("i", Rtf_KWD.PROP, Rtf_IPROP.ITALIC), new Rtf_SYMBOL("li", Rtf_KWD.PROP, Rtf_IPROP.LEFT_IND),
new Rtf_SYMBOL("ri", Rtf_KWD.PROP, Rtf_IPROP.RIGHT_IND), new Rtf_SYMBOL("fi", Rtf_KWD.PROP, Rtf_IPROP.FIRST_IND),
new Rtf_SYMBOL("cols", Rtf_KWD.PROP, Rtf_IPROP.COLS), new Rtf_SYMBOL("sbknone", Rtf_KWD.PROP, Rtf_IPROP.SBK),
new Rtf_SYMBOL("sbkcol", Rtf_KWD.PROP, Rtf_IPROP.SBK), new Rtf_SYMBOL("sbkeven", Rtf_KWD.PROP, Rtf_IPROP.SBK),
new Rtf_SYMBOL("sbkodd", Rtf_KWD.PROP, Rtf_IPROP.SBK), new Rtf_SYMBOL("sbkpage", Rtf_KWD.PROP, Rtf_IPROP.SBK),
new Rtf_SYMBOL("pgnx", Rtf_KWD.PROP, Rtf_IPROP.PGN_X), new Rtf_SYMBOL("pgny", Rtf_KWD.PROP, Rtf_IPROP.PGN_Y),
new Rtf_SYMBOL("pgndec", Rtf_KWD.PROP, Rtf_IPROP.PGN_FORMAT), new Rtf_SYMBOL("pgnucrm", Rtf_KWD.PROP, Rtf_IPROP.PGN_FORMAT),
new Rtf_SYMBOL("pgnlcrm", Rtf_KWD.PROP, Rtf_IPROP.PGN_FORMAT), new Rtf_SYMBOL("pgnucltr", Rtf_KWD.PROP, Rtf_IPROP.PGN_FORMAT),
new Rtf_SYMBOL("pgnlcltr", Rtf_KWD.PROP, Rtf_IPROP.PGN_FORMAT), new Rtf_SYMBOL("qc", Rtf_KWD.PROP, Rtf_IPROP.JUST),
new Rtf_SYMBOL("ql", Rtf_KWD.PROP, Rtf_IPROP.JUST), new Rtf_SYMBOL("qr", Rtf_KWD.PROP, Rtf_IPROP.JUST),
new Rtf_SYMBOL("qj", Rtf_KWD.PROP, Rtf_IPROP.JUST), new Rtf_SYMBOL("paperw", Rtf_KWD.PROP, Rtf_IPROP.XA_PAGE),
new Rtf_SYMBOL("paperh", Rtf_KWD.PROP, Rtf_IPROP.YA_PAGE), new Rtf_SYMBOL("margl", Rtf_KWD.PROP, Rtf_IPROP.XA_LEFT),
new Rtf_SYMBOL("margr", Rtf_KWD.PROP, Rtf_IPROP.XA_RIGHT), new Rtf_SYMBOL("margt", Rtf_KWD.PROP, Rtf_IPROP.YA_TOP),
new Rtf_SYMBOL("margb", Rtf_KWD.PROP, Rtf_IPROP.YA_BOTTOM), new Rtf_SYMBOL("pgnstart", Rtf_KWD.PROP, Rtf_IPROP.PGN_START),
new Rtf_SYMBOL("facingp", Rtf_KWD.PROP, Rtf_IPROP.FACING_P), new Rtf_SYMBOL("landscape", Rtf_KWD.PROP, Rtf_IPROP.LANDSCAPE),
new Rtf_SYMBOL("par", Rtf_KWD.CHAR, Rtf_RtfChar.LF), new Rtf_SYMBOL("\0x0a", Rtf_KWD.CHAR, Rtf_RtfChar.LF),
new Rtf_SYMBOL("\0x0d", Rtf_KWD.CHAR, Rtf_RtfChar.LF), new Rtf_SYMBOL("tab", Rtf_KWD.CHAR, Rtf_RtfChar.TAB),
new Rtf_SYMBOL("ldblquote", Rtf_KWD.CHAR, Rtf_RtfChar.DBLQUOTE), new Rtf_SYMBOL("rdblquote", Rtf_KWD.CHAR, Rtf_RtfChar.DBLQUOTE),
new Rtf_SYMBOL("lquote", Rtf_KWD.CHAR, Rtf_RtfChar.QUOTE), new Rtf_SYMBOL("rquote", Rtf_KWD.CHAR, Rtf_RtfChar.QUOTE),
new Rtf_SYMBOL("bullet", Rtf_KWD.CHAR, Rtf_RtfChar.BULLET), new Rtf_SYMBOL("endash", Rtf_KWD.CHAR, Rtf_RtfChar.DASH_CHAR),
new Rtf_SYMBOL("emdash", Rtf_KWD.CHAR, Rtf_RtfChar.DASH_CHAR), new Rtf_SYMBOL("~", Rtf_KWD.CHAR, Rtf_RtfChar.TILDA),
new Rtf_SYMBOL("-", Rtf_KWD.CHAR, Rtf_RtfChar.DASH), new Rtf_SYMBOL("{", Rtf_KWD.CHAR, Rtf_RtfChar.OPENINGBRACE),
new Rtf_SYMBOL("}", Rtf_KWD.CHAR, Rtf_RtfChar.CLOSINGBRACE), new Rtf_SYMBOL("\\", Rtf_KWD.CHAR, Rtf_RtfChar.BACKSLASH),
new Rtf_SYMBOL("bin", Rtf_KWD.SPEC, Rtf_IPFN.BIN), new Rtf_SYMBOL("*", Rtf_KWD.SPEC, Rtf_IPFN.SKIP_DEST),
new Rtf_SYMBOL("'", Rtf_KWD.SPEC, Rtf_IPFN.HEX), new Rtf_SYMBOL("f", Rtf_KWD.SPEC, Rtf_IPFN.FONT),
new Rtf_SYMBOL("fcharset", Rtf_KWD.SPEC, Rtf_IPFN.CHARSET), new Rtf_SYMBOL("u", Rtf_KWD.SPEC, Rtf_IPFN.UNICODE),
new Rtf_SYMBOL("author", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("buptim", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("colortbl", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("comment", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("creatim", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("doccomm", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("fonttbl", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("footer", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("footerf", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("footerl", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("footerr", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("footnote", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("ftncn", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("ftnsep", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("ftnsepc", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("header", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("headerf", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("headerl", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("headerr", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("info", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("keywords", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("operator", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("pict", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("printim", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("private1", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("revtim", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("rxe", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("stylesheet", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("subject", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("tc", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("title", Rtf_KWD.DEST, Rtf_IDEST.SKIP), new Rtf_SYMBOL("txe", Rtf_KWD.DEST, Rtf_IDEST.SKIP),
new Rtf_SYMBOL("xe", Rtf_KWD.DEST, Rtf_IDEST.SKIP)
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
const HTML_BACKSLASH = "\";
/** @type {?} */
const HTML_COMMA = ",";
/** @type {?} */
const HTML_HYPHEN = "-";
/** @type {?} */
const STR_2_HTML = 1;
/** @type {?} */
const SEQ_2_HTML = 2;
/** @type {?} */
const HTML_2_STR = 3;
/** @type {?} */
const HTML_2_SEQ = 4;
/** @type {?} */
const SEQ_2_STR = 5;
class StrUtil {
/**
* @param {?} str
* @param {?} len
* @return {?}
*/
static mem_trim(str, len) {
/** @type {?} */
let result;
if (len > 0) {
if (len > str.length) {
result = -1;
return result;
}
while (len > 0 && str[len - 1] === ' ') {
len = len - 1;
}
}
result = len;
return result;
}
/**
* @param {?} dest
* @param {?} destCount
* @param {?} src
* @param {?} srcCount
* @param {?} len
* @return {?}
*/
static memmove(dest, destCount, src, srcCount, len) {
/** @type {?} */
let stringBuilder = new StringBuilder(dest.length + len);
if (UtilStrByteMode.isLocaleDefLangJPN() && dest.length < destCount) {
stringBuilder.Append(NString.FromChar(' ', destCount));
}
else {
stringBuilder.Append(dest.substr(0, destCount));
}
stringBuilder.Append(src.substr(srcCount, len));