Skip to content

Commit

Permalink
Support for multibyte string
Browse files Browse the repository at this point in the history
  • Loading branch information
takuma-watanabe committed Aug 26, 2021
1 parent 3d0250b commit 9b8b8b0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ csv = "1.1.6"
serde = { version = "1.0.129", features = ["derive"] }
serde_json = "1.0.66"
tokio = { version = "1.10.1", features = ["full"] }
unicode-width = "0.1.7"
6 changes: 4 additions & 2 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::{collections::HashMap, fmt::Display};
use crate::utils::Transpose;
use anyhow::{Context, Result};

use unicode_width::UnicodeWidthStr;

type Json<'a> = HashMap<&'a str, serde_json::Value>;

#[derive(Debug)]
Expand Down Expand Up @@ -74,7 +76,7 @@ impl<'a> Data<'a> {
.zip(keys)
.map(|(mut xs, k)| {
xs.push(&k);
xs.into_iter().map(|x| x.len()).max().unwrap_or_default()
xs.into_iter().map(|x| x.width()).max().unwrap_or_default()
})
.collect::<Vec<_>>()
}
Expand Down Expand Up @@ -108,7 +110,7 @@ impl<'a> Display for Data<'a> {
xs
.iter()
.zip(pads.clone())
.map(|(x, pad)| format!("{:>width$}", x, width = pad))
.map(|(x, pad)| format!("{}{}", " ".repeat(pad - x.width()), x))
.collect::<Vec<_>>()
.join("|")
)
Expand Down
2 changes: 1 addition & 1 deletion test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"name": "test",
"name": "テストテスト",
"age": 10,
"lang": "ja"
},
Expand Down

0 comments on commit 9b8b8b0

Please sign in to comment.