Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Friends | List of all members
JLANG::JString Class Reference

Wrapper class around STL string class. More...

#include <JString.hh>

Inheritance diagram for JLANG::JString:

Public Member Functions

 JString ()
 Default constructor. More...
 
 JString (const std::string &buffer)
 Constructor. More...
 
 JString (const char c)
 Constructor. More...
 
 JString (const char *buffer, const std::string::size_type length)
 Constructor. More...
 
template<class T >
 JString (const T &value)
 Constructor. More...
 
template<class... Args>
 JString (const char *format, const Args &...args)
 Constructor. More...
 
 JString (const JString &buffer, const JStringFacet &facet)
 Constructor. More...
 
JStringcompile (const JStringFacet &facet)
 Compile token with given facet. More...
 
bool startsWith (const std::string &prefix) const
 Test if this string starts with the specified prefix. More...
 
bool endsWith (const std::string &suffix) const
 Test if this string ends with the specified suffix. More...
 
JStringreplace (const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
 Replace characters. More...
 
JStringreplace (const std::string &target, const std::string &replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
 Replace character sequences. More...
 
template<class T >
JStringreplace (const std::string &target, const T &value, const std::size_t max=std::numeric_limits< std::size_t >::max())
 Replace character sequence. More...
 
JStringtrim ()
 Trim string. More...
 
JStringtrim (const char c)
 Trim string. More...
 
JString trim (const std::string &target)
 Trim string. More...
 
JStringtoUpper ()
 Convert all character to upper case. More...
 
JStringtoLower ()
 Convert all character to lower case. More...
 
template<class T >
JStringassign (T &output)
 Assign (part of) string to value. More...
 

Static Public Member Functions

static JString valueOf (const int input)
 Convert enumeration type to string. More...
 
template<class T >
static JString valueOf (const T &input)
 Convert value to string. More...
 
template<class T >
static const TtoValue (const JString &input)
 Convert string to value. More...
 

Private Member Functions

template<class T , class... Args>
void __set__ (const T &value, const Args &...args)
 Recursive method for formatting string. More...
 
void __set__ () const
 Termination method for formatting string. More...
 

Friends

std::istream & operator>> (std::istream &in, JString &object)
 Read string from input stream. More...
 
std::ostream & operator<< (std::ostream &out, const JString &object)
 Write string to output stream. More...
 

Detailed Description

Wrapper class around STL string class.

Definition at line 27 of file JString.hh.

Constructor & Destructor Documentation

JLANG::JString::JString ( )
inline

Default constructor.

Definition at line 39 of file JString.hh.

39  :
40  std::string()
41  {}
JLANG::JString::JString ( const std::string &  buffer)
inlineexplicit

Constructor.

Parameters
bufferstring

Definition at line 49 of file JString.hh.

49  :
50  std::string(buffer)
51  {}
JLANG::JString::JString ( const char  c)
inlineexplicit

Constructor.

Parameters
cchar

Definition at line 59 of file JString.hh.

59  :
60  std::string(1,c)
61  {}
JLANG::JString::JString ( const char *  buffer,
const std::string::size_type  length 
)
inlineexplicit

Constructor.

Parameters
bufferstring
lengthlength

Definition at line 70 of file JString.hh.

70  :
71  std::string(buffer, length)
72  {}
template<class T >
JLANG::JString::JString ( const T value)
inline

Constructor.

Parameters
valuevalue

Definition at line 81 of file JString.hh.

81  :
82  std::string(valueOf(value))
83  {}
static JString valueOf(const int input)
Convert enumeration type to string.
Definition: JString.hh:303
template<class... Args>
JLANG::JString::JString ( const char *  format,
const Args &...  args 
)
inline

Constructor.


Each '' in the format string will be replaced by the corresponding argument.

Parameters
formatformat
argsvalues

Definition at line 94 of file JString.hh.

94  :
95  std::string(format)
96  {
97  __set__(args...);
98  }
void __set__() const
Termination method for formatting string.
Definition: JString.hh:466
JLANG::JString::JString ( const JString buffer,
const JStringFacet facet 
)
inline

Constructor.


This constructor compiles (see below) the input string.

Parameters
bufferinput string
facetfacet

Definition at line 108 of file JString.hh.

108  :
109  std::string(buffer)
110  {
111  compile(facet);
112  }
JString & compile(const JStringFacet &facet)
Compile token with given facet.
Definition: JString.hh:123

Member Function Documentation

JString& JLANG::JString::compile ( const JStringFacet facet)
inline

Compile token with given facet.


This method uses the given facet to parse the input string. The result is then compatible with the definition of a token and may be empty.

Parameters
facetfacet
Returns
this string

Definition at line 123 of file JString.hh.

124  {
125  using namespace std;
126 
127  istringstream is(*this);
128 
129  ios_base::iostate state;
130 
131  facet.get(is, istreambuf_iterator<char>(), is, state, *this);
132 
133  return *this;
134  }
is
Definition: JDAQCHSM.chsm:167
istreambuf_iterator get(const istreambuf_iterator __begin, const istreambuf_iterator __end, const std::ios_base &format, std::ios_base::iostate &result, std::string &buffer) const
Get string.
Definition: JStringFacet.hh:70
bool JLANG::JString::startsWith ( const std::string &  prefix) const
inline

Test if this string starts with the specified prefix.

Parameters
prefixprefix
Returns
true if this string starts with prefix; else false

Definition at line 144 of file JString.hh.

145  {
146  return this->size() >= prefix.size() && this->substr(0, prefix.size()) == prefix;
147  }
bool JLANG::JString::endsWith ( const std::string &  suffix) const
inline

Test if this string ends with the specified suffix.

Parameters
suffixsuffix
Returns
true if this string ends with suffix; else false

Definition at line 156 of file JString.hh.

157  {
158  return this->size() >= suffix.size() && this->substr(this->size() - suffix.size()) == suffix;
159  }
JString& JLANG::JString::replace ( const char  target,
const char  replacement,
const std::size_t  max = std::numeric_limits<std::size_t>::max() 
)
inline

Replace characters.

Parameters
targettarget character
replacementreplacement character
maxmaximum number of replacements
Returns
this string

Definition at line 170 of file JString.hh.

173  {
174  for (std::size_t i = this->find(target), n = max; i != std::string::npos && n != 0; i = find(target,i), --n) {
175  (*this)[i] = replacement;
176  }
177 
178  return *this;
179  }
alias put_queue eval echo n
Definition: qlib.csh:19
JString& JLANG::JString::replace ( const std::string &  target,
const std::string &  replacement,
const std::size_t  max = std::numeric_limits<std::size_t>::max() 
)
inline

Replace character sequences.

Parameters
targettarget string
replacementreplacement string
maxmaximum number of replacements
Returns
this string

Definition at line 190 of file JString.hh.

193  {
194  for (std::size_t i = this->find(target), n = max; i != std::string::npos && n != 0; i = this->find(target,i), --n) {
195  replace(this->begin() + i, this->begin() + i + target.length(), replacement);
196  }
197 
198  return *this;
199  }
alias put_queue eval echo n
Definition: qlib.csh:19
JString & replace(const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
Replace characters.
Definition: JString.hh:170
template<class T >
JString& JLANG::JString::replace ( const std::string &  target,
const T value,
const std::size_t  max = std::numeric_limits<std::size_t>::max() 
)
inline

Replace character sequence.

Parameters
targettarget string
valuevalue
maxmaximum number of replacements
Returns
this string

Definition at line 211 of file JString.hh.

214  {
215  for (std::size_t i = this->find(target), n = max; i != std::string::npos && n != 0; i = this->find(target,i), --n) {
216  replace(this->begin() + i, this->begin() + i + target.length(), JString(value));
217  }
218 
219  return *this;
220  }
JString()
Default constructor.
Definition: JString.hh:39
alias put_queue eval echo n
Definition: qlib.csh:19
JString & replace(const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
Replace characters.
Definition: JString.hh:170
JString& JLANG::JString::trim ( )
inline

Trim string.


Returns the modified string, with leading and trailing white spaces omitted.

Returns
this string

Definition at line 229 of file JString.hh.

230  {
231  *this = JLANG::trim(*this);
232 
233  return *this;
234  }
std::string trim(const std::string &buffer)
Trim string.
Definition: JLangToolkit.hh:79
JString& JLANG::JString::trim ( const char  c)
inline

Trim string.


Returns the modified string, with leading and trailing target characters omitted.

Parameters
cstrip character
Returns
this string

Definition at line 244 of file JString.hh.

245  {
246  *this = JLANG::trim(*this, c);
247 
248  return *this;
249  }
std::string trim(const std::string &buffer)
Trim string.
Definition: JLangToolkit.hh:79
JString JLANG::JString::trim ( const std::string &  target)
inline

Trim string.


Returns the modified string, with leading and trailing target characters omitted.

Parameters
targetcharacter(s) to strip
Returns
this string

Definition at line 259 of file JString.hh.

260  {
261  *this = JLANG::trim(*this, target);
262 
263  return *this;
264  }
std::string trim(const std::string &buffer)
Trim string.
Definition: JLangToolkit.hh:79
JString& JLANG::JString::toUpper ( )
inline

Convert all character to upper case.

Returns
this string

Definition at line 272 of file JString.hh.

273  {
274  for (iterator i = begin(); i != end(); ++i) {
275  *i = toupper(*i);
276  }
277 
278  return *this;
279  }
JString& JLANG::JString::toLower ( )
inline

Convert all character to lower case.

Returns
this string

Definition at line 287 of file JString.hh.

288  {
289  for (iterator i = begin(); i != end(); ++i) {
290  *i = tolower(*i);
291  }
292 
293  return *this;
294  }
static JString JLANG::JString::valueOf ( const int  input)
inlinestatic

Convert enumeration type to string.

Parameters
inputvalue
Returns
string

Definition at line 303 of file JString.hh.

304  {
305  std::ostringstream os;
306 
307  if (os << input)
308  return JString(os.str());
309  else
310  throw JException("JString::valueOf()");
311  }
General exception.
Definition: JException.hh:23
JString()
Default constructor.
Definition: JString.hh:39
template<class T >
static JString JLANG::JString::valueOf ( const T input)
inlinestatic

Convert value to string.

Parameters
inputvalue
Returns
string

Definition at line 321 of file JString.hh.

322  {
323  std::ostringstream os;
324 
325  if (os << input)
326  return JString(os.str());
327  else
328  throw JException("JString::valueOf()");
329  }
General exception.
Definition: JException.hh:23
JString()
Default constructor.
Definition: JString.hh:39
template<class T >
static const T& JLANG::JString::toValue ( const JString input)
inlinestatic

Convert string to value.

Parameters
inputstring
Returns
value

Definition at line 339 of file JString.hh.

340  {
341  static T value;
342 
343  std::istringstream is(input);
344 
345  if (is >> value)
346  return value;
347  else
348  throw JException("JString::toValue<T>()");
349  }
General exception.
Definition: JException.hh:23
is
Definition: JDAQCHSM.chsm:167
do set_variable OUTPUT_DIRECTORY $WORKDIR T
template<class T >
JString& JLANG::JString::assign ( T output)
inline

Assign (part of) string to value.

Parameters
outputvalue
Returns
remaining string

Definition at line 359 of file JString.hh.

360  {
361  using namespace std;
362 
363  istringstream is(*this);
364 
365  is >> output;
366 
367  if (!is) {
368  throw JException("JString::assign()");
369  }
370 
371  this->assign(istreambuf_iterator<char>(is),
372  istreambuf_iterator<char>());
373 
374  return *this;
375  }
General exception.
Definition: JException.hh:23
is
Definition: JDAQCHSM.chsm:167
JString & assign(T &output)
Assign (part of) string to value.
Definition: JString.hh:359
template<class T , class... Args>
void JLANG::JString::__set__ ( const T value,
const Args &...  args 
)
inlineprivate

Recursive method for formatting string.

Parameters
valuenext value
argsremaining values

Definition at line 448 of file JString.hh.

449  {
450  using namespace std;
451 
452  const size_t pos = this->find('%');
453 
454  if (pos != string::npos) {
455 
456  replace(pos, 1, JString::valueOf(value));
457 
458  __set__(args...);
459  }
460  }
void __set__() const
Termination method for formatting string.
Definition: JString.hh:466
static JString valueOf(const int input)
Convert enumeration type to string.
Definition: JString.hh:303
JString & replace(const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
Replace characters.
Definition: JString.hh:170
void JLANG::JString::__set__ ( ) const
inlineprivate

Termination method for formatting string.

Definition at line 466 of file JString.hh.

467  {}

Friends And Related Function Documentation

std::istream& operator>> ( std::istream &  in,
JString object 
)
friend

Read string from input stream.

Parameters
ininput stream
objectstring
Returns
input stream

Definition at line 385 of file JString.hh.

386  {
387  using namespace std;
388 
389  istream::sentry sentry(in); // skips white spaces
390 
391  if (sentry) {
392 
393  const locale& loc = in.getloc();
394 
395  if (has_facet<JStringFacet>(loc)) {
396 
397  ios_base::iostate state;
398 
399  use_facet<JStringFacet>(loc).get(in, istreambuf_iterator<char>(), in, state, object);
400 
401  if (state != ios_base::goodbit && state != ios_base::eofbit) {
402  in.setstate(state);
403  }
404 
405  } else {
406 
407  in >> static_cast<string&>(object);
408  }
409  }
410 
411  return in;
412  }
char * loc(char *orig)
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
std::ostream& operator<< ( std::ostream &  out,
const JString object 
)
friend

Write string to output stream.

Parameters
outoutput stream
objectstring
Returns
output stream

Definition at line 422 of file JString.hh.

423  {
424  using namespace std;
425 
426  const locale& loc = out.getloc();
427 
428  if (has_facet<JStringFacet>(loc)) {
429 
430  use_facet<JStringFacet>(loc).put(out, out, out.fill(), object);
431 
432  } else {
433 
434  out << static_cast<const string&>(object);
435  }
436 
437  return out;
438  }
char * loc(char *orig)

The documentation for this class was generated from the following file: