Wrapper class around STL string class.  
 More...
#include <JString.hh>
 | 
|   | JString () | 
|   | Default constructor.  
  | 
|   | 
|   | JString (const std::string &buffer) | 
|   | Constructor.  
  | 
|   | 
|   | JString (const char c) | 
|   | Constructor.  
  | 
|   | 
|   | JString (const char *buffer, const std::string::size_type length) | 
|   | Constructor.  
  | 
|   | 
| template<class T >  | 
|   | JString (const T &value) | 
|   | Constructor.  
  | 
|   | 
| template<class ... Args>  | 
|   | JString (const char *format, const Args &...args) | 
|   | Constructor.  
  | 
|   | 
|   | JString (const JString &buffer, const JStringFacet &facet) | 
|   | Constructor.  
  | 
|   | 
| JString &  | compile (const JStringFacet &facet) | 
|   | Compile token with given facet.  
  | 
|   | 
| bool  | startsWith (const std::string &prefix) const | 
|   | Test if this string starts with the specified prefix.  
  | 
|   | 
| bool  | endsWith (const std::string &suffix) const | 
|   | Test if this string ends with the specified suffix.  
  | 
|   | 
| JString &  | replace (const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max()) | 
|   | Replace characters.  
  | 
|   | 
| JString &  | replace (const std::string &target, const std::string &replacement, const std::size_t max=std::numeric_limits< std::size_t >::max()) | 
|   | Replace character sequences.  
  | 
|   | 
| template<class T >  | 
| JString &  | replace (const std::string &target, const T &value, const std::size_t max=std::numeric_limits< std::size_t >::max()) | 
|   | Replace character sequence.  
  | 
|   | 
| JString &  | trim () | 
|   | Trim string.  
  | 
|   | 
| JString &  | trim (const char c) | 
|   | Trim string.  
  | 
|   | 
| JString  | trim (const std::string &target) | 
|   | Trim string.  
  | 
|   | 
| JString &  | toUpper () | 
|   | Convert all character to upper case.  
  | 
|   | 
| JString &  | toLower () | 
|   | Convert all character to lower case.  
  | 
|   | 
| template<class T >  | 
| JString &  | assign (T &output) | 
|   | Assign (part of) string to value.  
  | 
|   | 
 | 
| static JString  | valueOf (const int input) | 
|   | Convert enumeration type to string.  
  | 
|   | 
| template<class T >  | 
| static JString  | valueOf (const T &input) | 
|   | Convert value to string.  
  | 
|   | 
| template<class T >  | 
| static const T &  | toValue (const JString &input) | 
|   | Convert string to value.  
  | 
|   | 
 | 
| template<class T , class ... Args>  | 
| void  | __set__ (const T &value, const Args &...args) | 
|   | Recursive method for formatting string.  
  | 
|   | 
| void  | __set__ () const | 
|   | Termination method for formatting string.  
  | 
|   | 
 | 
| std::istream &  | operator>> (std::istream &in, JString &object) | 
|   | Read string from input stream.  
  | 
|   | 
| std::ostream &  | operator<< (std::ostream &out, const JString &object) | 
|   | Write string to output stream.  
  | 
|   | 
Wrapper class around STL string class. 
Definition at line 27 of file JString.hh.
 
◆ JString() [1/7]
  
  
      
        
          | JLANG::JString::JString  | 
          ( | 
           | ) | 
           | 
         
       
   | 
  
inline   | 
  
 
Default constructor. 
Definition at line 39 of file JString.hh.
   39              :
   40      std::string()
   41    {}
 
 
 
◆ JString() [2/7]
  
  
      
        
          | JLANG::JString::JString  | 
          ( | 
          const std::string & |           buffer | ) | 
           | 
         
       
   | 
  
inlineexplicit   | 
  
 
Constructor. 
- Parameters
 - 
  
  
 
Definition at line 49 of file JString.hh.
   49                                              :
   50      std::string(buffer)
   51    {}
 
 
 
◆ JString() [3/7]
  
  
      
        
          | JLANG::JString::JString  | 
          ( | 
          const char |           c | ) | 
           | 
         
       
   | 
  
inlineexplicit   | 
  
 
Constructor. 
- Parameters
 - 
  
  
 
Definition at line 59 of file JString.hh.
   59                                  :
   60      std::string(1,c)
   61    {}
 
 
 
◆ JString() [4/7]
  
  
      
        
          | JLANG::JString::JString  | 
          ( | 
          const char * |           buffer,  | 
         
        
           | 
           | 
          const std::string::size_type |           length ) | 
         
       
   | 
  
inlineexplicit   | 
  
 
Constructor. 
- Parameters
 - 
  
    | buffer | string  | 
    | length | length  | 
  
   
Definition at line 70 of file JString.hh.
   70                                                                          :
   71      std::string(buffer, length)
   72    {}
 
 
 
◆ JString() [5/7]
template<class T > 
  
  
      
        
          | JLANG::JString::JString  | 
          ( | 
          const T & |           value | ) | 
           | 
         
       
   | 
  
inline   | 
  
 
Constructor. 
- Parameters
 - 
  
  
 
Definition at line 81 of file JString.hh.
   81                            :
   83    {}
static JString valueOf(const int input)
Convert enumeration type to string.
 
 
 
 
◆ JString() [6/7]
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
 - 
  
  
 
Definition at line 94 of file JString.hh.
   94                                                     :
   95      std::string(format)
   96    {
   98    }
void __set__() const
Termination method for formatting string.
 
 
 
 
◆ JString() [7/7]
Constructor. 
This constructor compiles (see below) the input string.
- Parameters
 - 
  
    | buffer | input string  | 
    | facet | facet  | 
  
   
Definition at line 108 of file JString.hh.
  108                                                              :
  109      std::string(buffer)
  110    {
  112    }
JString & compile(const JStringFacet &facet)
Compile token with given facet.
 
 
 
 
◆ compile()
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
 - 
  
  
 
- Returns
 - this string 
 
Definition at line 123 of file JString.hh.
  124    {
  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    }
 
 
 
◆ startsWith()
  
  
      
        
          | bool JLANG::JString::startsWith  | 
          ( | 
          const std::string & |           prefix | ) | 
           const | 
         
       
   | 
  
inline   | 
  
 
Test if this string starts with the specified prefix. 
- Parameters
 - 
  
  
 
- 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    }
 
 
 
◆ endsWith()
  
  
      
        
          | bool JLANG::JString::endsWith  | 
          ( | 
          const std::string & |           suffix | ) | 
           const | 
         
       
   | 
  
inline   | 
  
 
Test if this string ends with the specified suffix. 
- Parameters
 - 
  
  
 
- 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    }
 
 
 
◆ replace() [1/3]
  
  
      
        
          | 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
 - 
  
    | target | target character  | 
    | replacement | replacement character  | 
    | max | maximum 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    }
 
 
 
◆ replace() [2/3]
  
  
      
        
          | 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
 - 
  
    | target | target string  | 
    | replacement | replacement string  | 
    | max | maximum 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    }
JString & replace(const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
Replace characters.
 
 
 
 
◆ replace() [3/3]
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
 - 
  
    | target | target string  | 
    | value | value  | 
    | max | maximum 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.
 
 
 
 
◆ trim() [1/3]
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    {
  232 
  233      return *this;
  234    }
std::string trim(const std::string &buffer)
Trim string.
 
 
 
 
◆ trim() [2/3]
  
  
      
        
          | JString & JLANG::JString::trim  | 
          ( | 
          const char |           c | ) | 
           | 
         
       
   | 
  
inline   | 
  
 
Trim string. 
Returns the modified string, with leading and trailing target characters omitted.
- Parameters
 - 
  
  
 
- Returns
 - this string 
 
Definition at line 244 of file JString.hh.
  245    {
  247 
  248      return *this;
  249    }
 
 
 
◆ trim() [3/3]
  
  
      
        
          | JString JLANG::JString::trim  | 
          ( | 
          const std::string & |           target | ) | 
           | 
         
       
   | 
  
inline   | 
  
 
Trim string. 
Returns the modified string, with leading and trailing target characters omitted.
- Parameters
 - 
  
    | target | character(s) to strip  | 
  
   
- Returns
 - this string 
 
Definition at line 259 of file JString.hh.
  260    {
  262 
  263      return *this;
  264    }
 
 
 
◆ toUpper()
  
  
      
        
          | 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    }
 
 
 
◆ toLower()
  
  
      
        
          | 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    }
 
 
 
◆ valueOf() [1/2]
  
  
      
        
          | static JString JLANG::JString::valueOf  | 
          ( | 
          const int |           input | ) | 
           | 
         
       
   | 
  
inlinestatic   | 
  
 
Convert enumeration type to string. 
- Parameters
 - 
  
  
 
- Returns
 - string 
 
Definition at line 303 of file JString.hh.
  304    {
  305      std::ostringstream os;
  306 
  307      if (os << input)
  309      else
  310        THROW(JException, 
"JString::valueOf()");
 
  311    }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
 
 
 
 
◆ valueOf() [2/2]
template<class T > 
  
  
      
        
          | static JString JLANG::JString::valueOf  | 
          ( | 
          const T & |           input | ) | 
           | 
         
       
   | 
  
inlinestatic   | 
  
 
Convert value to string. 
- Parameters
 - 
  
  
 
- Returns
 - string 
 
Definition at line 321 of file JString.hh.
  322    {
  323      std::ostringstream os;
  324 
  325      if (os << input)
  327      else
  328        THROW(JException, 
"JString::valueOf()");
 
  329    }
 
 
 
◆ toValue()
template<class T > 
  
  
      
        
          | static const T & JLANG::JString::toValue  | 
          ( | 
          const JString & |           input | ) | 
           | 
         
       
   | 
  
inlinestatic   | 
  
 
Convert string to value. 
- Parameters
 - 
  
  
 
- 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    }
 
 
 
◆ assign()
template<class T > 
  
  
      
        
          | JString & JLANG::JString::assign  | 
          ( | 
          T & |           output | ) | 
           | 
         
       
   | 
  
inline   | 
  
 
Assign (part of) string to value. 
- Parameters
 - 
  
  
 
- Returns
 - remaining string 
 
Definition at line 359 of file JString.hh.
  360    {
  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    }
JString & assign(T &output)
Assign (part of) string to value.
 
 
 
 
◆ __set__() [1/2]
template<class T , class ... Args> 
  
  
      
        
          | void JLANG::JString::__set__  | 
          ( | 
          const T & |           value,  | 
         
        
           | 
           | 
          const Args &... |           args ) | 
         
       
   | 
  
inlineprivate   | 
  
 
Recursive method for formatting string. 
- Parameters
 - 
  
    | value | next value  | 
    | args | remaining values  | 
  
   
Definition at line 448 of file JString.hh.
  449    {
  451 
  452      const size_t pos = this->find('%');
  453 
  454      if (pos != string::npos) {
  455 
  457 
  459      }
  460    }
 
 
 
◆ __set__() [2/2]
  
  
      
        
          | void JLANG::JString::__set__  | 
          ( | 
           | ) | 
           const | 
         
       
   | 
  
inlineprivate   | 
  
 
Termination method for formatting string. 
Definition at line 466 of file JString.hh.
 
 
◆ operator>>
  
  
      
        
          | std::istream & operator>>  | 
          ( | 
          std::istream & |           in,  | 
         
        
           | 
           | 
          JString & |           object ) | 
         
       
   | 
  
friend   | 
  
 
Read string from input stream. 
- Parameters
 - 
  
    | in | input stream  | 
    | object | string  | 
  
   
- Returns
 - input stream 
 
Definition at line 385 of file JString.hh.
  386    {
  388 
  389      istream::sentry sentry(in);   
  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    }
 
 
 
◆ operator<<
  
  
      
        
          | std::ostream & operator<<  | 
          ( | 
          std::ostream & |           out,  | 
         
        
           | 
           | 
          const JString & |           object ) | 
         
       
   | 
  
friend   | 
  
 
Write string to output stream. 
- Parameters
 - 
  
    | out | output stream  | 
    | object | string  | 
  
   
- Returns
 - output stream 
 
Definition at line 422 of file JString.hh.
  423    {
  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    }
 
 
 
The documentation for this class was generated from the following file: