aboutsummaryrefslogtreecommitdiff
path: root/build/name.cxx
blob: 46e244036c1e12f4547279d1a04dbd80e1b528bb (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
// file      : build/name.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#include <build/name>

#include <ostream>

#include <build/diagnostics>

using namespace std;

namespace build
{
  ostream&
  operator<< (ostream& os, const name& n)
  {
    bool ht (!n.type.empty ());
    bool hv (!n.value.empty ());
    bool hd (false);

    if (ht)
      os << n.type << '{';

    if (!n.dir.empty ())
    {
      string s (diag_relative_work (n.dir));

      // If both type and value are empty, there will be nothing printed.
      //
      if (s != "." || (!ht && !hv))
      {
        os << s;

        // Add the directory separator unless it is already there
        // or we have type but no value. The idea is to print foo/
        // or dir{foo}.
        //
        if (s.back () != path::traits::directory_separator && (hv || !ht))
          os << path::traits::directory_separator;

        hd = true;
      }
    }

    os << n.value;

    if (ht)
      os << '}';

    if (!ht && !hv && !hd)
      os << "{}"; // Nothing got printed.

    return os;
  }

  ostream&
  operator<< (ostream& os, const names& ns)
  {
    for (auto i (ns.begin ()), e (ns.end ()); i != e; )
    {
      const name& n (*i);
      ++i;
      os << n << (n.pair ? "=" : (i != e ? " " : ""));
    }

    return os;
  }
}