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§
- Target
Language - 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.