00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <cstdlib>
00011 #include <GeographicLib/Utility.hpp>
00012
00013 #if defined(_MSC_VER)
00014
00015 # pragma warning (disable: 4996)
00016 #endif
00017
00018 namespace GeographicLib {
00019
00020 using namespace std;
00021
00022 bool Utility::ParseLine(const std::string& line,
00023 std::string& key, std::string& val) {
00024 const char* spaces = " \t\n\v\f\r";
00025 string::size_type n0 = line.find_first_not_of(spaces);
00026 if (n0 == string::npos)
00027 return false;
00028 string::size_type n1 = line.find_first_of('#', n0);
00029 if (n0 == n1)
00030 return false;
00031 val = line.substr(n0, n1 == string::npos ? n1 : n1 - n0);
00032 n0 = val.find_first_of(spaces);
00033 key = val.substr(0, n0);
00034 if (n0 == string::npos) {
00035 val = "";
00036 return true;
00037 }
00038 n0 = val.find_first_not_of(spaces, n0);
00039 if (n0 == string::npos) {
00040 val = "";
00041 return true;
00042 }
00043 n1 = val.find_last_not_of(spaces);
00044 val = val.substr(n0, n1 + 1 - n0);
00045 return true;
00046 }
00047
00048 int Utility::set_digits(int ndigits) {
00049 #if GEOGRAPHICLIB_PRECISION == 5
00050 if (ndigits <= 0) {
00051 char* digitenv = getenv("GEOGRAPHICLIB_DIGITS");
00052 if (digitenv)
00053 ndigits = strtol(digitenv, NULL, 0);
00054 if (ndigits <= 0)
00055 ndigits = 256;
00056 }
00057 #endif
00058 return Math::set_digits(ndigits);
00059 }
00060
00061 }