Functions
WireCell::String Namespace Reference

Functions

std::vector< std::stringsplit (const std::string &in, const std::string &delim=":")
 
std::pair< std::string, std::stringparse_pair (const std::string &in, const std::string &delim=":")
 
template<typename TYPE >
boost::format format_flatten (boost::format f, TYPE obj)
 
template<typename TYPE , typename... MORE>
boost::format format_flatten (boost::format start, TYPE o, MORE...objs)
 
boost::format format_flatten (boost::format f)
 
template<typename... TYPES>
std::string format (const std::string &form, TYPES...objs)
 
template<typename T >
std::string stringify (T obj)
 

Function Documentation

template<typename... TYPES>
std::string WireCell::String::format ( const std::string form,
TYPES...  objs 
)

The format() function provides an sprintf() like function. It's a wrapper on boost::format() but returns a string instead of a stream and has function calling semantics instead of the "%" list. Use like:

int a=42; std::string foo = "bar"; std::string msg = format("the answer to %s is %d", foo, a);

Definition at line 45 of file String.h.

45  {
46  auto final = format_flatten(boost::format(form), objs...);
47  std::stringstream ss;
48  ss << final;
49  return ss.str();
50  }
boost::format format_flatten(boost::format f)
Definition: String.h:30
std::string format(const std::string &form, TYPES...objs)
Definition: String.h:45
template<typename TYPE >
boost::format WireCell::String::format_flatten ( boost::format  f,
TYPE  obj 
)

Definition at line 22 of file String.h.

22  {
23  return f % obj;
24  }
template<typename TYPE , typename... MORE>
boost::format WireCell::String::format_flatten ( boost::format  start,
TYPE  o,
MORE...  objs 
)

Definition at line 26 of file String.h.

26  {
27  auto next = start % o;
28  return format_flatten(next, objs...);
29  }
boost::format format_flatten(boost::format f)
Definition: String.h:30
boost::format WireCell::String::format_flatten ( boost::format  f)
inline

Definition at line 30 of file String.h.

30  {
31  return f;
32  }
std::pair< std::string, std::string > WireCell::String::parse_pair ( const std::string in,
const std::string delim = ":" 
)

Definition at line 15 of file String.cxx.

16 {
17  vector<string> chunks = split(in, delim);
18 
19  string first = chunks[0];
20  string second = "";
21  if (chunks.size() > 1) {
22  second = chunks[1];
23  }
24  return make_pair(first, second);
25 }
string delim()
Definition: fcldump.cxx:41
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:80
std::vector< std::string > WireCell::String::split ( const std::string in,
const std::string delim = ":" 
)

Definition at line 5 of file String.cxx.

6 {
7  vector<string> chunks;
8  if (in.empty()) {
9  return chunks;
10  }
11  boost::split(chunks, in, boost::is_any_of(delim), boost::token_compress_on);
12  return chunks;
13 }
string delim()
Definition: fcldump.cxx:41
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
template<typename T >
std::string WireCell::String::stringify ( obj)

Definition at line 55 of file String.h.

55  {
56  std::stringstream ss;
57  ss << obj;
58  return ss.str();
59  }