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

expandlib-cmd-abbr.h

Go to the documentation of this file.
00001 
00002 /* This file is part of Expandlib.
00003 
00004   Copyright (C) 2002 Jasper van de Gronde
00005 
00006   This software is provided 'as-is', without any express or implied
00007   warranty.  In no event will the authors be held liable for any damages
00008   arising from the use of this software.
00009 
00010   Permission is granted to anyone to use this software for any purpose,
00011   including commercial applications, and to alter it and redistribute it
00012   freely, subject to the following restrictions:
00013 
00014   1. The origin of this software must not be misrepresented; you must not
00015      claim that you wrote the original software. If you use this software
00016      in a product, an acknowledgment in the product documentation would be
00017      appreciated but is not required.
00018   2. Altered source versions must be plainly marked as such, and must not be
00019      misrepresented as being the original software.
00020   3. This notice may not be removed or altered from any source distribution.
00021 
00022   Jasper van de Gronde th.v.d.gronde@hccnet.nl
00023 
00024 */
00025 
00030 #ifndef EXPANDLIB_CMD_ABBR_H_INCLUDED
00031 #define EXPANDLIB_CMD_ABBR_H_INCLUDED
00032 
00033 #include <boost/lexical_cast.hpp>
00034 
00035 #include "expandlib-cmd.h"
00036 
00037 namespace expander { // *** Start of namespace
00038 
00040 
00044     template<
00045         // Used for the expandable string (and the expanded string)
00046         class StringType = ::std::string
00047         >
00048     class expcmd_abbr : public expandcmd<StringType> {
00049     protected:
00050     public:
00052 
00055         expcmd_abbr(expandable<StringType> * const eobj) : expandcmd<StringType>(eobj, _T("abbr")) {};
00056 
00057         virtual void operator()(StringType &dest, const FParamVectorType &params, const FVarMapType &vars, ExpandResultsType &results) const
00058         {
00059             if ( params.size() == 1 ) {
00060                 StringType s;
00061                 expobj->expand(s, params[0], vars, results);
00062 
00063                 {
00064 //                  bool storechar=true;
00065                     for(StringType::const_iterator u=s.begin(); u!=s.end(); ++u) {
00066                         dest+=*u;
00067                         for(; u!=s.end(); ++u) {
00068                             if ( *u == _T(' ') || *u == _T(',') || *u == _T('\\') ) break;
00069                         }
00070 /*                      if ( storechar ) {
00071                             dest+=*u;
00072                             storechar=false;
00073                         } else if ( *u == _T(' ') || *u == _T(',') || *u == _T('\\') ) {
00074                             storechar=true;
00075                         }*/
00076                     }
00077                 }
00078             } else if ( params.size() == 2 ) {
00079                 StringType s;
00080                 expobj->expand(s, params[0], vars, results);
00081 
00082                 {
00083                     try {
00084                         const StringType::size_type num=boost::lexical_cast<StringType::size_type>(params[1]);
00085 
00086                         if ( s.size() > num ) {
00087         //                  bool storechar=true;
00088                             for(StringType::const_iterator u=s.begin(); u!=s.end(); ++u) {
00089                                 dest+=*u;
00090                                 for(; u!=s.end(); ++u) {
00091                                     if ( *u == _T(' ') || *u == _T(',') || *u == _T('\\') ) break;
00092                                 }
00093         /*                      if ( storechar ) {
00094                                     dest+=*u;
00095                                     storechar=false;
00096                                 } else if ( *u == _T(' ') || *u == _T(',') || *u == _T('\\') ) {
00097                                     storechar=true;
00098                                 }*/
00099                             }
00100                         } else {
00101                             dest+=s;
00102                         }
00103                     } catch(boost::bad_lexical_cast) {
00104                         throw expand_error(_T("expcmd_abbr"),_T("Illegal size"),params[1].c_str());
00105                     }
00106                 }
00107             } else {
00108                 throw expand_error(_T("expcmd_abbr"),_T("Parameter error"));
00109             }
00110         }
00111     };
00112 
00113 } // *** End of namespace
00114 
00115 #endif //EXPANDLIB_CMD_ABBR_H_INCLUDED

Generated on Tue Feb 4 17:24:13 2003 for ExpandLib by doxygen1.3-rc2