Skip to main content

Module charset

Module charset 

Source
Expand description

Byte-faithful strings and the graph charset (lib/common/input.c, utils.c).

C works on the bytes of its input: attribute values, names and the text of -Tdot/-Tsvg/… output are whatever bytes the file held, and only label text is converted to UTF-8 (latin1ToUTF8 for charset=latin1, htmlEntityUTF8 otherwise, whose invalid-UTF-8 recovery treats the offending byte as Latin-1).

The port keeps strings as String. Input that is not valid UTF-8 is decoded with decode: valid UTF-8 sequences stay as they are and every other byte b becomes the private-use code point U+10FF00 + b (a “raw byte”). encode maps them back, so the CLI writes C’s exact bytes, and the C conversions run on encoded bytes, so charset=latin1 text is converted exactly once, where C converts it. Text measurement (which C does byte by byte) also uses the encoded bytes. Input that genuinely contains U+10FF00..=U+10FFFF is not distinguished from raw bytes (no real-world encoding assigns these code points).

Enums§

Charset
GD_charset(g): the input character set of a graph (CHAR_UTF8, CHAR_LATIN1, CHAR_BIG5 in lib/common/const.h).

Functions§

begin_layout
graph_init for charset purposes: records the root graph’s charset and name for the label conversions that follow, clears htmlEntityUTF8’s once-per-graph warning flag and warns about an unsupported charset name.
begin_render
Sets the charset of the graph being rendered (no warnings; the layout already gave them).
current
Charset of the graph being laid out or rendered on this thread.
decode
Decodes input bytes: valid UTF-8 is kept, every other byte becomes a raw-byte char.
decode_slice
decode for a borrowed slice.
encode
The bytes C would hold for s: raw-byte chars become their byte again.
eprint_bytes
Writes msg to stderr as C’s bytes, as cgraph’s default_usererrf (lib/cgraph/agerror.c) does: up to the first NUL, with control characters other than white space written as \ooo.
has_raw
Whether s holds raw-byte chars (non-UTF-8 input bytes).
raw_char
The char that stands for the raw (non-UTF-8) byte b; encode turns it back.