22@ {
33from collections import OrderedDict
44from rosidl_generator_c import escape_string
5+ from rosidl_generator_c import escape_utf8
56from rosidl_generator_c import idl_structure_type_to_c_include_prefix
67from rosidl_generator_c import type_hash_to_c_definition
78from rosidl_parser .definition import NamespacedType
@@ -26,11 +27,6 @@ def static_seq(varname, values):
2627 return f' {{{varname}, {len(values)}, {len(values)}}}'
2728 return ' {NULL, 0, 0}'
2829
29- def utf8_encode (value_string):
30- from rosidl_generator_c import escape_string
31- # Slice removes the b'' from the representation.
32- return escape_string (repr (value_string .encode (' utf-8' ))[2 : - 1 ])
33-
3430implicit_type_names = set (td[' type_description' ][' type_name' ] for td, _ in implicit_type_descriptions)
3531includes = OrderedDict ()
3632toplevel_msg, _ = toplevel_type_description
@@ -98,7 +94,7 @@ ref_tds = msg['referenced_type_descriptions']
9894@ [ for field in itype_description[' fields' ]]@
9995static char @ (td_c_typename)__FIELD_NAME__@ (field[' name' ])[] = " @(field['name'])" ;
10096@ [ if field[' default_value' ]]@
101- static char @ (td_c_typename)__DEFAULT_VALUE__@ (field[' name' ])[] = " @(utf8_encode( field['default_value']))" ;
97+ static char @ (td_c_typename)__DEFAULT_VALUE__@ (field[' name' ])[] = " @(escape_utf8(escape_string( field['default_value']) ))" ;
10298@ [ end if ]@
10399@ [ end for ]@
104100
@@ -167,9 +163,9 @@ c_typename = typename_to_c(ref_td['type_name'])
167163@ [if raw_source_content]@
168164static char toplevel_type_raw_source[] = @
169165@ [ for line in raw_source_content .splitlines ()[: - 1 ]]
170- " @(utf8_encode( line))\n " @
166+ " @(escape_utf8(escape_string( line) ))\n " @
171167@ [ end for ]
172- " @(utf8_encode( raw_source_content.splitlines()[-1]))" ;
168+ " @(escape_utf8(escape_string( raw_source_content.splitlines()[-1]) ))" ;
173169@ [end if ]@
174170
175171static char @ (toplevel_encoding)_encoding[] = " @(toplevel_encoding)" ;
0 commit comments