Branch: Tag:

2018-10-31

2018-10-31 14:06:08 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Cpp: Improved white-space fidelity.

White space characters that aren't '\r' are now kept unmodified
in the output. '\r' characters are removed if they are followed
immediately by a '\n' character, and are otherwise kept.

This change makes cpp() keep indentations, and improves the
readability of the output from Tools.Standalone.precompile.

375:    }    }    if (!(raw_arg & DEF_ARG_NOPOSTSPACE)) { +  if (!s.s->len || +  !wide_isspace(index_shared_string(s.s, s.s->len-1))) {    string_builder_putchar(&s, ' ');    }    } -  +  }    break;    default:    /* FIXME: Check that we have a callable. */
3494:    PUTC(' ');    break;    +  case '\r': +  /* NB: Keep only CR's that aren't followed by NL. */ +  if (DATA(pos) == '\n') break; +  /* FALLTHRU */    case '\t':    case ' ': -  case '\r': -  PUTC(' '); +  PUTC(c);       do_skipwhite: -  while( wide_isspace(c=DATA(pos)) && c != '\n' && c != '\r' ) +  while( wide_isspace(c=DATA(pos)) && c != '\n' && c != '\r' ) { +  PUTC(c);    pos++; -  +  }    break;       /* Minor optimization */
4442:    string_builder_append(&str, ADD_PCHARP(data, tmp3), pos - tmp3);    continue;    +  case '\r': +  if (DATA(pos) != '\n') { +  string_builder_putchar(&str, '\r'); +  } +  break; +     case '\n':    PUTNL();    this->current_line++;