Skip to main content

Module escaping

Module escaping 

Source
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§

EscapeContext
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.