You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					36 lines
				
				632 B
			
		
		
			
		
	
	
					36 lines
				
				632 B
			| 
								 
											3 years ago
										 
									 | 
							
								// StringBuilder - a way to keep string memory operations to a minimum
							 | 
						||
| 
								 | 
							
								// while building the strings for the xml files
							 | 
						||
| 
								 | 
							
								class StringBuilder {
							 | 
						||
| 
								 | 
							
								  constructor() {
							 | 
						||
| 
								 | 
							
								    this.reset();
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  get length() {
							 | 
						||
| 
								 | 
							
								    return this._buf.length;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  toString() {
							 | 
						||
| 
								 | 
							
								    return this._buf.join('');
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  reset(position) {
							 | 
						||
| 
								 | 
							
								    if (position) {
							 | 
						||
| 
								 | 
							
								      while (this._buf.length > position) {
							 | 
						||
| 
								 | 
							
								        this._buf.pop();
							 | 
						||
| 
								 | 
							
								      }
							 | 
						||
| 
								 | 
							
								    } else {
							 | 
						||
| 
								 | 
							
								      this._buf = [];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  addText(text) {
							 | 
						||
| 
								 | 
							
								    this._buf.push(text);
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  addStringBuf(inBuf) {
							 | 
						||
| 
								 | 
							
								    this._buf.push(inBuf.toString());
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module.exports = StringBuilder;
							 |