diff --git a/src/atom.cpp b/src/atom.cpp index cf676a8b0d..b1f4190002 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1834,8 +1834,8 @@ void Atom::set_mass(const char *file, int line, int /*narg*/, char **arg) { if (mass == nullptr) error->all(file,line, "Cannot set atom mass for atom style {}", atom_style); - if (!isdigit(arg[0][0]) && arg[0][0] != '*') { - std::string typestr(arg[0]); + std::string typestr = utils::trim(arg[0]); + if (!isdigit(typestr[0]) && typestr[0] != '*') { int itype = lmap->find(typestr,Atom::ATOM); if (itype == -1) error->all(file,line,"Invalid type for mass set"); mass[itype] = utils::numeric(FLERR,arg[1],false,lmp); diff --git a/src/input.cpp b/src/input.cpp index f5ad023513..72465cd9a9 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -728,7 +728,7 @@ int Input::readtype(char *&str, int mode) int type,max,max2; char typechar[256]; - std::string labelstr(str); + std::string labelstr = utils::trim(str); type = atom->lmap->find(labelstr,mode); if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str)); diff --git a/src/label_map.cpp b/src/label_map.cpp index 4aeb4f29a1..e95780135a 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -137,7 +137,7 @@ void LabelMap::modify_lmap(int narg, char **arg) int itype = utils::inumeric(FLERR, arg[iarg++], false, lmp); if ((itype < 1) || (itype > ntypes)) error->all(FLERR, "Labelmap {} type {} must be within 1-{}", tlabel, itype, ntypes); - std::string slabel(arg[iarg++]); + std::string slabel = utils::trim(arg[iarg++]); if (isdigit(slabel[0]) || (slabel[0] == '#') || (slabel[0] == '*')) error->all(FLERR, "Label {} for {} type {} must not start with a number, a '#', or a '*'", slabel, tlabel, itype); diff --git a/unittest/commands/test_labelmap.cpp b/unittest/commands/test_labelmap.cpp index 15344b45bb..bd4224864a 100644 --- a/unittest/commands/test_labelmap.cpp +++ b/unittest/commands/test_labelmap.cpp @@ -153,6 +153,16 @@ TEST_F(SetTest, NoBoxAtoms) ASSERT_FALSE(atom->lmap->is_complete(Atom::ATOM)); ASSERT_EQ(atom->lmap->find("C1", Atom::ATOM), 3); ASSERT_EQ(atom->lmap->find("N2", Atom::ATOM), 2); + + BEGIN_HIDE_OUTPUT(); + command("labelmap clear"); + command("labelmap atom 1 \"C1'\" 2 'C2\"' 3 \"\"\"C1'-C2\" \"\"\" 4 \"\"\" C2\"-C1'\"\"\""); + END_HIDE_OUTPUT(); + ASSERT_TRUE(atom->lmap->is_complete(Atom::ATOM)); + ASSERT_EQ(atom->lmap->find("C1'", Atom::ATOM), 1); + ASSERT_EQ(atom->lmap->find("C2\"", Atom::ATOM), 2); + ASSERT_EQ(atom->lmap->find("C1'-C2\"", Atom::ATOM), 3); + ASSERT_EQ(atom->lmap->find("C2\"-C1'", Atom::ATOM), 4); } } // namespace LAMMPS_NS