Skip to main content

Module identifier_sanitization

Module identifier_sanitization 

Source
Expand description

Language-specific identifier sanitization for code generation.

Provides utilities to sanitize identifiers (variable names, class names, function names, etc.) for use in different programming languages. Handles reserved keywords, invalid characters, and language-specific naming conventions.

§Examples

use spikard_cli::codegen::common::identifier_sanitization::{sanitize_identifier, TargetLanguage};

// Python reserved word becomes prefixed with underscore
assert_eq!(
    sanitize_identifier("class", TargetLanguage::Python),
    "_class"
);

// Invalid characters are replaced with underscores
assert_eq!(
    sanitize_identifier("hello-world", TargetLanguage::TypeScript),
    "hello_world"
);

// Identifiers starting with digits are prefixed
assert_eq!(
    sanitize_identifier("123field", TargetLanguage::Rust),
    "_123field"
);

Enums§

TargetLanguage
Target programming language for identifier sanitization.

Functions§

sanitize_identifier
Sanitize an identifier to be valid in the target language.
sanitize_identifier_camel_case
Sanitize an identifier and convert it to camelCase.
sanitize_identifier_pascal_case
Sanitize an identifier and convert it to PascalCase.
sanitize_identifier_snake_case
Sanitize an identifier and convert it to snake_case.