Skip to content

Commit 0cd16bd

Browse files
sublipriSerial-ATA
authored andcommitted
util: Add helper function to trim trailing nulls
1 parent f45d1d3 commit 0cd16bd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/util/text.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ pub(crate) fn encode_text(text: &str, text_encoding: TextEncoding, terminated: b
212212
}
213213
}
214214

215+
pub(crate) fn trim_end_nulls(text: &mut String) {
216+
if text.ends_with('\0') {
217+
let new_len = text.trim_end_matches('\0').len();
218+
text.truncate(new_len);
219+
}
220+
}
221+
215222
fn utf16_encode(
216223
text: &str,
217224
endianness: fn(u16) -> [u8; 2],

0 commit comments

Comments
 (0)