SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FileUtil.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2013 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27  */
28 /// @todo Documentation Core/Utils/FileUtil.h
29 
30 #ifndef CORE_UTILS_FILEUTIL_H
31 #define CORE_UTILS_FILEUTIL_H
32 
33 #include <sstream>
34 #include <Core/Utils/share.h>
35 
36 namespace SCIRun
37 {
38 namespace Core
39 {
40 
41 inline bool fileContainsString(const std::string& filename, const std::string& str)
42 {
43  std::ifstream input(filename.c_str());
44  std::string line;
45 
46  while (std::getline(input, line))
47  {
48  auto index = line.find(str);
49  if (index != std::string::npos && line.find('\0') > index)
50  return true;
51  }
52 
53  return false;
54 }
55 
56 inline void replaceDelimitersWithWhitespace(std::string& line)
57 {
58  /// @todo this code doesn't work under VS2010 - check with VS2012
59 
60  // replace comma's, tabs etc. with white spaces
61 // for (auto &c : line)
62 // {
63 // if ( (c == '\t') || (c == ',') || (c == '"') )
64 // c = ' ';
65 // }
66  for (auto it = line.begin(); it != line.end(); it++)
67  {
68  char c = *it;
69  if ( (c == '\t') || (c == ',') || (c == '"') )
70  c = ' ';
71  }
72 }
73 
74 inline bool lineStartsWithComment(const std::string& line)
75 {
76  if ( line.empty() ) return false;
77 
78  if ( (line[0] == '#') || (line[0] == '%') ) return true;
79 
80  return false;
81 }
82 
83 }}
84 
85 #endif
void replaceDelimitersWithWhitespace(std::string &line)
Definition: FileUtil.h:56
bool fileContainsString(const std::string &filename, const std::string &str)
Definition: FileUtil.h:41
bool lineStartsWithComment(const std::string &line)
Definition: FileUtil.h:74