This is Unofficial EPICS BASE Doxygen Site
epics::pvData::escape Struct Reference

#include "typeCast.h"

Public Types

enum  style_t { C, CSV }
 

Public Member Functions

 escape (const std::string &orig)
 
 ~escape ()
 
escapestyle (style_t s)
 Change escaping style. More...
 
std::string str () const
 print to string and return. (alloc and copy) More...
 

Friends

epicsShareFunc std::ostream & operator<< (std::ostream &strm, const escape &Q)
 

Detailed Description

Helper to print a string with escaping

strm<<'"'<<escape(astring)<<'"'

Definition at line 218 of file typeCast.h.

Member Enumeration Documentation

Enumerator
CSV 

Definition at line 220 of file typeCast.h.

220  {
221  C, // default
222  CSV, // a la RFC4180
223  };

Constructor & Destructor Documentation

epics::pvData::escape::escape ( const std::string &  orig)
inline

Definition at line 228 of file typeCast.h.

228 :orig(orig), S(C) {}
epics::pvData::escape::~escape ( )

Definition at line 472 of file printer.cpp.

472 {}

Member Function Documentation

std::string epics::pvData::escape::str ( ) const

print to string and return. (alloc and copy)

Definition at line 474 of file printer.cpp.

475 {
476  std::ostringstream strm;
477  strm<<(*this);
478  return strm.str();
479 }
escape& epics::pvData::escape::style ( style_t  s)
inline

Change escaping style.

Definition at line 231 of file typeCast.h.

231 { S = s; return *this; }

Friends And Related Function Documentation

epicsShareFunc std::ostream& operator<< ( std::ostream &  strm,
const escape Q 
)
friend

Definition at line 482 of file printer.cpp.

483 {
484  for(size_t pos = 0, len = Q.orig.size(); pos < len; pos++) {
485  const char C = Q.orig[pos];
486  char quote = '\\', next;
487  // compare me with epicsStrnEscapedFromRaw()
488  switch(C) {
489  case '\a': next = 'a'; break;
490  case '\b': next = 'b'; break;
491  case '\f': next = 'f'; break;
492  case '\n': next = 'n'; break;
493  case '\r': next = 'r'; break;
494  case '\t': next = 't'; break;
495  case '\v': next = 'v'; break;
496  case '\\': next = '\\'; break;
497  case '\'': next = '\''; break;
498  case '\"': next = '\"'; if(Q.S==escape::CSV) quote = '"'; break;
499  default:
500  if(!isprint(C)) {
501  // print three charator escape
502  strm<<"\\x"<<hexdigit(C>>4)<<hexdigit(C);
503  } else {
504  // literal
505  strm.put(C);
506  }
507  continue;
508  }
509  // print two charactor escape
510  strm.put(quote);
511  strm.put(next);
512  }
513 
514  return strm;
515 }
#define quote(v)

The documentation for this struct was generated from the following files: