-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathStringBuilder.js
More file actions
66 lines (55 loc) · 1.74 KB
/
StringBuilder.js
File metadata and controls
66 lines (55 loc) · 1.74 KB
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
define ([
'require'
], function(requirejs) {
"use strict";
/**
* @class StringBuilder
* @constructor
*/
var StringBuilder = function() {
this.buffer = new Array();
};
// 문자열 추가.
StringBuilder.prototype.append = function(str) {
this.buffer[this.buffer.length] = str;
}
// 문자열 추가하고 줄바꿈.
StringBuilder.prototype.appendLine = function(str) {
this.append((str == null ? "" : str) + "\n");
}
// 문자열 포멧형 추가.
StringBuilder.prototype.appendFormat = function() {
var cnt = arguments.length;
if (cnt < 2)
return "";
var str = arguments[0];
for (var idx = 1; idx < cnt; idx++)
str = str.replace("{" + (idx - 1) + "}", arguments[idx]);
this.buffer[this.buffer.length] = str;
}
// 문자열 포멧형 추가하고 줄바꿈.
StringBuilder.prototype.appendFormatLine = function() {
var cnt = arguments.length;
if (cnt < 2)
return "";
var str = arguments[0];
for (var idx = 1; idx < cnt; idx++)
str = str.replace("{" + (idx - 1) + "}", arguments[idx]);
this.buffer[this.buffer.length] = str + "\n";
}
// 문자열 변환.
StringBuilder.prototype.replace = function(from, to) {
for (var i = this.buffer.length - 1; i >= 0; i--)
this.buffer[i] = this.buffer[i].replace(new RegExp(from, "g"), to);
}
// 문자열 반환.
StringBuilder.prototype.toString = function() {
return this.buffer.join("");
}
StringBuilder.prototype.clear = function() {
this.buffer = new Array();
}
return {
StringBuilder: StringBuilder
};
});