FACT++  1.0
vector< Description > Description::SplitDescription ( const std::string &  buffer)
static

This function breaks down a descriptive string into its components. For details see class reference.

Parameters
bufferstring which should be broekn into pieces
Returns
A vector<Description> containing all the descriptions found. The first entry contains the Description members name and comment, corresponding to the service or command name the Description list is for and its corresponding description.

Definition at line 82 of file Description.cc.

References comment, name, Tools::Trim(), and unit.

Referenced by DimDescriptions::HandleServiceDesc(), DimServiceInfoList::infoHandler(), EventImp::Print(), and ServiceList::ProcessServiceList().

83 {
84  const size_t p0 = buffer.find_first_of('=');
85 
86  const string svc = buffer.substr(0, p0);
87  const string desc = buffer.substr(p0+1);
88 
89  const size_t p = desc.find_first_of('|');
90 
91  // Extract a general description
92  const string d = Trim(desc.substr(0, p));
93 
94  vector<Description> vec;
95  vec.emplace_back(svc, d);
96 
97  if (p==string::npos)
98  return vec;
99 
100  string buf;
101  stringstream stream(desc.substr(p+1));
102  while (getline(stream, buf, '|'))
103  {
104  if (buf.empty())
105  continue;
106 
107  const size_t p1 = buf.find_first_of(':');
108 
109  const string comment = p1==string::npos ? "" : buf.substr(p1+1);
110  if (p1!=string::npos)
111  buf.erase(p1);
112 
113  const size_t p2 = buf.find_last_of('[');
114  const size_t p3 = buf.find_last_of(']');
115 
116  const bool hasunit = p2<p3 && p2!=string::npos;
117 
118  const string unit = hasunit ? buf.substr(p2+1, p3-p2-1) : "";
119  const string name = hasunit ? buf.substr(0, p2) : buf;
120 
121  vec.emplace_back(name, comment, unit);
122  }
123 
124  return vec;
125 }
std::string unit
Definition: Description.h:11
std::string name
Definition: Description.h:9
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
std::string comment
Definition: Description.h:10
std::string Trim(const std::string &str)
Definition: tools.cc:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function: