Skip to content

Commit dcc01fb

Browse files
author
Stephan Dilly
committed
migrate some more to unicode-truncate crate
1 parent 36b8ca6 commit dcc01fb

File tree

4 files changed

+9
-28
lines changed

4 files changed

+9
-28
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ serde = "1.0"
4040
anyhow = "1.0"
4141
unicode-width = "0.1"
4242
textwrap = "0.13"
43-
unicode-truncate = {version="0.2", git="https://github.com/Aetf/unicode-truncate.git"}
43+
unicode-truncate = "0.2.0"
4444

4545
[target.'cfg(all(target_family="unix",not(target_os="macos")))'.dependencies]
4646
which = "4.0"

asyncgit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ crossbeam-channel = "0.5"
1919
log = "0.4"
2020
thiserror = "1.0"
2121
url = "2.2"
22+
unicode-truncate = "0.2.0"
2223

2324
[dev-dependencies]
2425
tempfile = "3.2"

asyncgit/src/sync/commits_info.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::utils::repo;
22
use crate::error::Result;
33
use git2::{Commit, Error, Oid};
44
use scopetime::scope_time;
5+
use unicode_truncate::UnicodeTruncateStr;
56

67
/// identifies a single commit
78
#[derive(
@@ -99,32 +100,18 @@ pub fn get_message(
99100
message_length_limit: Option<usize>,
100101
) -> String {
101102
let msg = String::from_utf8_lossy(c.message_bytes());
102-
let msg = msg.trim_start();
103+
let msg = msg.trim();
103104

104105
if let Some(limit) = message_length_limit {
105-
limit_str(msg, limit).to_string()
106+
msg.unicode_truncate(limit).0.to_string()
106107
} else {
107108
msg.to_string()
108109
}
109110
}
110111

111-
#[inline]
112-
fn limit_str(s: &str, limit: usize) -> &str {
113-
if let Some(first) = s.lines().next() {
114-
let mut limit = limit.min(first.len());
115-
while !first.is_char_boundary(limit) {
116-
limit += 1
117-
}
118-
&first[0..limit]
119-
} else {
120-
""
121-
}
122-
}
123-
124112
#[cfg(test)]
125113
mod tests {
126-
127-
use super::{get_commits_info, limit_str};
114+
use super::get_commits_info;
128115
use crate::error::Result;
129116
use crate::sync::{
130117
commit, stage_add_file, tests::repo_init_empty,
@@ -183,13 +170,4 @@ mod tests {
183170

184171
Ok(())
185172
}
186-
187-
#[test]
188-
fn test_limit_string_utf8() {
189-
assert_eq!(limit_str("里里", 1), "里");
190-
191-
let test_src = "导入按钮由选文件改为选目录,因为整个过程中要用到多个mdb文件,这些文件是在程序里写死的,暂且这么来做,有时间了后 再做调整";
192-
let test_dst = "导入按钮由选文";
193-
assert_eq!(limit_str(test_src, 20), test_dst);
194-
}
195173
}

0 commit comments

Comments
 (0)