Changeset 13221 for trunk/FACT++


Ignore:
Timestamp:
03/26/12 08:46:02 (13 years ago)
Author:
tbretz
Message:
Added TrimQuotes
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/tools.cc

    r13168 r13221  
    7676// --------------------------------------------------------------------------
    7777//
     78//! This is a static helper to remove leading and trailing whitespaces and
     79//! if available leading and trailing quotes, can be either ' or "
     80//!
     81//! @param buf
     82//!    a pointer to the char array to be trimmed
     83//!
     84//! @returns
     85//!    a std::string with the content trimmed
     86//
     87string Tools::TrimQuotes(const string &str)
     88{
     89    string rc = Trim(str);
     90    if (rc.length()<2)
     91        return rc;
     92
     93    const char b = rc[0];
     94    const char e = rc[rc.length()-1];
     95
     96    if ((b=='\"' && e=='\"') || (b=='\'' && e=='\''))
     97        return rc.substr(1, rc.length()-2);
     98
     99    return rc;
     100}
     101
     102// --------------------------------------------------------------------------
     103//
    78104//! This is a static helper to remove leading and trailing whitespaces.
    79105//!
  • trunk/FACT++/src/tools.h

    r13168 r13221  
    99    std::string Form(const char *fmt, ...);
    1010    std::string Trim(const std::string &str);
     11    std::string TrimQuotes(const std::string &str);
    1112    std::string Wrap(std::string &str, size_t width=78);
    1213}
Note: See TracChangeset for help on using the changeset viewer.