Skip to content

Commit fa8be8c

Browse files
authored
Merge pull request #1 from MADE-Apps/feature/string-builder
Added StringBuilder class and tests
2 parents 482081a + 7e7078e commit fa8be8c

File tree

11 files changed

+303
-7
lines changed

11 files changed

+303
-7
lines changed

.github/workflows/made-collections.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: npm install
5151

5252
- name: Update Version
53-
run: npm version $BUILD_VERSION
53+
run: npm version $BUILD_VERSION --no-git-tag-version --allow-same-version
5454

5555
- name: Build
5656
run: npm run build

.github/workflows/made-data-converters.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: npm install
5151

5252
- name: Update Version
53-
run: npm version $BUILD_VERSION
53+
run: npm version $BUILD_VERSION --no-git-tag-version --allow-same-version
5454

5555
- name: Build
5656
run: npm run build

.github/workflows/made-data-validation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: npm install
5151

5252
- name: Update Version
53-
run: npm version $BUILD_VERSION
53+
run: npm version $BUILD_VERSION --no-git-tag-version --allow-same-version
5454

5555
- name: Build
5656
run: npm run build

.github/workflows/made-diagnostics.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: npm install
5151

5252
- name: Update Version
53-
run: npm version $BUILD_VERSION
53+
run: npm version $BUILD_VERSION --no-git-tag-version --allow-same-version
5454

5555
- name: Build
5656
run: npm run build

.github/workflows/made-networking.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: npm install
5151

5252
- name: Update Version
53-
run: npm version $BUILD_VERSION
53+
run: npm version $BUILD_VERSION --no-git-tag-version --allow-same-version
5454

5555
- name: Build
5656
run: npm run build

.github/workflows/made-runtime.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: npm install
5151

5252
- name: Update Version
53-
run: npm version $BUILD_VERSION
53+
run: npm version $BUILD_VERSION --no-git-tag-version --allow-same-version
5454

5555
- name: Build
5656
run: npm run build

.github/workflows/made-threading.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: npm install
5151

5252
- name: Update Version
53-
run: npm version $BUILD_VERSION
53+
run: npm version $BUILD_VERSION --no-git-tag-version --allow-same-version
5454

5555
- name: Build
5656
run: npm run build
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* Defines a builder for constructing a string from values.
3+
*/
4+
export class StringBuilder {
5+
private _strings: string[];
6+
7+
/**
8+
* Initializes a new instance of the StringBuilder class with an optional starting string value.
9+
* @param value The optional starting string value.
10+
*/
11+
constructor(value: string | StringBuilder | null = null) {
12+
this._strings = [];
13+
this.append(value);
14+
}
15+
16+
/**
17+
* Appends the value to this instance.
18+
* @param value The value to append.
19+
* @returns {StringBuilder} A reference to this instance after the append operation has completed.
20+
*/
21+
public append(value: string | StringBuilder | null): StringBuilder {
22+
if (value === undefined || value === null) {
23+
return this;
24+
}
25+
26+
if (value instanceof StringBuilder) {
27+
this._strings.push(...value._strings);
28+
} else {
29+
if (/^\s*$/.test(value)) {
30+
return this;
31+
}
32+
33+
this._strings.push(value);
34+
}
35+
36+
return this;
37+
}
38+
39+
/**
40+
* Inserts the value to this instance at the specified index.
41+
* @param index The position in this instance where the value should be inserted.
42+
* @param value The value to insert.
43+
* @returns {StringBuilder} A reference to this instance after the insert operation has completed.
44+
*/
45+
public insert(index: number, value: string | StringBuilder | null): StringBuilder {
46+
if (value === undefined || value === null) {
47+
return this;
48+
}
49+
50+
if (value instanceof StringBuilder) {
51+
this._strings.splice(index, 0, ...value._strings);
52+
} else {
53+
if (/^\s*$/.test(value)) {
54+
return this;
55+
}
56+
57+
this._strings.splice(index, 0, value);
58+
}
59+
60+
return this;
61+
}
62+
63+
/**
64+
* Replaces all occurrences of a specified string or value based on a regular expression in this instance with another specified string.
65+
* @param search The string or regular expression to find values to replace.
66+
* @param replace The string to replace values with.
67+
* @returns {StringBuilder} A reference to this instance after the replace operation has completed.
68+
*/
69+
public replace(search: string | RegExp, replace: string): StringBuilder {
70+
for (let i = 0; i < this._strings.length; i++) {
71+
this._strings[i] = this._strings[i].replace(search, replace);
72+
}
73+
74+
return this;
75+
}
76+
77+
/**
78+
* Removes the specified range of characters from this instance.
79+
* @param startIndex The zero-based position in this instance where removal begins.
80+
* @param length The number of characters to remove.
81+
* @returns {StringBuilder} A reference to this instance after the remove operation has completed.
82+
*/
83+
public remove(startIndex: number, length: number): void {
84+
this._strings.splice(startIndex, length);
85+
}
86+
87+
/**
88+
* Checks whether this instance is empty.
89+
* @returns {boolean} True if this instance is empty; otherwise, false.
90+
*/
91+
public isEmpty(): boolean {
92+
return this._strings.length === 0;
93+
}
94+
95+
/**
96+
* Clears all strings from this instance.
97+
*/
98+
public clear(): void {
99+
this._strings = [];
100+
}
101+
102+
/**
103+
* Returns a string representation of the value of this instance with a join.
104+
* @returns {string} The strings with a join.
105+
*/
106+
public toString(join: string): string {
107+
return this._strings.join(join);
108+
}
109+
}

MADE.Runtime/src/Text/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './StringBuilder'

MADE.Runtime/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from "./Text";
12
export * from "./Guid";
23
export * from "./IEquatable";

0 commit comments

Comments
 (0)