string-builder.js 649 B

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