Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

string.hh

00001 /*
00002 *  Name:      string.hh
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Tools for TString
00005 *  Date:      $Date: 2003/04/14 00:18:32 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #ifndef _MPCL_TEXT_STRING__
00027 #define _MPCL_TEXT_STRING__
00028 
00029 #include <algorithm>
00030 #include "basic_string.hh"
00031 
00032 
00034 namespace mpcl
00035 {
00036   
00038   namespace text
00039   {
00040 
00041     //
00042     //  E X P O R T E D   T Y P E S
00043     //
00044 
00046     typedef TBasicString<char>   TString;
00047 
00048 
00049     //
00050     //  E X P O R T E D   F U N C T I O N S
00051     //
00052 
00060     const char* BoolToString ( bool        gTRUTH             ,
00061                                const char* pkcTRUE  = "true"  ,
00062                                const char* pkcFALSE = "false" );
00063 
00072     TString Format (const char* pkcFORMAT...);
00073 
00081     template <typename TChar, typename TTraits, typename TAllocator>
00082     inline TBasicString<TChar, TTraits, TAllocator>
00083     Lowercase (const std::basic_string<TChar, TTraits, TAllocator>& rkySOURCE)
00084     {
00085 
00086       TBasicString<TChar, TTraits, TAllocator>   yTarget = rkySOURCE;
00087 
00088       std::transform (yTarget.begin(), yTarget.end(), yTarget.begin(), tolower);
00089       return yTarget;
00090 
00091     }  // Lowercase()
00092 
00100     template <typename TChar, typename TTraits, typename TAllocator>
00101     inline TBasicString<TChar, TTraits, TAllocator>
00102     Uppercase (const std::basic_string<TChar, TTraits, TAllocator>& rkySOURCE)
00103     {
00104 
00105       TBasicString<TChar, TTraits, TAllocator>   yTarget = rkySOURCE;
00106 
00107       std::transform (yTarget.begin(), yTarget.end(), yTarget.begin(), toupper);
00108       return yTarget;
00109 
00110     }  // Uppercase()
00111 
00118     template <typename TInputIter, typename TChar, typename TOutputIter>
00119     inline TOutputIter Split ( TInputIter  tBEGIN_ITER  ,
00120                                TInputIter  tEND_ITER    ,
00121                                TChar       tSEPARATOR   ,
00122                                TOutputIter tTARGET_ITER )
00123     {
00124 
00125       TInputIter   tSeparatorIter;
00126       TString      ySubstring;
00127 
00128       while ( tEND_ITER != (tSeparatorIter = std::find (tBEGIN_ITER, tEND_ITER, tSEPARATOR)) )
00129       {
00130         ySubstring = TString (tBEGIN_ITER, tSeparatorIter);
00131         if ( ySubstring.length() )
00132         {
00133           *tTARGET_ITER = ySubstring;
00134           ++tTARGET_ITER;
00135         }
00136         tBEGIN_ITER = tSeparatorIter + 1;
00137       }
00138 
00139       //
00140       //  Add last path item if any.
00141       //
00142       if ( tBEGIN_ITER != tEND_ITER )
00143       {
00144         ySubstring    = TString (tBEGIN_ITER, tEND_ITER);
00145         *tTARGET_ITER = ySubstring;
00146       }
00147       return tTARGET_ITER;
00148 
00149     }  // Split()
00150 
00151   }  // namespace text
00152 
00153 }  // namespace mpcl
00154 
00155 
00156 #endif  // not _MPCL_TEXT_STRING__

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18