MCPcopy Index your code
hub / github.com/RustPython/RustPython / compile_string_value

Method compile_string_value

crates/codegen/src/compile.rs:9403–9418  ·  view source on GitHub ↗

Convert a string literal AST node to Wtf8Buf, handling surrogate literals correctly.

(&self, string: &ast::ExprStringLiteral)

Source from the content-addressed store, hash-verified

9401
9402 /// Convert a string literal AST node to Wtf8Buf, handling surrogate literals correctly.
9403 fn compile_string_value(&self, string: &ast::ExprStringLiteral) -> Wtf8Buf {
9404 let value = string.value.to_str();
9405 if value.contains(char::REPLACEMENT_CHARACTER) {
9406 // Might have a surrogate literal; reparse from source to preserve them.
9407 string
9408 .value
9409 .iter()
9410 .map(|lit| {
9411 let source = self.source_file.slice(lit.range);
9412 crate::string_parser::parse_string_literal(source, lit.flags.into())
9413 })
9414 .collect()
9415 } else {
9416 value.into()
9417 }
9418 }
9419
9420 fn compile_fstring_literal_value(
9421 &self,

Callers 2

compile_expressionMethod · 0.80

Calls 7

parse_string_literalFunction · 0.85
to_strMethod · 0.80
collectMethod · 0.80
containsMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected