import { CommandInterface } from '../Commands' ; import { Variables } from './Variables' ; import { Variable } from './Variable' ; export class String extends Variable { private static readonly STR_TYPE = 'string' ; private static readonly ESC_STR_TYPE = 'sq_string' ; private _typename : string ; private _children : Array < Variable > ; constructor ( name = '' , value = '' , type = String . STR_TYPE ) { super ( ) ; this . _name = name ; this . _value = value ; this . _typename = type ; if ( this . _value . length > 1 ) { this . _numberOfChildren = this . _value . length ; Variables . addReferenceTo ( this ) ; } else { this . _numberOfChildren = 0 ; } } public typename ( ) { return this . _typename ; } public loads ( type ) { return type === String . STR_TYPE || type === String . ESC_STR_TYPE ; } public extendedTypename ( ) { return this . typename ( ) ; } public createConcreteType ( name , value , type ) { return new String ( name , value , type ) ; } public loadNew ( name , type , runtime , callback ) { Variables . getValue ( name , runtime , ( value ) => { const v = this . createConcreteType ( name , value , type ) ; callback ( v ) ; } ) ; } public listChildren ( runtime , count , start , callback ) { if ( this . _children === undefined ) { this . _children = new Array < Variable > ( ) ; const values = this . _value . split ( '' ) ; const name = this . name ( ) ; const type = this . _typename ; for ( let i = 0 ; i != values . length ; ++ i ) { const v = this . createConcreteType ( `${ name }(${ i })` , values [ i ] , type ) ; this . _children . push ( v ) ; } } callback ( this . _children . slice ( start , start + count ) ) ; } }