aboutsummaryrefslogtreecommitdiff
path: root/odb/semantics/relational/name.cxx
blob: 68b640e0078b01891fbd15fa48b51a6c6a4be21c (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// file      : odb/semantics/relational/name.cxx
// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
// license   : GNU GPL v3; see accompanying LICENSE file

#include <ostream>
#include <istream>

#include <odb/semantics/relational/name.hxx>

using namespace std;

namespace semantics
{
  namespace relational
  {
    string qname::
    string () const
    {
      std::string r;

      bool f (true);
      for (iterator i (begin ()); i < end (); ++i)
      {
        if (i->empty ())
          continue;

        if (f)
          f = false;
        else
          r += '.';

        r += *i;
      }

      return r;
    }

    ostream&
    operator<< (ostream& os, qname const& n)
    {
      bool f (true);
      for (qname::iterator i (n.begin ()); i < n.end (); ++i)
      {
        if (i->empty ())
          continue;

        if (f)
          f = false;
        else
          os << '.';

        os << *i;
      }

      return os;
    }

    istream&
    operator>> (istream& is, qname& n)
    {
      n.clear ();

      string s;
      is >> s;

      if (!is.fail ())
      {
        string::size_type p (string::npos);

        for (size_t i (0); i < s.size (); ++i)
        {
          char c (s[i]);

          if (c == '.')
          {
            if (p == string::npos)
              n.append (string (s, 0, i));
            else
              n.append (string (s, p + 1, i - p - 1));

            p  = i;
          }
        }

        if (p == string::npos)
          n.append (s);
        else
          n.append (string (s, p + 1, string::npos));
      }

      return is;
    }
  }
}