string-builder.js 597 B

1234567891011121314151617181920212223242526272829303132333435
  1. // StringBuilder - a way to keep string memory operations to a minimum
  2. // while building the strings for the xml files
  3. class StringBuilder {
  4. constructor() {
  5. this.reset();
  6. }
  7. get length() {
  8. return this._buf.length;
  9. }
  10. toString() {
  11. return this._buf.join('');
  12. }
  13. reset(position) {
  14. if (position) {
  15. while (this._buf.length > position) {
  16. this._buf.pop();
  17. }
  18. } else {
  19. this._buf = [];
  20. }
  21. }
  22. addText(text) {
  23. this._buf.push(text);
  24. }
  25. addStringBuf(inBuf) {
  26. this._buf.push(inBuf.toString());
  27. }
  28. }
  29. module.exports = StringBuilder;