Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

Sequence.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2004  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 //#include <stdio.h>
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 
00028 #include "Token.h"
00029 #include "Scope.h"
00030 #include "Sequence.h"
00031 #include "dp.h"
00032 #include "BaseParser.h" // tokens
00033 
00034 
00035 
00036 Sequence::Sequence()
00037 :m_file("")
00038 ,m_line(0)
00039 ,m_pos(0)
00040 ,m_bExtern(false)
00041 ,m_parent(NULL)
00042 {
00043 }
00044 
00045 
00046 Sequence::Sequence(token_v &tokens)
00047 :m_file("")
00048 ,m_line(0)
00049 ,m_pos(0)
00050 ,m_bExtern(false)
00051 ,m_tokens(tokens)
00052 ,m_parent(NULL)
00053 {
00054 }
00055 
00056 
00057 Sequence::~Sequence()
00058 {
00059         while (m_tokens.size())
00060         {
00061                 token_v::iterator it = m_tokens.begin();
00062                 Token *t = *it;
00063                 delete t;
00064                 m_tokens.erase(it);
00065         }
00066 }
00067 
00068 
00069 void Sequence::Display()
00070 {
00071         return;
00072         printf("%s",GetExpr().c_str());
00073 }
00074 
00075 
00076 void Sequence::Tab()
00077 {
00078         Scope *p = GetParent();
00079         while (p && p -> GetParent() )
00080         {
00081                 printf("\t");
00082                 p = p -> GetParent();
00083         }
00084 }
00085 
00086 
00087 std::string Sequence::GetExpr()
00088 {
00089         std::string tmp;
00090         bool first = true;
00091         for (token_v::iterator it = m_tokens.begin(); it != m_tokens.end(); it++)
00092         {
00093                 Token *t = *it;
00094                 if (t -> GetCode() != COMMENT || first)
00095                 {
00096                         std::string str = t -> GetVal();
00097 //                      if (tmp.size() && (isalpha(str[0]) || str[0] == '<' || str[0] == '_' || str[0] == 34 || str[0] == '~') )
00098 //                              tmp += " ";
00099                         tmp += str;
00100                 }
00101                 first = false;
00102         }
00103         if (config["-xml"] == "true")
00104                 xmlsafestr(tmp);
00105         return tmp;
00106 }
00107 
00108 
00109 void Sequence::xmlsafestr(std::string &s) 
00110 {
00111         std::string str;
00112         for (size_t i = 0; i < s.size(); i++)
00113         {
00114                 switch (s[i])
00115                 {
00116                 case '&':
00117                         str += "&amp;";
00118                         break;
00119                 case '<':
00120                         str += "&lt;";
00121                         break;
00122                 case '>':
00123                         str += "&gt;";
00124                         break;
00125                 case '"':
00126                         str += "&quot;";
00127                         break;
00128                 case '\'':
00129                         str += "&apos;";
00130                         break;
00131                 default:
00132                         str += s[i];
00133                 }
00134         }
00135         s = str;
00136 }
00137 
00138 
00139 Token *Sequence::GetFirstToken()
00140 {
00141         if (!m_tokens.size())
00142                 return NULL;
00143         token_v::iterator it = m_tokens.begin();
00144         Token *t = *it;
00145         return t;
00146 }
00147 
00148 

Generated for My SDL C++ Gui by doxygen 1.3.6