GeographicLib
1.21
|
00001 /** 00002 * \file Utility.cpp 00003 * \brief Implementation for GeographicLib::Utility class 00004 * 00005 * Copyright (c) Charles Karney (2011) <charles@karney.com> and licensed under 00006 * the MIT/X11 License. For more information, see 00007 * http://geographiclib.sourceforge.net/ 00008 **********************************************************************/ 00009 00010 #include <GeographicLib/Utility.hpp> 00011 00012 #define GEOGRAPHICLIB_UTILITY_CPP \ 00013 "$Id: 6f06d5d8fa9d731dc5a5fa4516838f639a2ba40b $" 00014 00015 RCSID_DECL(GEOGRAPHICLIB_UTILITY_CPP) 00016 RCSID_DECL(GEOGRAPHICLIB_UTILITY_HPP) 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; // Blank line 00028 string::size_type n1 = line.find_first_of('#', n0); 00029 if (n0 == n1) 00030 return false; // Only a comment 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 } // namespace GeographicLib