Unverified Commit 6a9073a0 authored by Richard Berger's avatar Richard Berger
Browse files

Add count_words for C-Strings

parent 645d3b61
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -365,12 +365,12 @@ std::string utils::trim_comment(const std::string & line) {
}

/* ----------------------------------------------------------------------
   Return number of words
   return number of words
------------------------------------------------------------------------- */

size_t utils::count_words(const std::string & text) {
size_t utils::count_words(const char * text) {
  size_t count = 0;
  const char * buf = text.c_str();
  const char * buf = text;
  char c = *buf;

  while (c) {
@@ -393,6 +393,14 @@ size_t utils::count_words(const std::string & text) {
  return count;
}

/* ----------------------------------------------------------------------
   return number of words
------------------------------------------------------------------------- */

size_t utils::count_words(const std::string & text) {
  return utils::count_words(text.c_str());
}

/* ----------------------------------------------------------------------
   Return number of words
------------------------------------------------------------------------- */
+8 −0
Original line number Diff line number Diff line
@@ -166,6 +166,14 @@ namespace LAMMPS_NS {
     */
    size_t count_words(const std::string & text);

    /**
     * \brief Count words in C-string, ignore any whitespace matching " \t\r\n\f"
     * \param text string that should be searched
     * \param separators string containing characters that will be treated as whitespace
     * \return number of words found
     */
    size_t count_words(const char * text);

    /**
     * \brief Count words in a single line, trim anything from '#' onward
     * \param text string that should be trimmed and searched