mirror of https://github.com/jbeder/yaml-cpp.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include <cassert>
|
|
#include <stdexcept>
|
|
|
|
#include "directives.h" // IWYU pragma: keep
|
|
#include "tag.h"
|
|
#include "token.h"
|
|
|
|
namespace YAML {
|
|
Tag::Tag(const Token& token)
|
|
: type(static_cast<TYPE>(token.data)), handle{}, value{} {
|
|
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);
|
|
}
|
|
}
|
|
|
|
std::string Tag::Translate(const Directives& directives) {
|
|
switch (type) {
|
|
case VERBATIM:
|
|
return value;
|
|
case PRIMARY_HANDLE:
|
|
return directives.TranslateTagHandle("!") + value;
|
|
case SECONDARY_HANDLE:
|
|
return directives.TranslateTagHandle("!!") + value;
|
|
case NAMED_HANDLE:
|
|
return directives.TranslateTagHandle("!" + handle + "!") + value;
|
|
case NON_SPECIFIC:
|
|
// TODO:
|
|
return "!";
|
|
default:
|
|
assert(false);
|
|
}
|
|
throw std::runtime_error("yaml-cpp: internal error, bad tag type");
|
|
}
|
|
} // namespace YAML
|