tag.cpp 1.05 KB
Newer Older
1
#include "tag.h"
2
#include "directives.h"
3
4
#include "token.h"
#include <cassert>
5
#include <stdexcept>
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

namespace YAML
{
	Tag::Tag(const Token& token): type(static_cast<TYPE>(token.data))
	{
		switch(type) {
			case VERBATIM:
				value = token.value;
				break;
			case PRIMARY_HANDLE:
				value = token.value;
				break;
			case SECONDARY_HANDLE:
				value = token.value;
				break;
			case NAMED_HANDLE:
				handle = token.value;
				value = token.params[0];
				break;
			case NON_SPECIFIC:
				break;
			default:
				assert(false);
		}
	}

32
	const std::string Tag::Translate(const Directives& directives)
33
34
35
36
37
	{
		switch(type) {
			case VERBATIM:
				return value;
			case PRIMARY_HANDLE:
38
				return directives.TranslateTagHandle("!") + value;
39
			case SECONDARY_HANDLE:
40
				return directives.TranslateTagHandle("!!") + value;
41
			case NAMED_HANDLE:
42
				return directives.TranslateTagHandle("!" + handle + "!") + value;
43
44
45
46
47
48
			case NON_SPECIFIC:
				// TODO:
				return "!";
			default:
				assert(false);
		}
49
		throw std::runtime_error("yaml-cpp: internal error, bad tag type");
50
51
52
	}
}