StrPut() section Parameters
In Unicode versions of AutoHotkey all of these seem to return a size value in UTF-16 code-units.Encoding [...] Specify an empty string or "CP0" to use the system default ANSI code page.
Code: Select all
MsgBox % StrPut("𐍈") ; 3
MsgBox % StrPut("𐍈", "") ; 3
MsgBox % StrPut("𐍈", "UTF-16") ; 3
In Unicode versions of AutoHotkey specify an empty string "" to use UTF-16. In ANSI versions of AutoHotkey specify an empty string "" or "CP0" to use the system default ANSI code page.
StrPut() section Return Value
The second sentence leaves implicit which code units the returned buffer size value uses. This expansion would make that clear.This function returns the number of characters written. If no Target was given, it returns the required buffer size in characters.
If no Target was given, it returns the required buffer size in the target encoding's code units (e.g. 1 byte (8bit) units for "UTF-8", 2 byte (16bit) units for "UTF-16") and the size includes the null-terminator.
StrPut() section Examples
Inbetween example #1 and #2 add some simple examples that only showcase returning the buffer size with different target encodings.
Code: Select all
StrPut("𐍈") ; 3
StrPut("𐍈", "") ; 3
StrPut("𐍈", "UTF-16") ; 3
; Target encoding is "UTF-16" so the return value is in 16-bit code units
; and 2 16-bit code units for "𐍈" + 1 for null-terminator = 3
StrPut("𐍈", "UTF-8") ; 5
; Target encoding is "UTF-8" so the return value is in 8-bit code units
; and 4 8-bit code units for "𐍈" + 1 for null-terminator = 5
Suggestion added 2021-03-09:
StrPut() section Parameters
Source should be changed to String.Length must not be omitted unless the buffer size is known to be sufficient, such as if the buffer was allocated based on a previous call to StrPut with the same Source and Encoding.