@@ -143,67 +143,53 @@ private static String processFormatSpecifier(
143
143
// Get the value to format
144
144
RuntimeScalar value = (RuntimeScalar ) list .elements .get (args .valueArgIndex );
145
145
146
- // For vector formats with %*v, we need special handling
147
- if (spec .vectorFlag && spec .widthFromArg ) {
148
- // Only treat as separator if * came BEFORE v
149
- // Check the raw format to see the order
150
- int starPos = spec .raw .indexOf ('*' );
151
- int vPos = spec .raw .indexOf ('v' );
152
-
153
- if (starPos < vPos ) {
154
- // This is %*v format - * is separator
155
- // System.err.println("DEBUG: Processing %*v format (separator)");
156
-
146
+ // Special handling for %*v formats where * is the separator
147
+ if (spec .vectorFlag ) {
148
+ // Check if this is %*v format (custom separator)
149
+ if (spec .widthFromArg && spec .raw .matches (".*\\ *v.*" )) {
150
+ // %*v format - * is for separator
157
151
String separator = "." ;
158
- int sepArgIndex ;
159
-
160
- if (spec .widthArgIndex != null ) {
161
- sepArgIndex = spec .widthArgIndex - 1 ;
162
- } else {
163
- sepArgIndex = argIndex ;
164
- }
165
-
166
- // System.err.println("DEBUG: sepArgIndex=" + sepArgIndex);
152
+ int sepArgIndex = argIndex ;
167
153
168
154
if (sepArgIndex < list .size ()) {
169
155
separator = ((RuntimeScalar ) list .elements .get (sepArgIndex )).toString ();
170
- // System.err.println("DEBUG: Got separator: '" + separator + "'");
171
156
}
172
157
173
- // For %*v formats, we need to get the value from the correct position
174
- int actualValueIndex ;
175
- if (spec .parameterIndex != null ) {
176
- actualValueIndex = spec .parameterIndex - 1 ;
158
+ int actualWidth = 0 ;
159
+ int valueIndex ;
160
+
161
+ if (spec .precisionFromArg ) {
162
+ // %*v*d format - second * is for width
163
+ int widthArgIndex = sepArgIndex + 1 ;
164
+ if (widthArgIndex < list .size ()) {
165
+ actualWidth = ((RuntimeScalar ) list .elements .get (widthArgIndex )).getInt ();
166
+ }
167
+ valueIndex = widthArgIndex + 1 ;
177
168
} else {
178
- // Skip past the separator argument
179
- actualValueIndex = argIndex + 1 ;
169
+ // %*vd or %*v2d format
170
+ actualWidth = spec .width != null ? spec .width : 0 ;
171
+ valueIndex = sepArgIndex + 1 ;
180
172
}
181
173
182
- if (actualValueIndex >= list .size ()) {
174
+ if (valueIndex >= list .size ()) {
183
175
return handleMissingArgument (spec , args );
184
176
}
177
+ value = (RuntimeScalar ) list .elements .get (valueIndex );
185
178
186
- // Update value to the correct argument
187
- value = (RuntimeScalar ) list .elements .get (actualValueIndex );
188
-
189
- // System.err.println("DEBUG: Calling formatVectorString with width=" + spec.width + ", separator='" + separator + "'");
190
-
191
- // Format with custom separator - use spec.width which has the actual width
192
- return formatter .formatVectorString (value , spec .flags , spec .width != null ? spec .width : 0 ,
179
+ return formatter .formatVectorString (value , spec .flags , actualWidth ,
193
180
args .precision , spec .conversionChar , separator );
181
+ } else if (spec .widthFromArg ) {
182
+ // %v*d format - * is for width, not separator
183
+ // Use default separator and get width from args
184
+ return formatter .formatVectorString (value , spec .flags , args .width ,
185
+ args .precision , spec .conversionChar );
194
186
} else {
195
- // This is %v*d format - * is width, handle normally
196
- // System.err.println("DEBUG: Processing %v*d format ( width from arg)");
197
- // Fall through to normal formatting
187
+ // Regular vector format
188
+ return formatter . formatVectorString ( value , spec . flags , args . width ,
189
+ args . precision , spec . conversionChar );
198
190
}
199
- }
200
-
201
- // Format the value using the appropriate formatter
202
- if (spec .vectorFlag ) {
203
- // System.err.println("DEBUG: Processing vector format: " + spec.raw);
204
- return formatter .formatVectorString (value , spec .flags , args .width ,
205
- args .precision , spec .conversionChar );
206
191
} else {
192
+ // Non-vector format
207
193
return formatter .formatValue (value , spec .flags , args .width ,
208
194
args .precision , spec .conversionChar );
209
195
}
0 commit comments