@@ -27,7 +27,7 @@ public static RuntimeScalar sprintf(RuntimeScalar runtimeScalar, RuntimeList lis
27
27
result .append ((String ) element );
28
28
} else if (element instanceof SprintfFormatParser .FormatSpecifier spec ) {
29
29
30
- // System.err.println("DEBUG Operator: spec.raw=" + spec.raw + ", isValid=" + spec.isValid + ", errorMessage=" + spec.errorMessage);
30
+ // // System.err.println("DEBUG Operator: spec.raw=" + spec.raw + ", isValid=" + spec.isValid + ", errorMessage=" + spec.errorMessage);
31
31
32
32
// Handle %%
33
33
if (spec .conversionChar == '%' ) {
@@ -84,7 +84,7 @@ public static RuntimeScalar sprintf(RuntimeScalar runtimeScalar, RuntimeList lis
84
84
WarnDie .warn (new RuntimeScalar (spec .invalidLengthModifierWarning ), new RuntimeScalar ("" ));
85
85
}
86
86
87
- // System.err.println("DEBUG: Processing valid spec: " + spec.raw);
87
+ // // System.err.println("DEBUG: Processing valid spec: " + spec.raw);
88
88
89
89
// The rest of the valid format processing continues here...
90
90
int savedArgIndex = argIndex ;
@@ -146,6 +146,7 @@ public static RuntimeScalar sprintf(RuntimeScalar runtimeScalar, RuntimeList lis
146
146
} else {
147
147
valueArgIndex = argIndex ++;
148
148
}
149
+ // System.err.println("DEBUG sprintf: before MISSING check - valueArgIndex=" + valueArgIndex + ", list.size=" + list.size() + ", vectorFlag=" + spec.vectorFlag);
149
150
if (valueArgIndex >= list .size ()) {
150
151
if (spec .conversionChar == 'n' ) {
151
152
// %n is a no-op for now - just continue without throwing
@@ -185,8 +186,17 @@ public static RuntimeScalar sprintf(RuntimeScalar runtimeScalar, RuntimeList lis
185
186
// Format the value
186
187
String formatted ;
187
188
if (spec .vectorFlag ) {
189
+ // System.err.println("DEBUG sprintf: vector format, valueArgIndex=" + valueArgIndex + ", list.size=" + list.size());
190
+ // System.err.println("DEBUG sprintf: value type=" + value.type + ", value=" + value + ", toString()=" + value.toString());
191
+
192
+ // Check if it's a VSTRING
193
+ if (value .type == RuntimeScalarType .VSTRING ) {
194
+ // System.err.println("DEBUG sprintf: This is a VSTRING!");
195
+ }
196
+
188
197
formatted = formatVectorString (value , spec .flags , width ,
189
198
precision , spec .conversionChar );
199
+ // System.err.println("DEBUG sprintf: formatVectorString returned: '" + formatted + "'");
190
200
} else {
191
201
formatted = formatValue (value , spec .flags , width ,
192
202
precision , spec .conversionChar );
@@ -208,12 +218,20 @@ private static boolean isInvalidSpecifier(char c) {
208
218
// List of invalid specifiers that should return "INVALID"
209
219
return "CHIKMVWYJLNPQRSTZ" .indexOf (c ) >= 0 ;
210
220
}
211
-
212
221
private static String formatVectorString (RuntimeScalar value , String flags , int width ,
213
222
int precision , char conversionChar ) {
214
- // Check if this is a version object
223
+ try {
224
+ // System.err.println("DEBUG formatVectorString: Start - type=" + value.type + ", precision=" + precision);
225
+
215
226
String str ;
216
- if (value .isBlessed () && NameNormalizer .getBlessStr (value .blessId ).equals ("version" )) {
227
+ boolean isVersionObject = false ;
228
+
229
+ // Check for VSTRING type first
230
+ if (value .type == RuntimeScalarType .VSTRING ) {
231
+ // VSTRINGs should be handled as byte sequences
232
+ str = value .toString ();
233
+ // Don't treat it as a version object
234
+ } else if (value .isBlessed () && NameNormalizer .getBlessStr (value .blessId ).equals ("version" )) {
217
235
// Extract the version string from the version object
218
236
RuntimeHash versionObj = value .hashDeref ();
219
237
str = versionObj .get ("version" ).toString ();
@@ -263,7 +281,11 @@ private static String formatVectorString(RuntimeScalar value, String flags, int
263
281
}
264
282
265
283
int byteValue = bytes [i ] & 0xFF ;
284
+ // System.err.println("DEBUG formatVectorString: Processing byte[" + i + "]=" + byteValue);
285
+
266
286
String formatted = formatVectorValue (byteValue , flags , precision , conversionChar );
287
+ // System.err.println("DEBUG formatVectorString: Formatted to: " + formatted);
288
+
267
289
result .append (formatted );
268
290
}
269
291
@@ -279,7 +301,12 @@ private static String formatVectorString(RuntimeScalar value, String flags, int
279
301
}
280
302
281
303
return formatted ;
304
+ } catch (Exception e ) {
305
+ // System.err.println("ERROR in formatVectorString: " + e);
306
+ e .printStackTrace ();
307
+ throw e ;
282
308
}
309
+ }
283
310
284
311
private static boolean isVersionObject (RuntimeScalar value ) {
285
312
// Check if this is a version object by looking at its string representation
@@ -362,6 +389,7 @@ private static String formatVectorValue(int byteValue, String flags, int precisi
362
389
formatted = String .valueOf (byteValue );
363
390
}
364
391
392
+ // System.err.println("DEBUG sprintf: calling formatVectorString with precision=" + precision);
365
393
// Apply precision padding
366
394
if (precision > 0 ) {
367
395
String prefix = "" ;
@@ -381,12 +409,9 @@ private static String formatVectorValue(int byteValue, String flags, int precisi
381
409
}
382
410
383
411
// Pad the numeric part
384
- if (number .length () < precision - (flags .contains ("#" ) && (conversionChar == 'o' || conversionChar == 'x' || conversionChar == 'X' || conversionChar == 'b' || conversionChar == 'B' ) && byteValue != 0 ? prefix .length () : 0 )) {
385
- int padWidth = precision ;
386
- if (flags .contains ("#" ) && byteValue != 0 && (conversionChar == 'o' || conversionChar == 'x' || conversionChar == 'X' || conversionChar == 'b' || conversionChar == 'B' )) {
387
- padWidth = precision ; // Don't subtract prefix for padding calculation
388
- }
389
- number = String .format ("%0" + padWidth + "s" , number );
412
+ if (number .length () < precision ) {
413
+ int padWidth = precision - number .length ();
414
+ number = "0" .repeat (padWidth ) + number ;
390
415
}
391
416
392
417
formatted = prefix + number ;
0 commit comments