Houjie
2025-07-24 52a3ff1bce1417b39f6872d8e8cb378e9c2ccc6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import StringUtils from '../common/StringUtils';
export default class StringBuilder {
    constructor(value = '') {
        this.value = value;
    }
    enableDecoding(encoding) {
        this.encoding = encoding;
        return this;
    }
    append(s) {
        if (typeof s === 'string') {
            this.value += s.toString();
        }
        else if (this.encoding) {
            // use passed format (fromCharCode will return UTF8 encoding)
            this.value += StringUtils.castAsNonUtf8Char(s, this.encoding);
        }
        else {
            // correctly converts from UTF-8, but not other encodings
            this.value += String.fromCharCode(s);
        }
        return this;
    }
    appendChars(str, offset, len) {
        for (let i = offset; offset < offset + len; i++) {
            this.append(str[i]);
        }
        return this;
    }
    length() {
        return this.value.length;
    }
    charAt(n) {
        return this.value.charAt(n);
    }
    deleteCharAt(n) {
        this.value = this.value.substr(0, n) + this.value.substring(n + 1);
    }
    setCharAt(n, c) {
        this.value = this.value.substr(0, n) + c + this.value.substr(n + 1);
    }
    substring(start, end) {
        return this.value.substring(start, end);
    }
    /**
     * @note helper method for RSS Expanded
     */
    setLengthToZero() {
        this.value = '';
    }
    toString() {
        return this.value;
    }
    insert(n, c) {
        this.value = this.value.substring(0, n) + c + this.value.substring(n);
    }
}