Fraxinus  18.10
An IGT application
cxStringHelpers.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxStringHelpers.h"
13 #include <QStringList>
14 
15 namespace cx
16 {
17 
21 QStringList splitStringContaingQuotes(QString line)
22 {
23  QStringList base = line.split(" ");
24  QStringList retval;
25 
26  for (int i=0; i<base.size(); ++i)
27  {
28  if (base[i].startsWith("\"") && !base[i].endsWith("\""))
29  {
30  QString s;
31  do
32  {
33  s += base[i];
34  if ((i+1)<base.size() && !base[i].endsWith("\""))
35  s += " ";
36  ++i;
37  } while (i<base.size() && !base[i].endsWith("\""));
38  if (i<base.size())
39  s += base[i];
40  retval.push_back(s);
41  }
42  else
43  {
44  retval.push_back(base[i]);
45  }
46 
47  retval.back() = retval.back().remove("\"");
48  }
49 
50  retval.removeAll("");
51  return retval;
52 }
53 
54 int convertStringWithDefault(QString text, int def)
55 {
56  bool ok = true;
57  int retval = text.toInt(&ok,0);
58  if (ok)
59  return retval;
60  return def;
61 }
62 
63 
64 } // namespace cx
65 
QStringList splitStringContaingQuotes(QString line)
bool startsWith(std::string const &s, std::string const &prefix)
Definition: catch.hpp:162
int convertStringWithDefault(QString text, int def)
Namespace for all CustusX production code.