int_letter.hxx

00001 // int_letter.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2004, 2005 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX
00019 
00020 # include <sstream>
00021 
00022 # include <vaucanson/algebra/implementation/letter/int_letter.hh>
00023 
00024 namespace vcsn {
00025 
00026   template <typename S>
00027   bool op_parse(const algebra::FreeMonoidBase<S>& set,
00028                 std::list<int>& v,
00029                 const std::string& s,
00030                 typename std::string::const_iterator& i,
00031                 const std::list<char>& escaped)
00032   {
00033     typename std::string::const_iterator j = i;
00034     typename std::string::const_iterator k;
00035     typename std::string::const_iterator back;
00036 
00037     while ((i != s.end()) &&
00038            (std::find(escaped.begin(), escaped.end(), *i) == escaped.end())) {
00039       std::string out;
00040       back = i;
00041 
00042       while ((i != s.end()) && (((*i >= '0') && (*i <= '9'))) || (*i == '\\'))
00043         if (*i == '\\') {
00044           k = i;
00045           ++k;
00046           if (k != s.end())
00047             i = k;
00048           out += *i;
00049           ++i;
00050         }
00051         else {
00052           out += *i;
00053           ++i;
00054         }
00055 
00056       int value;
00057       std::istringstream is(out);
00058       is >> value;
00059       if (!set.alphabet().contains(value)) {
00060         i = back;
00061         break ;
00062       }
00063       v.push_back(value);
00064     }
00065     return (i != j);
00066   }
00067 
00068 } // vcsn
00069 
00070 namespace std {
00071 
00072   ostream& operator<<(ostream& o, list<int> s)
00073   {
00074     list<int>::const_iterator i;
00075     list<int>::const_iterator j;
00076 
00077     for (i = s.begin(); i != s.end(); ) {
00078       o << *i;
00079       i++;
00080       if (i != s.end())
00081         o << ",";
00082     }
00083 
00084     return o;
00085   }
00086 
00087 } // std
00088 
00089 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX

Generated on Sun Jul 29 19:35:20 2007 for Vaucanson by  doxygen 1.5.2