GeographicLib 1.52
Loading...
Searching...
No Matches
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-2020) <charles@karney.com> and licensed
6 * under the MIT/X11 License. For more information, see
7 * https://geographiclib.sourceforge.io/
8 **********************************************************************/
9
10#include <cstdlib>
12
13#if defined(_MSC_VER)
14// Squelch warnings about unsafe use of getenv
15# pragma warning (disable: 4996)
16#endif
17
18namespace GeographicLib {
19
20 using namespace std;
21
22 bool Utility::ParseLine(const std::string& line,
23 std::string& key, std::string& value,
24 char delim) {
25 key.clear(); value.clear();
26 string::size_type n = line.find('#');
27 string linea = trim(line.substr(0, n));
28 if (linea.empty()) return false;
29 n = delim ? linea.find(delim) : linea.find_first_of(" \t\n\v\f\r"); //
30 key = trim(linea.substr(0, n));
31 if (key.empty()) return false;
32 if (n != string::npos) value = trim(linea.substr(n + 1));
33 return true;
34 }
35
36 bool Utility::ParseLine(const std::string& line,
37 std::string& key, std::string& value) {
38 return ParseLine(line, key, value, '\0');
39 }
40
41 int Utility::set_digits(int ndigits) {
42#if GEOGRAPHICLIB_PRECISION == 5
43 if (ndigits <= 0) {
44 char* digitenv = getenv("GEOGRAPHICLIB_DIGITS");
45 if (digitenv)
46 ndigits = strtol(digitenv, NULL, 0);
47 if (ndigits <= 0)
48 ndigits = 256;
49 }
50#endif
51 return Math::set_digits(ndigits);
52 }
53
54} // namespace GeographicLib
Header for GeographicLib::Utility class.
static int set_digits(int ndigits)
Definition: Math.cpp:34
static std::string trim(const std::string &s)
Definition: Utility.hpp:325
static bool ParseLine(const std::string &line, std::string &key, std::string &value, char delim)
Definition: Utility.cpp:22
static int set_digits(int ndigits=0)
Definition: Utility.cpp:41
Namespace for GeographicLib.
Definition: Accumulator.cpp:12