Skip to main content

GetUpperCaseUtf16

Short summary

This function converts the lower case characters in the given UTF16 string to upper case .

Example:

myString :WString(10) := "Test" ;

------------------
UpperCaseUtf16(
stringAddress := ADR(myString)
);

Parameters

NameTypeCommentKind
stringAddressPOINTER TO WORDpointer to the utf-16 stringinput
buffersizeUDINTsize of the string variable in bytesinput

Code

Declaration

FUNCTION GetUpperCaseUtf16
VAR_INPUT
(*pointer to the utf-16 string*)
stringAddress :POINTER TO WORD;
(* size of the string variable in bytes *)
buffersize :UDINT := 0;
END_VAR
VAR
stringLength :UDINT;
codepoints :POINTER TO UnicodeCodePoint;
codepointCount :UDINT;
END_VAR

Implementation

GetUtf16StringLength(stringAddress, wordCount => stringLength);
RETURN (stringLength = 0);
codepoints := __NEW(UnicodeCodepoint, stringLength);
RETURN(codepoints = 0);

GetCodepointsFromUtf16String(
utf16StringAddress := stringAddress,
utf16StringWordCount := stringLength,
codepointBuffer := codepoints,
bufferSize := stringLength*SIZEOF(UnicodeCodepoint),
codePointCount => codepointCount
);

GetUpperCaseForCodepoint(
addressOfCodePoints := codepoints,
codePointCount := codepointCount
);

Tc2_System.MEMSET(stringAddress, 0, MAX(stringLength*SIZEOF(WORD), buffersize));

(*buffersize is stringLength + 1 as the string terminator is not counted in string length*)
GetUtf16StringFromCodepoints(
addressOfCodePoints := codepoints,
codePointCount := codepointCount,
stringBuffer := stringAddress,
bufferSize := MAX((stringLength+1)*SIZEOF(WORD), buffersize) // there was a null terminator in the original string, so the actual buffersize is length+1
);

__DELETE(codepoints);