aboutsummaryrefslogtreecommitdiff
path: root/bbot/variable
blob: c210dc0072cd084500765225cc09e1b3ef17f482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// file      : bbot/variable -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BBOT_VARIABLE
#define BBOT_VARIABLE

#include <string>
#include <vector>
#include <cstdint>   // uint64_t
#include <stdexcept> // invalid_argument

#include <bbot/export>

namespace bbot
{
  //@@ invalid_argument
  //
  class LIBBBOT_EXPORT invalid_variable: public std::invalid_argument
  {
  public:
    invalid_variable (std::uint64_t p, const std::string& d)
        : invalid_argument (d), pos (p) {}

    std::uint64_t pos; // Zero-based.
  };

  // String in the name=value format. Can contain single or double quoted
  // substrings. No escaping is supported. The name must not contain spaces.
  // Throw variable_error if the string doesn't conform with the above
  // constraints.
  //
  struct LIBBBOT_EXPORT variable: std::string
  {
    variable (std::string);

    // Remove a single level of quotes. Don't validate the format or the
    // correctness of the quotation. Note that the variable can potentially be
    // modified through the std::string interface in a way that breaks
    // format/quoting.
    //
    std::string
    unquoted () const;
  };

  using variables = std::vector<variable>;
}

#endif // BBOT_VARIABLE