import CharacterSetECI from '../common/CharacterSetECI' ; import { int , char } from '../../customTypings' ; import StringUtils from '../common/StringUtils' ; export default class StringBuilder { private encoding : CharacterSetECI ; public constructor ( private value = '' ) { } public enableDecoding ( encoding ) { this . encoding = encoding ; return this ; } public append ( s ) { if ( typeof s === 'string' ) { this . value += s . toString ( ) ; } else if ( this . encoding ) { this . value += StringUtils . castAsNonUtf8Char ( s , this . encoding ) ; } else { this . value += String . fromCharCode ( s ) ; } return this ; } public appendChars ( str , offset , len ) { for ( let i = offset ; offset < offset + len ; i ++ ) { this . append ( str [ i ] ) ; } return this ; } public length ( ) { return this . value . length ; } public charAt ( n ) { return this . value . charAt ( n ) ; } public deleteCharAt ( n ) { this . value = this . value . substr ( 0 , n ) + this . value . substring ( n + 1 ) ; } public setCharAt ( n , c ) { this . value = this . value . substr ( 0 , n ) + c + this . value . substr ( n + 1 ) ; } public substring ( start , end ) { return this . value . substring ( start , end ) ; } note public setLengthToZero ( ) { this . value = '' ; } public toString ( ) { return this . value ; } public insert ( n , c ) { this . value = this . value . substr ( 0 , n ) + c + this . value . substr ( n + c . length ) ; } }