增加了示例fiber_id 修改了rust中关于字符串的处理
This commit is contained in:
@ -26,6 +26,7 @@ pub fn read_spectral_info<R: Read>(reader: &mut R) -> Result<SpectralInfo> {
|
||||
let mut sensor_buf = [0u8; 50];
|
||||
reader.read_exact(&mut sensor_buf)?;
|
||||
info.sensor_id = String::from_utf8_lossy(&sensor_buf).trim_end_matches('\0').to_string();
|
||||
info.sensor_id = remove_after_null_split_once( info.sensor_id);
|
||||
|
||||
// Read wave coefficients
|
||||
for i in 0..4 {
|
||||
@ -49,6 +50,7 @@ pub fn read_image_info<R: Read>(reader: &mut R) -> Result<ImageInfo> {
|
||||
let mut name_buf = [0u8; 100];
|
||||
reader.read_exact(&mut name_buf)?;
|
||||
info.name = String::from_utf8_lossy(&name_buf).trim_end_matches('\0').to_string();
|
||||
info.name = remove_after_null_split_once(info.name);
|
||||
|
||||
// Read collection time
|
||||
info.collection_time = read_time(reader)?;
|
||||
@ -202,7 +204,15 @@ pub fn read_other_info<R: Read>(reader: &mut R) -> Result<OtherInfo> {
|
||||
|
||||
Ok(info)
|
||||
}
|
||||
|
||||
fn remove_after_null_split_once(s: String) -> String {
|
||||
if let Some((before_null, _after_null)) = s.split_once('\0') {
|
||||
// 返回 \0 之前的部分
|
||||
before_null.to_string()
|
||||
} else {
|
||||
// 如果没有找到 \0,就返回原始 String
|
||||
s
|
||||
}
|
||||
}
|
||||
pub fn read_spectral_data<R: Read>(reader: &mut R) -> Result<SpectralData> {
|
||||
let mut data = SpectralData::new();
|
||||
|
||||
@ -213,10 +223,12 @@ pub fn read_spectral_data<R: Read>(reader: &mut R) -> Result<SpectralData> {
|
||||
name_buf[99] = 0; // Ensure null termination
|
||||
let temp= String::from_utf8_lossy(&name_buf);
|
||||
data.name = temp.trim_end_matches('\0').to_string();
|
||||
data.name = remove_after_null_split_once(data.name);
|
||||
|
||||
let mut sensor_buf = [0u8; 50];
|
||||
reader.read_exact(&mut sensor_buf)?;
|
||||
data.sensor_id = String::from_utf8_lossy(&sensor_buf).trim_end_matches('\0').to_string();
|
||||
data.sensor_id = remove_after_null_split_once(data.sensor_id);
|
||||
let mut uint8_buf = [0u8; 1];
|
||||
|
||||
reader.read_exact(&mut uint8_buf)?;
|
||||
|
Reference in New Issue
Block a user