///|
// STEP text helpers
pub fn step_str(s : String) -> String {
  // Escape every apostrophe by doubling it. Build the result explicitly:
  // `String::replace` is not guaranteed to replace more than the first match,
  // and a STEP string may contain several doubled quotes.
  let builder = StringBuilder()
  builder.write_char('\'')
  for c in s {
    if c == '\'' {
      builder.write_char('\'')
    }
    builder.write_char(c)
  }
  builder.write_char('\'')
  builder.to_string()
}

///|
pub fn fmt_num(n : Double) -> String {
  // ISO 10303-21 reals are [sign] digits "." digits [ "E" [sign] digits ]:
  // the decimal point is mandatory and the exponent marker must be an
  // upper-case E. Rounding trig residue (< 1e-12) to zero keeps such values
  // out of exponent form (and makes nominally axis-aligned geometry exact).
  if n.abs() < 1.0e-12 {
    return "0.0"
  }
  if n == n.floor() {
    "\{n.to_int()}.0"
  } else {
    let s = n.to_string().replace(old="e", new="E")
    let parts = s.split("E").collect()
    if parts.length() == 2 {
      let mant = parts[0].to_owned()
      let mant = if mant.contains(".") { mant } else { mant + ".0" }
      mant + "E" + parts[1].to_owned()
    } else {
      s
    }
  }
}