TF++, Miscellaneous classes and modules in C++:

◆ trimws()

std::string tfxx::string::trimws ( std::string  s)

function #tf::trimws#: Erase leading and trailing whitespace from a string. This in fact is an inline adapter to trimws_begin# and trimws_end#.

Returns
string with leading and trailing whitespace removed
Parameters
sstring to remove leading and trailing whitespace from
Author
Thomas Forbriger
Version
V1.0 (#$Revision: 1.4 $
Date
2009-11-11 12:34:04

#) remove leading and trailing whitespace

See also
trimws_begin
trimws_end

Definition at line 51 of file stringfunc.cc.

52  {
53  if (s.length()>0)
54  {
55  std::string::size_type ib=s.find_first_not_of(" ", 0);
56  if (ib==std::string::npos)
57  {
58  s="";
59  }
60  else
61  {
62  std::string::size_type il=s.find_last_not_of(" \r", s.length());
63  std::string::size_type n=il>=ib ? il-ib+1 : 0;
64  if (n==0) { ib = 0; }
65  if ((ib!=0) || (n!=s.length())) { s=s.substr(ib,n); }
66  }
67  }
68  return(s);
69  } // std::string trimws(std::string s)