Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion sjsonnet/src/sjsonnet/Format.scala
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,13 @@ object Format {
else if (signedConversion && formatted.signCharacter) "+" + lhs
else lhs

val missingWidth = formatted.widthOr(-1) - lhs2.length - mhs.length - rhs.length
val missingWidth =
if (numeric) formatted.widthOr(-1) - lhs2.length - mhs.length - rhs.length
else
formatted.widthOr(-1) -
lhs2.codePointCount(0, lhs2.length) -
mhs.codePointCount(0, mhs.length) -
rhs.codePointCount(0, rhs.length)

if (missingWidth <= 0) {
// Avoid unnecessary string concatenation when parts are empty
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Width padding must count codepoints, not UTF-16 code units.
// Supplementary characters (surrogate pairs) count as 1 codepoint.
[
std.assertEqual("%5s" % "πŸ˜€", " πŸ˜€"),
std.assertEqual("%-5s" % "πŸ˜€", "πŸ˜€ "),
std.assertEqual("%5s" % "aπŸ˜€b", " aπŸ˜€b"),
std.assertEqual("%3s" % "πŸ˜€πŸ˜€", " πŸ˜€πŸ˜€"),
std.assertEqual("%5.1s" % "πŸ˜€x", " πŸ˜€"),
std.assertEqual("%5s" % "hello", "hello"),
std.assertEqual("%10s" % "hello", " hello"),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
true,
true,
true,
true,
true,
true,
true
]
Loading