Skip to content

Commit fddf14e

Browse files
committed
fix pack() WIP
1 parent 2a791b8 commit fddf14e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/main/java/org/perlonjava/operators/Unpack.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ public static RuntimeList unpack(int ctx, RuntimeBase... args) {
154154
// Repeat until end of data
155155
groupRepeatCount = Integer.MAX_VALUE;
156156
nextPos++;
157+
} else if (nextChar == '[') {
158+
// Parse repeat count in brackets [n]
159+
int j = nextPos + 1;
160+
while (j < template.length() && Character.isDigit(template.charAt(j))) {
161+
j++;
162+
}
163+
if (j >= template.length() || template.charAt(j) != ']') {
164+
throw new PerlCompilerException("No group ending character ']' found in template");
165+
}
166+
String countStr = template.substring(nextPos + 1, j);
167+
groupRepeatCount = Integer.parseInt(countStr);
168+
nextPos = j + 1; // Move past ']'
157169
} else if (Character.isDigit(nextChar)) {
158170
// Parse numeric repeat count
159171
int j = nextPos;
@@ -274,6 +286,18 @@ public static RuntimeList unpack(int ctx, RuntimeBase... args) {
274286
isStarCount = true;
275287
i++;
276288
count = getRemainingCount(state, format, startsWithU);
289+
} else if (nextChar == '[') {
290+
// Parse repeat count in brackets [n]
291+
int j = i + 2;
292+
while (j < template.length() && Character.isDigit(template.charAt(j))) {
293+
j++;
294+
}
295+
if (j >= template.length() || template.charAt(j) != ']') {
296+
throw new PerlCompilerException("No group ending character ']' found in template");
297+
}
298+
String countStr = template.substring(i + 2, j);
299+
count = Integer.parseInt(countStr);
300+
i = j; // Position at ']'
277301
} else if (Character.isDigit(nextChar)) {
278302
int j = i + 1;
279303
while (j < template.length() && Character.isDigit(template.charAt(j))) {

0 commit comments

Comments
 (0)