forceUnicode: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\|seealso= *\[\[([^ ]+)\]\], \[\[([^ ]+)\]\]" to "|seealso= $1 $2")
m (Some wiki formatting)
(5 intermediate revisions by the same user not shown)
Line 6: Line 6:
|gr1= Strings
|gr1= Strings


|descr= Sets the Unicode flag which forces some of the string manipulation commands to switch to Unicode. The Unicode flag is always set right after [[forceUnicode]] command execution, but is reset depending on the command mode:  
|descr=
* 1 - the Unicode flag is reset right after any of the supported commands executed or the end of script, whichever comes earlier.
<div style="float: right">
* 0 - the Unicode flag is reset at the end of the script.
List of the commands that work with [[forceUnicode]]:
When the flag is set it will also affect all scopes within the script including child scopes (see also: [[diag_scope]]). There are many other string manipulation commands like [[ctrlSetText]], [[getTextWidth]], etc. that support Unicode by design so no additional forcing is needed.
{{Columns|2|
<br><br>List of the commands that work with [[forceUnicode]]:
{{Columns|5|
* [[copyFromClipboard]]
* [[copyFromClipboard]]
* [[copyToClipboard]]
* [[copyToClipboard]]
Line 26: Line 24:
* [[regexReplace]]
* [[regexReplace]]
}}
}}
</div>
Sets the Unicode flag which forces some of the string manipulation commands to switch to Unicode. The Unicode flag is always set right after [[forceUnicode]] command execution, but is reset depending on the command mode:
* 1 - the Unicode flag is reset right after any of the supported commands executed or the end of script, whichever comes earlier.
* 0 - the Unicode flag is reset at the end of the script.
When the flag is set it will also affect all scopes within the script including child scopes (see also: [[diag_scope]]). There are many other string manipulation commands like [[ctrlSetText]], [[getTextWidth]], etc. that support Unicode by design so no additional forcing is needed.


|s1= [[forceUnicode]] mode
|s1= [[forceUnicode]] mode
Line 36: Line 39:
|r1= [[Anything]]
|r1= [[Anything]]


|x1= <code>[[copyToClipboard]] "д"; {{cc|Copies "д" to clipboard}}
|x1= <sqf>
copyToClipboard "д"; // copies "д" to clipboard


[[forceUnicode]] 1;
forceUnicode 1;
[[copyToClipboard]] "д"; {{cc|Copies "д" to clipboard}}</code>
copyToClipboard "д"; // copies "д" to clipboard
</sqf>


|x2= <code>[[private]] _string [[a = b|=]] "привет"; {{cc|a string that uses Unicode characters}}
|x2= <sqf>
[[systemChat]] [[str]] [[count]] _string; {{cc|12 - the character count is wrong without [[forceUnicode]]}}
private _string = "привет"; // a string that uses Unicode characters
systemChat str count _string; // 12 - the character count is wrong without forceUnicode


[[call]] {
call {
[[systemChat]] [[str]] [[count]] _string; {{cc|12 - identical result}}
systemChat str count _string; // 12 - identical result
[[forceUnicode]] 0;
forceUnicode 0;
[[systemChat]] [[str]] [[count]] _string; {{cc|6 - correct result}}
systemChat str count _string; // 6 - correct result
};
};


[[systemChat]] [[str]] [[count]] _string; {{cc|6 - outer scope is affected by [[forceUnicode]] as well, because the command mode is 0}}
systemChat str count _string; // 6 - outer scope is affected by forceUnicode as well, because the command mode is 0


[[forceUnicode]] -1; {{cc| cancelled}}
forceUnicode -1; // cancelled


[[call]] {
call {
[[systemChat]] [[str]] [[count]] _string; {{cc|12 - wrong count}}
systemChat str count _string; // 12 - wrong count
[[forceUnicode]] 1;
forceUnicode 1;
[[systemChat]] [[str]] [[count]] _string; {{cc|6 - correct result, but Unicode it reset after this operation, because command mode is 1}}
systemChat str count _string; // 6 - correct result, but Unicode it reset after this operation, because command mode is 1
};
};


[[systemChat]] [[str]] [[count]] _string; {{cc|12 - outer scope is not affected as it was reset right after [[count]]}}</code>
systemChat str count _string; // 12 - outer scope is not affected as it was reset right after count
</sqf>


|seealso= [[copyToClipboard]] [[copyFromClipboard]] [[select]], [[count]], [[in]], [[insert]], [[find]], [[splitString]] [[reverse]]
|seealso= [[copyToClipboard]] [[copyFromClipboard]] [[select]] [[count]] [[in]] [[insert]] [[find]] [[splitString]] [[reverse]]
}}
}}

Revision as of 14:49, 5 May 2022

Hover & click on the images for description

Description

Description:

Sets the Unicode flag which forces some of the string manipulation commands to switch to Unicode. The Unicode flag is always set right after forceUnicode command execution, but is reset depending on the command mode:

  • 1 - the Unicode flag is reset right after any of the supported commands executed or the end of script, whichever comes earlier.
  • 0 - the Unicode flag is reset at the end of the script.
When the flag is set it will also affect all scopes within the script including child scopes (see also: diag_scope). There are many other string manipulation commands like ctrlSetText, getTextWidth, etc. that support Unicode by design so no additional forcing is needed.
Groups:
Strings

Syntax

Syntax:
forceUnicode mode
Parameters:
mode: Number - Mode of operation, can be:
  • -1 - resets previously set Unicode flag
  •  0 - sets Unicode flag until the end of script
  •  1 - sets Unicode flag until after next supported command or until the end of script, whichever comes earlier
Return Value:
Anything

Examples

Example 1:
copyToClipboard "д"; // copies "д" to clipboard forceUnicode 1; copyToClipboard "д"; // copies "д" to clipboard
Example 2:
private _string = "привет"; // a string that uses Unicode characters systemChat str count _string; // 12 - the character count is wrong without forceUnicode call { systemChat str count _string; // 12 - identical result forceUnicode 0; systemChat str count _string; // 6 - correct result }; systemChat str count _string; // 6 - outer scope is affected by forceUnicode as well, because the command mode is 0 forceUnicode -1; // cancelled call { systemChat str count _string; // 12 - wrong count forceUnicode 1; systemChat str count _string; // 6 - correct result, but Unicode it reset after this operation, because command mode is 1 }; systemChat str count _string; // 12 - outer scope is not affected as it was reset right after count

Additional Information

See also:
copyToClipboard copyFromClipboard select count in insert find splitString reverse

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note