aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/xmlstream.hpp
blob: bbfb3b11a23d667195d7ef3fb4114e4d926426fa (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "xmlstream.h"
#include <vespa/vespalib/util/exceptions.h>
#include <sstream>

namespace vespalib::xml {

template<typename T>
XmlAttribute::XmlAttribute(const std::string& name, T value, uint32_t flags)
    : _name(name),
      _value(),
      _next()
{
    std::ostringstream ost;
    if (flags & HEX) ost << std::hex << "0x";
    ost << value;
    _value = ost.str();
    if (!isLegalName(name)) {
        throw IllegalArgumentException("Name '" + name + "' contains "
                "illegal XML characters and cannot be used as attribute name");
    }
}

}