INET Framework for OMNeT++/OMNEST
inet::StringFormat Class Reference

#include <StringFormat.h>

Classes

class  IDirectiveResolver
 

Public Member Functions

void parseFormat (const char *format)
 
const char * formatString (IDirectiveResolver *resolver) const
 
const char * formatString (std::function< const char *(char)> &resolver) const
 

Static Public Member Functions

static const char * formatString (const char *format, const IDirectiveResolver *resolver)
 
static const char * formatString (const char *format, const std::function< const char *(char)> resolver)
 

Protected Attributes

std::string format
 

Member Function Documentation

◆ formatString() [1/4]

const char * inet::StringFormat::formatString ( const char *  format,
const IDirectiveResolver resolver 
)
static
28 {
29  return formatString(format, [&] (char directive) { return resolver->resolveDirective(directive); });
30 }

◆ formatString() [2/4]

const char * inet::StringFormat::formatString ( const char *  format,
const std::function< const char *(char)>  resolver 
)
static
33 {
34  static std::string result;
35  result.clear();
36  int current = 0;
37  int previous = current;
38  while (true) {
39  char ch = format[current];
40  if (ch == '\0') {
41  if (previous != current)
42  result.append(format + previous, current - previous);
43  break;
44  }
45  else if (ch == '%') {
46  if (previous != current)
47  result.append(format + previous, current - previous);
48  previous = current;
49  current++;
50  ch = format[current];
51  if (ch == '%')
52  result.append(format + previous, current - previous);
53  else
54  result.append(resolver(ch));
55  previous = current + 1;
56  }
57  current++;
58  }
59  return result.c_str();
60 }

◆ formatString() [3/4]

◆ formatString() [4/4]

const char * inet::StringFormat::formatString ( std::function< const char *(char)> &  resolver) const
23 {
24  return formatString(format.c_str(), resolver);
25 }

◆ parseFormat()

Member Data Documentation

◆ format

std::string inet::StringFormat::format
protected

Referenced by formatString(), and parseFormat().


The documentation for this class was generated from the following files:
inet::StringFormat::format
std::string format
Definition: StringFormat.h:26
inet::StringFormat::formatString
const char * formatString(IDirectiveResolver *resolver) const
Definition: StringFormat.cc:17