From a11916449656b3d514930d49827c34e5d499729f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 25 Jan 2021 20:53:59 -0500 Subject: [PATCH] add utf-8 check, substitution, and warning to Input::parse() function --- src/input.cpp | 11 +++++++++++ src/input.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/input.cpp b/src/input.cpp index 457cf74b1a..df5cf0efbe 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -106,6 +106,7 @@ Input::Input(LAMMPS *lmp, int argc, char **argv) : Pointers(lmp) label_active = 0; labelstr = nullptr; jump_skip = 0; + utf8_warn = true; if (me == 0) { nfile = 1; @@ -421,6 +422,16 @@ void Input::parse() ptr++; } + if (utils::has_utf8(copy)) { + std::string buf = utils::utf8_subst(copy); + strcpy(copy,buf.c_str()); + if (utf8_warn && (comm->me == 0)) + error->warning(FLERR,"Detected non-ASCII characters in input. " + "Will try to continue by replacing with ASCII " + "equivalents where known."); + utf8_warn = false; + } + // perform $ variable substitution (print changes) // except if searching for a label since earlier variable may not be defined diff --git a/src/input.h b/src/input.h index b8ffb276f9..a86b10a686 100644 --- a/src/input.h +++ b/src/input.h @@ -54,6 +54,7 @@ class Input : protected Pointers { int label_active; // 0 = no label, 1 = looking for label char *labelstr; // label string being looked for int jump_skip; // 1 if skipping next jump, 0 otherwise + bool utf8_warn; // true if need to warn about UTF-8 chars FILE **infiles; // list of open input files