add strip_style_suffix utility function
This commit is contained in:
@ -133,6 +133,9 @@ and parsing files or arguments.
|
|||||||
.. doxygenfunction:: trim_comment
|
.. doxygenfunction:: trim_comment
|
||||||
:project: progguide
|
:project: progguide
|
||||||
|
|
||||||
|
.. doxygenfunction:: strip_style_suffix
|
||||||
|
:project: progguide
|
||||||
|
|
||||||
.. doxygenfunction:: star_subst
|
.. doxygenfunction:: star_subst
|
||||||
:project: progguide
|
:project: progguide
|
||||||
|
|
||||||
|
|||||||
@ -866,6 +866,30 @@ std::string utils::star_subst(const std::string &name, bigint step, int pad)
|
|||||||
return fmt::format("{}{:0{}}{}", name.substr(0, star), step, pad, name.substr(star + 1));
|
return fmt::format("{}{:0{}}{}", name.substr(0, star), step, pad, name.substr(star + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
Remove accelerator style suffix from string
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
std::string utils::strip_style_suffix(const std::string &style, LAMMPS *lmp)
|
||||||
|
{
|
||||||
|
std::string newstyle = style;
|
||||||
|
if (lmp->suffix_enable) {
|
||||||
|
if (lmp->suffix) {
|
||||||
|
if (utils::strmatch(style, fmt::format("/{}$", lmp->suffix))) {
|
||||||
|
newstyle.resize(style.size() - strlen(lmp->suffix) - 1);
|
||||||
|
return newstyle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lmp->suffix2) {
|
||||||
|
if (utils::strmatch(style, fmt::format("/{}$", lmp->suffix2))) {
|
||||||
|
newstyle.resize(style.size() - strlen(lmp->suffix2) - 1);
|
||||||
|
return newstyle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newstyle;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
Replace UTF-8 encoded chars with known ASCII equivalents
|
Replace UTF-8 encoded chars with known ASCII equivalents
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|||||||
18
src/utils.h
18
src/utils.h
@ -430,7 +430,23 @@ namespace utils {
|
|||||||
|
|
||||||
std::string star_subst(const std::string &name, bigint step, int pad);
|
std::string star_subst(const std::string &name, bigint step, int pad);
|
||||||
|
|
||||||
/*! Check if a string will likely have UTF-8 encoded characters
|
/*! Remove style suffix from string if suffix flag is active
|
||||||
|
*
|
||||||
|
*
|
||||||
|
\verbatim embed:rst
|
||||||
|
|
||||||
|
This will try to undo the effect from using the :doc:`suffix command <suffix>`
|
||||||
|
or the *-suffix/-sf* command line flag and return correspondingly modified string.
|
||||||
|
|
||||||
|
\endverbatim
|
||||||
|
*
|
||||||
|
* \param style string of style name
|
||||||
|
* \param lmp pointer to the LAMMPS class (has suffix_flag and suffix strings)
|
||||||
|
* \return processed string */
|
||||||
|
|
||||||
|
std::string strip_style_suffix(const std::string &style, LAMMPS *lmp);
|
||||||
|
|
||||||
|
/*! Check if a string will likely have UTF-8 encoded characters
|
||||||
*
|
*
|
||||||
* UTF-8 uses the 7-bit standard ASCII table for the first 127 characters and
|
* UTF-8 uses the 7-bit standard ASCII table for the first 127 characters and
|
||||||
* all other characters are encoded as multiple bytes. For the multi-byte
|
* all other characters are encoded as multiple bytes. For the multi-byte
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
|
#include "utils.h"
|
||||||
#include "variable.h"
|
#include "variable.h"
|
||||||
|
|
||||||
#include "../testing/core.h"
|
#include "../testing/core.h"
|
||||||
@ -265,14 +266,22 @@ TEST_F(SimpleCommandsTest, Suffix)
|
|||||||
|
|
||||||
BEGIN_HIDE_OUTPUT();
|
BEGIN_HIDE_OUTPUT();
|
||||||
command("suffix one");
|
command("suffix one");
|
||||||
|
command("suffix yes");
|
||||||
END_HIDE_OUTPUT();
|
END_HIDE_OUTPUT();
|
||||||
ASSERT_THAT(lmp->suffix, StrEq("one"));
|
ASSERT_THAT(lmp->suffix, StrEq("one"));
|
||||||
|
ASSERT_EQ(lmp->suffix_enable, 1);
|
||||||
|
ASSERT_THAT(utils::strip_style_suffix("one/four", lmp), StrEq("one/four"));
|
||||||
|
ASSERT_THAT(utils::strip_style_suffix("four/one", lmp), StrEq("four"));
|
||||||
|
|
||||||
BEGIN_HIDE_OUTPUT();
|
BEGIN_HIDE_OUTPUT();
|
||||||
command("suffix hybrid two three");
|
command("suffix hybrid two three");
|
||||||
END_HIDE_OUTPUT();
|
END_HIDE_OUTPUT();
|
||||||
ASSERT_THAT(lmp->suffix, StrEq("two"));
|
ASSERT_THAT(lmp->suffix, StrEq("two"));
|
||||||
ASSERT_THAT(lmp->suffix2, StrEq("three"));
|
ASSERT_THAT(lmp->suffix2, StrEq("three"));
|
||||||
|
ASSERT_THAT(utils::strip_style_suffix("one/four", lmp), StrEq("one/four"));
|
||||||
|
ASSERT_THAT(utils::strip_style_suffix("one/two", lmp), StrEq("one"));
|
||||||
|
ASSERT_THAT(utils::strip_style_suffix("one/three", lmp), StrEq("one"));
|
||||||
|
ASSERT_THAT(utils::strip_style_suffix("four/one", lmp), StrEq("four/one"));
|
||||||
|
|
||||||
BEGIN_HIDE_OUTPUT();
|
BEGIN_HIDE_OUTPUT();
|
||||||
command("suffix four");
|
command("suffix four");
|
||||||
@ -284,11 +293,13 @@ TEST_F(SimpleCommandsTest, Suffix)
|
|||||||
command("suffix off");
|
command("suffix off");
|
||||||
END_HIDE_OUTPUT();
|
END_HIDE_OUTPUT();
|
||||||
ASSERT_EQ(lmp->suffix_enable, 0);
|
ASSERT_EQ(lmp->suffix_enable, 0);
|
||||||
|
ASSERT_THAT(utils::strip_style_suffix("one/four", lmp), StrEq("one/four"));
|
||||||
|
|
||||||
BEGIN_HIDE_OUTPUT();
|
BEGIN_HIDE_OUTPUT();
|
||||||
command("suffix yes");
|
command("suffix yes");
|
||||||
END_HIDE_OUTPUT();
|
END_HIDE_OUTPUT();
|
||||||
ASSERT_EQ(lmp->suffix_enable, 1);
|
ASSERT_EQ(lmp->suffix_enable, 1);
|
||||||
|
ASSERT_THAT(utils::strip_style_suffix("one/four", lmp), StrEq("one"));
|
||||||
|
|
||||||
BEGIN_HIDE_OUTPUT();
|
BEGIN_HIDE_OUTPUT();
|
||||||
command("suffix no");
|
command("suffix no");
|
||||||
|
|||||||
Reference in New Issue
Block a user