00001 /* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org> 00002 * 00003 * schroot is free software; you can redistribute it and/or modify it 00004 * under the terms of the GNU General Public License as published by 00005 * the Free Software Foundation; either version 2 of the License, or 00006 * (at your option) any later version. 00007 * 00008 * schroot is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program; if not, write to the Free Software 00015 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00016 * MA 02111-1307 USA 00017 * 00018 *********************************************************************/ 00019 00020 #include <config.h> 00021 00022 #include "sbuild-parse-value.h" 00023 00024 using namespace sbuild; 00025 00026 namespace 00027 { 00028 00029 typedef std::pair<parse_value_error_code,const char *> emap; 00030 00035 emap init_errors[] = 00036 { 00037 // TRANSLATORS: %1% = value (arbitrary text) 00038 emap(BAD_VALUE, N_("Could not parse value '%1%'")) 00039 }; 00040 00041 } 00042 00043 template<> 00044 error<parse_value_error_code>::map_type 00045 error<parse_value_error_code>::error_strings 00046 (init_errors, 00047 init_errors + (sizeof(init_errors) / sizeof(init_errors[0]))); 00048 00049 void 00050 sbuild::parse_value (std::string const& value, 00051 bool& parsed_value) 00052 { 00053 if (value == "true" || value == "yes" || value == "1") 00054 parsed_value = true; 00055 else if (value == "false" || value == "no" || value == "0") 00056 parsed_value = false; 00057 else 00058 { 00059 log_debug(DEBUG_NOTICE) << "parse error" << std::endl; 00060 throw parse_value_error(value, BAD_VALUE); 00061 } 00062 00063 log_debug(DEBUG_NOTICE) << "value=" << parsed_value << std::endl; 00064 } 00065 00066 void 00067 sbuild::parse_value (std::string const& value, 00068 std::string& parsed_value) 00069 { 00070 parsed_value = value; 00071 log_debug(DEBUG_NOTICE) << "value=" << parsed_value << std::endl; 00072 }