MCPcopy Create free account
hub / github.com/github/spec-kit / _render_toml_string

Method _render_toml_string

src/specify_cli/integrations/base.py:944–974  ·  view source on GitHub ↗

Render *value* as a TOML string literal. Uses a basic string for single-line values, multiline basic strings for values containing newlines, and falls back to a literal string or escaped basic string when delimiters appear in the content.

(value: str)

Source from the content-addressed store, hash-verified

942
943 @staticmethod
944 def _render_toml_string(value: str) -> str:
945 """Render *value* as a TOML string literal.
946
947 Uses a basic string for single-line values, multiline basic
948 strings for values containing newlines, and falls back to a
949 literal string or escaped basic string when delimiters appear in
950 the content.
951 """
952 if "\n" not in value and "\r" not in value:
953 escaped = value.replace("\\", "\\\\").replace('"', '\\"')
954 return f'"{escaped}"'
955
956 escaped = value.replace("\\", "\\\\")
957 if '"""' not in escaped:
958 if escaped.endswith('"'):
959 return '"""\n' + escaped + '\\\n"""'
960 return '"""\n' + escaped + '"""'
961 if "'''" not in value and not value.endswith("'"):
962 return "'''\n" + value + "'''"
963
964 return (
965 '"'
966 + (
967 value.replace("\\", "\\\\")
968 .replace('"', '\\"')
969 .replace("\n", "\\n")
970 .replace("\r", "\\r")
971 .replace("\t", "\\t")
972 )
973 + '"'
974 )
975
976 @staticmethod
977 def _render_toml(description: str, body: str) -> str:

Callers 1

_render_tomlMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected