Skip to content

Commit 6d5d13f

Browse files
author
skidy89
committed
streamline string trimming in parser function
1 parent 4b4f430 commit 6d5d13f

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

__test__/languages.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
/* eslint-disable */
55

66
export interface Lang {
7-
'test': string;
87
'hello': string;
8+
'test': string;
99
}
1010

1111
export interface Langs {

src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ fn parse_lang_data(data: &str) -> HashMap<String, String> {
4747
cval.push('\n');
4848
if line.trim().ends_with('"') && !line.trim().ends_with("\\\"") {
4949
mtl = false;
50+
if cval.starts_with('"') {
51+
cval = cval[1..cval.len() - 1].trim_end().to_string();
52+
}
53+
if cval.ends_with('"') {
54+
cval.pop();
55+
}
5056
if let Some(key) = ckey.take() {
51-
let value = if cval.starts_with('"') {
52-
cval[1..cval.len() - 1].trim_end().to_string()
53-
} else {
54-
cval.trim_end().to_string()
55-
};
56-
map.insert(key, value);
57-
cval.clear();
57+
map.insert(key, cval.trim_end().to_string());
5858
}
59+
cval.clear();
5960
}
6061
continue;
6162
}

0 commit comments

Comments
 (0)