source: trunk/debathena/third/schroot/sbuild/sbuild-parse-value.cc @ 24167

Revision 24167, 2.0 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
Line 
1/* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
2 *
3 * schroot is free software: you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * schroot is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 *********************************************************************/
18
19#include <config.h>
20
21#include "sbuild-parse-value.h"
22
23using namespace sbuild;
24
25namespace
26{
27
28  typedef std::pair<parse_value_error_code,const char *> emap;
29
30  /**
31   * This is a list of the supported error codes.  It's used to
32   * construct the real error codes map.
33   */
34  emap init_errors[] =
35    {
36      // TRANSLATORS: %1% = value (arbitrary text)
37      emap(BAD_VALUE, N_("Could not parse value '%1%'"))
38    };
39
40}
41
42template<>
43error<parse_value_error_code>::map_type
44error<parse_value_error_code>::error_strings
45(init_errors,
46 init_errors + (sizeof(init_errors) / sizeof(init_errors[0])));
47
48void
49sbuild::parse_value (std::string const& value,
50                     bool&              parsed_value)
51{
52  if (value == "true" || value == "yes" || value == "1")
53    parsed_value = true;
54  else if (value == "false" || value == "no" || value == "0")
55    parsed_value = false;
56  else
57    {
58      log_debug(DEBUG_NOTICE) << "parse error" << std::endl;
59      throw parse_value_error(value, BAD_VALUE);
60    }
61
62  log_debug(DEBUG_NOTICE) << "value=" << parsed_value << std::endl;
63}
64
65void
66sbuild::parse_value (std::string const& value,
67                     std::string&       parsed_value)
68{
69  parsed_value = value;
70  log_debug(DEBUG_NOTICE) << "value=" << parsed_value << std::endl;
71}
Note: See TracBrowser for help on using the repository browser.