00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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