##// END OF EJS Templates
Working on text writer
Working on text writer

File last commit:

r79:51649f0f8acd default
r81:2ac7406b138e default
Show More
FormatScanner.ts
48 lines | 1020 B | video/mp2t | TypeScriptLexer
/ src / main / ts / text / FormatScanner.ts
import { argumentNotEmptyString } from "../safe";
import { MapOf } from "../interfaces";
export const enum TokeType {
CurlOpen,
CurlClose,
Colon,
Text
}
const typeMap = {
"{": TokeType.CurlOpen,
"}": TokeType.CurlClose,
":": TokeType.Colon
} as MapOf<TokeType>;
export class FormatScanner {
private _text: string;
private _pos: number;
private _tokenType: TokeType;
private _tokenValue: string;
private _rx = /[^{}:]+|(.)/g;
constructor(text: string) {
argumentNotEmptyString(text, text);
this._text = text;
}
next() {
if (this._rx.lastIndex >= this._text.length)
return false;
this._pos = this._rx.lastIndex;
const match = this._rx.exec(this._text);
this._tokenType = typeMap[match[1]] || TokeType.Text;
this._tokenValue = match[0];
return true;
}
getTokenValue() {
return this._tokenValue;
}
getTokenType() {
return this._tokenType;
}
}