(May be this should be in the Swift Format category... I'm not too familiar with this forum. I will move this topic if this is not the right place. )
says that
"Because the
%s
specifier causes the characters to be interpreted in the system default encoding, the results can be variable, especially with right-to-left languages. For example, with RTL,%s
inserts direction markers when the characters are not strongly directional. For this reason, it’s best to avoid%s
and specify encodings explicitly."
Is it true that my UTF-8 characters are interpreted in the system default encoding if I do
"my string".withCString { String(format: "%-10s", $0) }
?
While I'm at it, how do I know what my system default encoding in Swift? Isn't it always UTF-8?
If one must specify encodings explicitly, how is it done when using this kind of formatting?
I'm not sure I understand the relationship between "interpreted in the system default encoding" and the "For example with RTL inserts direction markers when the characters are not strongly directional". Does this mean that the default encoding is used to establish the default directionality (are we by default in Hebrew/Arabic or rather in Latin as this machine is a Latin machine)?
I was going to ask whether the latest Unicode Bidi algorithm is implemented by %s? (E.g. are Directional isolates and Bracket Pairs taken into consideration?), but it seems that %s garbles the Arabic text:
let rtl = "The Car is السيارة in arabic."
print (rtl);
print (rtl.withCString {String(format: "%s", $0)})
The Car is السيارة in arabic.
The Car is السيارة in arabic.
Lastly, is there something more native in Swift (which does not require using .withCString) to format strings (minimum length, padding, etc.)