Skip to content

Commit 546e7c0

Browse files
committed
fix sprintf WIP
1 parent 9e6cfee commit 546e7c0

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package org.perlonjava.operators;
22

3-
import org.perlonjava.runtime.NameNormalizer;
4-
import org.perlonjava.runtime.RuntimeHash;
5-
import org.perlonjava.runtime.RuntimeScalar;
3+
import org.perlonjava.perlmodule.Version;
4+
import org.perlonjava.runtime.*;
65

76
/**
87
* Handles vector string formatting for sprintf operations.
@@ -41,15 +40,16 @@ public String formatVectorString(RuntimeScalar value, String flags, int width,
4140
RuntimeScalar originalScalar = versionObj.get("original");
4241
if (originalScalar.getDefinedBoolean()) {
4342
String originalStr = originalScalar.toString();
44-
// System.err.println("DEBUG: Version object detected, using original: " + originalStr);
4543

46-
// If original starts with 'v', it's a v-string format
44+
// For version objects created with version->new(), use the original
45+
// This preserves the exact format (e.g., "1.2" not "1.2.0")
46+
if (originalStr.matches("\\d+(\\.\\d+)*")) {
47+
return formatVersionVector(originalStr, flags, width, precision, conversionChar, separator);
48+
}
49+
50+
// For v-strings (e.g., "v1.2.3"), remove the 'v'
4751
if (originalStr.startsWith("v")) {
48-
// Remove the 'v' and format as version vector
4952
return formatVersionVector(originalStr.substring(1), flags, width, precision, conversionChar, separator);
50-
} else {
51-
// It's a decimal version string
52-
return formatVersionVector(originalStr, flags, width, precision, conversionChar, separator);
5353
}
5454
}
5555
}

0 commit comments

Comments
 (0)