|
19 | 19 | * |
20 | 20 | * Extended by blueblur |
21 | 21 | * url https://github.com/blueblur0730/modified-plugins |
22 | | - * Version 1.1.0 |
| 22 | + * Version 1.2.0 |
23 | 23 | * Date: 2025-11-14 |
24 | 24 | */ |
25 | 25 |
|
@@ -47,6 +47,14 @@ methodmap Stringt < AddressBase |
47 | 47 | return UTIL_StringtToCharArray(this, buffer, maxlen); |
48 | 48 | } |
49 | 49 |
|
| 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 | + |
50 | 58 | // included null terminator. |
51 | 59 | public int strlen() { |
52 | 60 | if (this.IsNull()) { |
@@ -129,6 +137,46 @@ stock int UTIL_StringtToCharArray(Stringt stringt, char[] buffer, int maxlen) |
129 | 137 | return index; |
130 | 138 | } |
131 | 139 |
|
| 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 | + |
132 | 180 | // not safe, did not check the length. |
133 | 181 | stock Stringt UTIL_StrCpy(Stringt pDest, const Stringt pSrc) |
134 | 182 | { |
|
0 commit comments