Skip to content

Commit 09de634

Browse files
committed
Update stringt.inc
1 parent 9e00193 commit 09de634

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

include/stringt.inc

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* Extended by blueblur
2121
* url https://github.com/blueblur0730/modified-plugins
22-
* Version 1.1.0
22+
* Version 1.2.0
2323
* Date: 2025-11-14
2424
*/
2525

@@ -47,6 +47,14 @@ methodmap Stringt < AddressBase
4747
return UTIL_StringtToCharArray(this, buffer, maxlen);
4848
}
4949

50+
public int ToCharArray2D(char[][] buffer, int maxlen1, int maxlen2) {
51+
if (this.IsNull()) {
52+
ThrowError("Stringt address is null.");
53+
}
54+
55+
return UTIL_StringtToCharArray2D(this, buffer, maxlen1, maxlen2);
56+
}
57+
5058
// included null terminator.
5159
public int strlen() {
5260
if (this.IsNull()) {
@@ -129,6 +137,46 @@ stock int UTIL_StringtToCharArray(Stringt stringt, char[] buffer, int maxlen)
129137
return index;
130138
}
131139

140+
stock int UTIL_StringtToCharArray2D(Stringt stringt, char[][] buffer, int maxlen1, int maxlen2)
141+
{
142+
if (stringt.addr == Address_Null) {
143+
ThrowError("Stringt address is null.");
144+
}
145+
146+
if (maxlen1 <= 0 || maxlen2 <= 0) {
147+
ThrowError("The parameters maxlen1 and maxlen2 must be greater than 0.");
148+
}
149+
150+
int rowIndex = 0;
151+
int colIndex = 0;
152+
int colEnd = maxlen2 - 1;
153+
char character;
154+
155+
while (rowIndex < maxlen1)
156+
{
157+
colIndex = 0;
158+
while (colIndex < colEnd)
159+
{
160+
character = LoadFromAddress(stringt.addr + (rowIndex * maxlen2) + colIndex, NumberType_Int8);
161+
162+
if (character == '\0')
163+
break;
164+
165+
buffer[rowIndex][colIndex] = character;
166+
++colIndex;
167+
}
168+
169+
buffer[rowIndex][colIndex] = '\0';
170+
171+
if (character == '\0')
172+
break;
173+
174+
++rowIndex;
175+
}
176+
177+
return rowIndex;
178+
}
179+
132180
// not safe, did not check the length.
133181
stock Stringt UTIL_StrCpy(Stringt pDest, const Stringt pSrc)
134182
{

0 commit comments

Comments
 (0)