BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
CsvNamespace.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvNamespace.cpp
6 //! @brief Implements functions of namespace csv
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include <fstream>
17 #include <sstream>
18 
19 bool csv::isAscii(QString filename)
20 {
21  return true;
22  // TODO
23  // This function needs to be defined properly (if at all)
24  // motivation: ° and Å characters are problematic.
25  char c;
26  size_t count = 0;
27  size_t count_bad = 0;
28  std::ifstream is(filename.toStdString());
29  while (is.get(c) && count < 1000) {
30  count++;
31  if (size_t(c) > 255)
32  count_bad++;
33  }
34  is.close();
35  double acceptance_threshold = 0.1 * double(count);
36  // std::cout << count << "; " << count_bad << std::endl;
37  return static_cast<double>(count_bad) <= acceptance_threshold;
38 }
Defines namespace csv.
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
bool isAscii(QString filename)