aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/basename.cpp
blob: ba2fa64c53d602305beb061dcc92bf6687a79aed (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "basename.h"

namespace search::attribute {

BaseName::BaseName(vespalib::stringref base, vespalib::stringref name)
    : string(base),
      _name(name)
{
    if (!empty()) {
        push_back('/');
    }
    append(name);
}

BaseName::BaseName(vespalib::stringref s)
    : string(s),
      _name(createAttributeName(s))
{ }
BaseName &
BaseName::operator = (vespalib::stringref s) {
        BaseName n(s);
        std::swap(*this, n);
        return *this;
    }

BaseName::~BaseName() = default;

vespalib::string
BaseName::createAttributeName(vespalib::stringref s)
{
    size_t p(s.rfind('/'));
    if (p == string::npos) {
       return s;
    } else {
        return s.substr(p+1);
    }
}

vespalib::string
BaseName::getDirName() const
{
    size_t p = rfind('/');
    if (p == string::npos) {
       return "";
    } else {
        return substr(0, p);
    }
}

}