File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ namespace runcpp2
3535
3636 std::string GetValue (ryml::ConstNodeRef node);
3737 std::string GetKey (ryml::ConstNodeRef node);
38+ std::string GetEscapedYAMLString (const std::string& input);
3839}
3940
4041#endif
Original file line number Diff line number Diff line change @@ -337,3 +337,24 @@ std::string runcpp2::GetKey(ryml::ConstNodeRef node)
337337{
338338 return std::string (node.key ().str , node.key ().len );
339339}
340+
341+ std::string runcpp2::GetEscapedYAMLString (const std::string& input)
342+ {
343+ std::string output = " \" " ;
344+
345+ for (char c : input)
346+ {
347+ switch (c)
348+ {
349+ case ' \\ ' : output += " \\\\ " ; break ;
350+ case ' \" ' : output += " \\\" " ; break ;
351+ case ' \' ' : output += " \\\' " ; break ;
352+ case ' \n ' : output += " \\ n" ; break ;
353+ case ' \t ' : output += " \\ t" ; break ;
354+ default : output += c;
355+ }
356+ }
357+
358+ output += " \" " ;
359+ return output;
360+ }
You can’t perform that action at this time.
0 commit comments