Skip to content

Commit 9e6cfee

Browse files
committed
fix sprintf WIP
1 parent 07bc628 commit 9e6cfee

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ private String formatByteVector(String str, String flags, int width,
171171
* @return The formatted element
172172
*/
173173
private String formatVectorValue(int byteValue, String flags, int width, int precision,
174-
char conversionChar) {
175-
// System.err.println("DEBUG: formatVectorValue called with byteValue=" + byteValue +
176-
// ", flags='" + flags + "', width=" + width + ", precision=" + precision);
177-
174+
char conversionChar) {
178175
String formatted = switch (conversionChar) {
179176
case 'd', 'i' -> formatVectorDecimal(byteValue, flags);
180177
case 'o' -> formatVectorOctal(byteValue, flags);
@@ -184,16 +181,17 @@ private String formatVectorValue(int byteValue, String flags, int width, int pre
184181
default -> String.valueOf(byteValue);
185182
};
186183

187-
// System.err.println("DEBUG: After formatting: '" + formatted + "'");
188-
189184
// Apply precision first
190185
formatted = SprintfPaddingHelper.applyVectorPrecision(formatted, precision, flags);
191-
// System.err.println("DEBUG: After precision: '" + formatted + "'");
186+
187+
// For vector formats, if precision is specified, ignore the '0' flag
188+
String widthFlags = flags;
189+
if (precision >= 0 && flags.contains("0")) {
190+
widthFlags = flags.replace("0", "");
191+
}
192192

193193
// Then apply width to the individual element
194-
String result = SprintfPaddingHelper.applyWidth(formatted, width, flags);
195-
// System.err.println("DEBUG: After width: '" + formatted + "' -> '" + result + "'");
196-
return result;
194+
return SprintfPaddingHelper.applyWidth(formatted, width, widthFlags);
197195
}
198196

199197
/**

0 commit comments

Comments
 (0)