wzp
2021-07-19 e65183d31755a0e5fae4bf428435d2e0fd6afdc5
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
 * @Date March 17, 2014
 */
 
/**
 * String startWith.
 *
 * @param string
 * @returns {boolean}
 */
String.prototype.startWith = function (string) {
    if (string == null || string == "" || this.length == 0 || string.length > this.length) {
        return false;
    } else {
        return this.substr(0, string.length) == string;
    }
};
 
/**
 * String endWith.
 *
 * @param string
 * @returns {boolean}
 */
String.prototype.endWith = function (string) {
    if (string == null || string == "" || this.length == 0 || string.length > this.length) {
        return false;
    } else {
        return this.substring(this.length - string.length) == string;
    }
};
 
/**
 * String replaceAll.
 *
 * @param string1
 * @param string2
 * @returns {string}
 */
String.prototype.replaceAll = function (string1, string2) {
    return this.replace(new RegExp(string1, "gm"), string2);
};
 
function StringBuilder() {
    if (arguments.length) {
        this.append.apply(this, arguments);
    }
}
/**
 * StringBuilder.
 * Property: length
 * Method: append,appendFormat,size,toString,valueOf
 *
 * From: http://webreflection.blogspot.com/2008/06/lazy-developers-stack-concept-and.html
 * (C) Andrea Giammarchi - Mit Style License
 * @type {StringBuilder.prototype}
 */
StringBuilder.prototype = function () {
    var join = Array.prototype.join, slice = Array.prototype.slice, RegExp = /\{(\d+)\}/g, toString = function () {
        return join.call(this, "");
    };
    return {
        constructor: StringBuilder,
        length: 0,
        append: Array.prototype.push,
        appendFormat: function (String) {
            var i = 0, args = slice.call(arguments, 1);
            this.append(RegExp.test(String) ? String.replace(RegExp, function (String, i) {
                return args[i];
            }) : String.replace(/\?/g, function () {
                return args[i++];
            }));
            return this;
        },
        size: function () {
            return this.toString().length;
        },
        toString: toString,
        valueOf: toString
    };
}();