aboutsummaryrefslogtreecommitdiff
path: root/build/name.cxx
blob: 4ffc848fe18eee8709683d76090098852df26d39 (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
// 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)
  {
    if (!n.type.empty ())
      os << n.type << '{';

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

      if (s != ".")
      {
        os << s;

        if (!n.value.empty () &&
            s.back () != path::traits::directory_separator)
          os << path::traits::directory_separator;
      }
      else if (n.value.empty () && n.type.empty ())
        os << s; // Otherwise nothing gets printed.
    }

    os << n.value;

    if (!n.type.empty ())
      os << '}';

    return os;
  }

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

    return os;
  }
}