Skip to main content

DecomposeSingleCodepoint

Short summary

This function recomposes a single codepoint recursively and writes the NFD form into the given codepoint buffer.

  • Return type: UDINT

Parameters

NameTypeCommentKind
codepointPOINTER TO UnicodeCodePointpointer to codepointinput
bufferPOINTER TO UnicodeCodePointpointer to bufferinput
lengthUDINTnumber of decomposed codepointsoutput

Code

Declaration

{warning disable C0561}
FUNCTION INTERNAL DecomposeSingleCodepoint
VAR_INPUT
(* pointer to codepoint *)
codepoint :POINTER TO UnicodeCodePoint;
(* pointer to buffer *)
buffer :POINTER TO UnicodeCodePoint;
END_VAR
VAR_OUTPUT
(* number of decomposed codepoints *)
length :UDINT;
END_VAR
VAR
countCurrent :UDINT;
countRecursive :UDINT;
tmpBuffer :ARRAY[0..3] OF UnicodeCodePoint;
END_VAR
{warning restore C0561}

Implementation

{warning disable C0561}
countCurrent := 0;
countRecursive := 0;
length := 0;
RETURN((codepoint = 0) OR_ELSE (buffer = 0));

IF GetCodepointDecomposition(
codepoint := codepoint,
newCodepoints := ADR(tmpBuffer[0]),
numberOfCodepoints => countCurrent
)
THEN
DecomposeSingleCodepoint(
codepoint := ADR(tmpBuffer[0]),
buffer := buffer,
length => countRecursive
);

Tc2_System.MEMCPY(
destAddr := ADR(buffer[countRecursive]),
srcAddr := ADR(tmpBuffer[1]),
n := SIZEOF(UnicodeCodepoint)*countCurrent-1
);
length := countCurrent-1 + countRecursive;
ELSE
buffer[0] := codepoint^;
length := 1;
END_IF
{warning restore C0561}