简体   繁体   中英

How can I write a version string as a literal (not string) in YAML-CPP?

I am trying to write the following information:

hints:
  SoftwareRequirement:
    packages:
      ApplicationName:
        version: [ 1.7.3.nonRelease ]

I am using the following section of code:

std::string m_exeName = # I get this from my CMakeLists file
std::string versionID = # I get this from my CMakeLists file

YAML::Node hints = config["hints"];
config["hints"]["SoftwareRequirement"]["packages"][m_exeName]["version"] = "[ " + versionID + " ]";

And it gets me the following:

hints:
  SoftwareRequirement:
    packages:
      ApplicationName:
        version: "[ 1.7.3.nonRelease ]"

Is there any way to get the quotes inside the square bracket or remove them entirely? This is to be in line with the Common Workflow Language (CWL) standard.

Possibly related to this question .

EDIT (added results from answer):

Went with this:

config["hints"]["SoftwareRequirement"]["packages"][m_exeName]["version"][0] = versionID

Result:

hints:
  SoftwareRequirement:
    packages:
      ApplicationName:
        version: 
          - 1.7.3.nonRelease

With is a valid CWL.

[] are YAML syntax for a sequence; so if you're trying to write

[ 1.7.3.nonRelease ]

then you're trying to write a sequence with a single element 1.7.3.nonRelease . When you tell yaml-cpp to write the string [ 1.7.3.nonRelease ] , it notices that if it just pasted the text directly, it would be interpreted as a list, so it quotes the string to prevent that.

If you really want to write a list with one element, then make it so:

config["hints"]["SoftwareRequirement"]["packages"][m_exeName]["version"][0] = versionID;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM