1 /*
2 * This file is part of CSSTidy.
3 *
4 * CSSTidy is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * CSSTidy is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with CSSTidy; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "csspp_globals.hpp"
20 using namespace std;
21
file_get_contents(const string filename)22 string file_get_contents(const string filename)
23 {
24 ifstream file_input(filename.c_str(),ios::binary);
25 string line, file_contents = "";
26
27 if(file_input.bad())
28 {
29 return "";
30 }
31 else
32 {
33 while(file_input.good())
34 {
35 getline(file_input,line);
36 file_contents += (line + "\n");
37 }
38 }
39 file_input.close();
40
41 return file_contents;
42 }
43
file_exists(const char * filename)44 bool file_exists(const char *filename)
45 {
46 ifstream file_input(filename);
47
48 if(file_input.is_open())
49 {
50 file_input.close();
51 return true;
52 }
53
54 file_input.close();
55 return false;
56 }
57