TAPs 0.7.7.3
TAPsStringManipulator.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsStringManipulator.cpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (03/29/2010)
00009 UPDATE          (03/30/2010)
00010 ******************************************************************************/
00011 #include "TAPsStringManipulator.hpp"
00012 // Using Inclusion Model (i.e. definitions are included in declarations)
00013 //                       (this name.cpp is included in name.hpp)
00014 // Each friend is defined directly inside its declaration.
00015 
00016 BEGIN_NAMESPACE_TAPs
00017 //=============================================================================
00018 //-----------------------------------------------------------------------------
00019 
00020 //-----------------------------------------------------------------------------
00021 std::string StringManipulator::StripOutComment (
00022     std::string const & str,    
00023     char delimiter              
00024 )
00025 {
00026     return str.substr( 0, str.find_first_of( delimiter ) );
00027 }
00028 
00029 //-----------------------------------------------------------------------------
00030 void StringManipulator::BreakString (
00031     std::string const & origstr,    
00032     std::string & substr1,          
00033     std::string & substr2,          
00034     std::string const & delimiters  
00035 )
00036 {
00037     int b = origstr.find_first_not_of( delimiters );
00038     if ( b == -1 ) {
00039         b = 0;
00040     }
00041     int e = origstr.find_first_of( delimiters, b );
00042     if ( e != -1 ) {
00043         if ( b == e ) {
00044             substr1 = origstr;
00045             substr2 = "";
00046         }
00047         else {
00048             substr1 = origstr.substr( b, e-b );
00049             substr2 = origstr.substr( e );
00050         }
00051     }
00052     else {
00053         substr1 = origstr.substr( b );
00054         substr2 = "";
00055     }
00056 }
00057 
00058 //-----------------------------------------------------------------------------
00059 template <typename T>
00060 void StringManipulator::ConvertStrToVar ( std::string const & str, T & var )
00061 {
00062     std::stringstream ss( str );
00063     ss >> var;
00064 }
00065 //-----------------------------------------------------------------------------
00066 template <typename T>
00067 void StringManipulator::ConvertVarToStr ( T const & var, std::string & str )
00068 {
00069     std::stringstream ss;
00070     ss << var;
00071     str = ss.str();
00072 }
00073 //=============================================================================
00074 END_NAMESPACE_TAPs
00075 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00076 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines