oxedyne/fe2o3/fe2o3_jdat/src/string/core.rs
1.2 KiB, 3 runs
created by r1870400018:483, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use crate::{ |
| 2 | prelude::*, |
| 3 | daticle::{ |
| 4 | IterDatValsMut, |
| 5 | }, |
| 6 | }; |
| 7 | |
| 8 | use oxedyne_fe2o3_core::prelude::*; |
| 9 | |
| 10 | |
| 11 | impl Dat { |
| 12 | |
| 13 | pub fn normalise_string_values(&mut self, tab: &str) -> Outcome<()> { |
| 14 | let iter = IterDatValsMut::new(self); |
| 15 | for d in iter { |
| 16 | if let Dat::Str(s) = d { |
| 17 | let mut snew = String::new(); |
| 18 | let mut backslash_active = false; |
| 19 | for c in s.chars() { |
| 20 | match c { |
| 21 | '\n' | '\r' => continue, |
| 22 | '\t' => snew.push_str(&tab), |
| 23 | '\\' => if !backslash_active { |
| 24 | backslash_active = true; |
| 25 | } else { |
| 26 | continue; |
| 27 | }, |
| 28 | ' ' if backslash_active => continue, |
| 29 | _ => { |
| 30 | if backslash_active && c != ' ' { |
| 31 | backslash_active = false; |
| 32 | } |
| 33 | snew.push(c); |
| 34 | }, |
| 35 | } |
| 36 | } |
| 37 | *s = snew; |
| 38 | } |
| 39 | } |
| 40 | Ok(()) |
| 41 | } |
| 42 | } |