yaro
yaro

Reputation: 33

TCL Format Command Returns Wrong UTF-8 Characters

I am implementing a socket client in TCL only. The server needs to be informed of the length of the message sent by the client, so I prepend the length of message with a utf-8 character of the message length. I converted the message length to utf-8 character using the TCL Format command.

However, the Format command does not always return the correct utf-8 character which confuses the server. For example in the sample code below format returns § for 21 and 167:

% format %c 21
§
% format %c 167
§

Could it be that I am doing something wrong?

Upvotes: 0

Views: 231

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137627

The § should come from format %c 167; that's exactly as expected given that it is the section sign character. By contrast, format %c 21 should produce a non-printable NAK character, though for some reason your terminal is rendering it differently. (I'm not sure what interpretation it is falling back to; it's not one that is listed in an encoding table that I have conveniently at hand.)

Tcl's probably doing exactly the right thing, especially as the NAK character is present in most common character encodings.

Upvotes: 1

Related Questions