GeographicLib  1.35
Utility.cpp
Go to the documentation of this file.
1 /**
2  * \file Utility.cpp
3  * \brief Implementation for GeographicLib::Utility class
4  *
5  * Copyright (c) Charles Karney (2011) <charles@karney.com> and licensed under
6  * the MIT/X11 License. For more information, see
7  * http://geographiclib.sourceforge.net/
8  **********************************************************************/
9 
11 
12 namespace GeographicLib {
13 
14  using namespace std;
15 
16  bool Utility::ParseLine(const std::string& line,
17  std::string& key, std::string& val) {
18  const char* spaces = " \t\n\v\f\r";
19  string::size_type n0 = line.find_first_not_of(spaces);
20  if (n0 == string::npos)
21  return false; // Blank line
22  string::size_type n1 = line.find_first_of('#', n0);
23  if (n0 == n1)
24  return false; // Only a comment
25  val = line.substr(n0, n1 == string::npos ? n1 : n1 - n0);
26  n0 = val.find_first_of(spaces);
27  key = val.substr(0, n0);
28  if (n0 == string::npos) {
29  val = "";
30  return true;
31  }
32  n0 = val.find_first_not_of(spaces, n0);
33  if (n0 == string::npos) {
34  val = "";
35  return true;
36  }
37  n1 = val.find_last_not_of(spaces);
38  val = val.substr(n0, n1 + 1 - n0);
39  return true;
40  }
41 
42 } // namespace GeographicLib
Header for GeographicLib::Utility class.
static bool ParseLine(const std::string &line, std::string &key, std::string &val)
Definition: Utility.cpp:16