utils.cpp

Go to the documentation of this file.
00001 //  This file is part of jdl_parser.
00002 //
00003 //  jdl_parser is free software: you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation, either version 3 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  jdl_parser is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with jdl_parser.  If not, see <http://www.gnu.org/licenses/>.
00015 
00016 // Copyright Simone Pellegrini 2007-2008; e-mail: motonacciu@gmail.com
00017 
00018 #include "utils.hpp"
00019 
00020 using namespace jdl;
00021 
00022 std::pair<int, int> jdl::iter2RowCol(std::string const& str, std::string const& where){
00023         int rows = 1, cols = 1;
00024         string::const_iterator it = str.begin();
00025         string::const_iterator end = search(str.begin(), str.end(), where.begin(), where.end());
00026         while(it != end){
00027                 if(*(it++) == '\n'){
00028                         rows++;
00029                         cols=0;
00030                 }
00031                 cols++;
00032         }
00033         return pair<int,int>(rows,cols);
00034 }
00035 
00036 void jdl::indent(int n, ostream& out){ 
00037         for(int i=0; i<n; i++)  
00038                 out << "\t"; 
00039 }
00040 
00041 string jdl::open_file(const string& file_name){
00042         std::ifstream jdl_file(file_name.c_str());
00043         std::string s;
00044         std::string jdl_def = "";
00045         if(std::getline(jdl_file, s)){
00046                 jdl_def += s;
00047                 while (std::getline(jdl_file, s)) 
00048                         jdl_def += "\n" + s;
00049         }
00050         return jdl_def;
00051 }
00052 

Generated on Sun Feb 17 16:55:14 2008 for JDLParser by  doxygen 1.5.3