Expand description
Language-specific string escaping utilities for code generation.
This module provides unified escaping functions for strings that will be embedded in generated code across multiple languages. Each language has specific quote characters, escape sequences, and special cases that must be handled correctly to produce valid, compilable code.
§Examples
use spikard_cli::codegen::common::escaping::{EscapeContext, escape_quotes, escape_for_docstring};
// Escape quotes for a Python single-quoted string
let python_str = escape_quotes("it's a string", EscapeContext::Python);
assert!(python_str.contains("\\'"));
// Escape for a Python docstring (triple-quoted)
let docstring = escape_for_docstring("The description says \"\"\"", EscapeContext::Python);
assert!(!docstring.contains("\"\"\""));Enums§
- Escape
Context - Language context for determining escape sequences and quote characters.
Functions§
- escape_
double_ quotes - Escape a string for use in double-quoted string literals.
- escape_
for_ docstring - Escape a string for use in docstrings or documentation comments.
- escape_
graphql_ sdl_ description - Escape a string for use in GraphQL SDL (Schema Definition Language) descriptions.
- escape_
graphql_ string - Escape a string for use in GraphQL SDL (Schema Definition Language) as a complete quoted string.
- escape_
json_ string - Escape a string for embedding in JSON strings.
- escape_
quotes - Escape a string for use in a single-quoted string literal in the target language.
- escape_
template_ literal - Escape a string for use in template literals or backtick-delimited strings.