Skip to content

Commit

Permalink
Merge pull request #304 from koto-lang/fill-character-fix
Browse files Browse the repository at this point in the history
Fix support for single-char-but-multi-byte fill characters
  • Loading branch information
irh authored Apr 5, 2024
2 parents 47915f2 + 2c7c85c commit 5285933
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion crates/parser/src/string_format_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ impl StringFormatOptions {
match (next, chars.peek(), position) {
// Check for single-char fill character at the start of the string
(_, Some('<' | '^' | '>'), Start) => {
result.fill_character = Some(add_string_constant(&format_string[0..1])?);
result.fill_character =
Some(add_string_constant(&format_string[0..next.len_utf8()])?);
result.alignment = char_to_alignment(chars.next().unwrap());
position = MinWidth;
}
Expand Down Expand Up @@ -205,6 +206,15 @@ mod tests {
..Default::default()
},
),
(
"𝜇<.9",
StringFormatOptions {
alignment: StringAlignment::Left,
fill_character: Some(0),
precision: Some(9),
..Default::default()
},
),
(
"🫶🏽>20.10",
StringFormatOptions {
Expand Down
7 changes: 6 additions & 1 deletion docs/language_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,12 @@ check! ('l', 'l', 'ø')
Interpolated string expressions can be formatted using formatting options
similar to [Rust's][rust-format-options].

Options can be provided after a `:` separator inside the `{}` expression.
Inside an interpolated expression, options are provided after a `:` separator.

```koto
print! '{number.pi:𝜋^8.2}'
check! 𝜋𝜋3.14𝜋𝜋
```

### Minimum Width and Alignment

Expand Down

0 comments on commit 5285933

Please sign in to comment.