yaml-cpp

FORK: A YAML parser and emitter in C++
git clone https://git.neptards.moe/neptards/yaml-cpp.git
Log | Files | Refs | README | LICENSE

tag.cpp (1185B)


      1 #include <cassert>
      2 #include <stdexcept>
      3 
      4 #include "directives.h"  // IWYU pragma: keep
      5 #include "tag.h"
      6 #include "token.h"
      7 
      8 namespace YAML {
      9 Tag::Tag(const Token& token)
     10     : type(static_cast<TYPE>(token.data)), handle{}, value{} {
     11   switch (type) {
     12     case VERBATIM:
     13       value = token.value;
     14       break;
     15     case PRIMARY_HANDLE:
     16       value = token.value;
     17       break;
     18     case SECONDARY_HANDLE:
     19       value = token.value;
     20       break;
     21     case NAMED_HANDLE:
     22       handle = token.value;
     23       value = token.params[0];
     24       break;
     25     case NON_SPECIFIC:
     26       break;
     27     default:
     28       assert(false);
     29   }
     30 }
     31 
     32 const std::string Tag::Translate(const Directives& directives) {
     33   switch (type) {
     34     case VERBATIM:
     35       return value;
     36     case PRIMARY_HANDLE:
     37       return directives.TranslateTagHandle("!") + value;
     38     case SECONDARY_HANDLE:
     39       return directives.TranslateTagHandle("!!") + value;
     40     case NAMED_HANDLE:
     41       return directives.TranslateTagHandle("!" + handle + "!") + value;
     42     case NON_SPECIFIC:
     43       // TODO:
     44       return "!";
     45     default:
     46       assert(false);
     47   }
     48   throw std::runtime_error("yaml-cpp: internal error, bad tag type");
     49 }
     50 }  // namespace YAML