NormalizeAnyString
Short summary
This functions transforms a given AnyString into the selected normalization form and returns the normalized string or wstring. To learn more about normalization forms of unicode, check this: https://unicode.org/reports/tr15/
Attention: the provided normalizedStringBuffer must have an appropiate size, otherwise ther normalized string will be cut!
- Return type:
UDINT
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| stringToNormalize | ANY_STRING | adrress of the utf-16 encoded string or word array (must be also null terminated!) | input |
| normalizedStringBuffer | PVOID | address of the buffer in which the normalized string is stored. e.g. ADR(myNormalizedString) | input |
| bufferSize | UDINT | size of the normalized string buffer in bytes, e.g. SIZEOF(myNormalizedWString) | input |
| normalForm | NormalizationForm | normalized form | input |
| normalizedStringLength | UDINT | length of the normalized string. If the given bufferSize is smaller, the normalized string will be cut! | output |
Code
Declaration
FUNCTION NormalizeAnyString :UDINT
VAR_INPUT
(* adrress of the utf-16 encoded string or word array (must be also null terminated!) *)
stringToNormalize :ANY_STRING;
(* address of the buffer in which the normalized string is stored.
e.g. ADR(myNormalizedString) *)
normalizedStringBuffer :PVOID;
(* size of the normalized string buffer in bytes, e.g. SIZEOF(myNormalizedWString) *)
bufferSize :UDINT;
(* normalized form *)
normalForm :NormalizationForm := NormalizationForm.NFC;
END_VAR
VAR_OUTPUT
(* length of the normalized string. If the given bufferSize is smaller, the normalized string will be cut! *)
normalizedStringLength :UDINT;
END_VAR
Implementation
NormalizeAnyString := 0;
RETURN((stringToNormalize.pValue = 0) OR stringToNormalize.diSize <= 0);
CASE stringToNormalize.TypeClass OF
__SYSTEM.TYPE_CLASS.TYPE_STRING:
NormalizeUtf8String(
utf8StringBuffer := stringToNormalize.pValue,
normalForm := normalForm,
normalizedStringBuffer := normalizedStringBuffer,
bufferSize := bufferSize,
normalizedStringLength => normalizedStringLength);
__SYSTEM.TYPE_CLASS.TYPE_WSTRING:
NormalizeUtf16String(
utf16StringBuffer := stringToNormalize.pValue,
normalForm := normalForm,
normalizedStringBuffer := normalizedStringBuffer,
bufferSize := bufferSize,
normalizedStringLength => normalizedStringLength);
ELSE
; // do nothing
END_CASE
NormalizeAnyString := normalizedStringLength;