Skip to main content

TrimLeftCodepoints

Short summary

This function removes whitespace from the left side (start) of a unicode character sequence. It returns the new character count.

  • Return type: UDINT

Parameters

NameTypeCommentKind
codepointsPOINTER TO UnicodeCodePointpointer to the codepoint sequenceinput
codepointCountUDINTnumber of codepoints in the sequenceinput
newCodepointCountUDINTnumber of codepoints after trimmingoutput

Code

Declaration

FUNCTION TrimLeftCodepoints :UDINT
VAR_INPUT
(* pointer to the codepoint sequence *)
codepoints :POINTER TO UnicodeCodePoint;
(* number of codepoints in the sequence *)
codepointCount :UDINT;
END_VAR
VAR_OUTPUT
(* number of codepoints after trimming *)
newCodepointCount :UDINT := 0;
END_VAR
VAR
index, whitespaceCount :UDINT;
END_VAR

Implementation

newCodepointCount  := codepointCount;
TrimLeftCodepoints := codepointCount;
RETURN ((codepoints = 0) OR_ELSE (codepointcount = 0));
whitespaceCount := 0;

index := 0;
WHILE (index < codepointCount) DO
IF CheckCodepointIsWhitespace(codepoints[index]) THEN
codepoints[index] := 16#0000_0000;
index := index + 1;
whitespaceCount := whitespaceCount + 1;
ELSE
EXIT;
END_IF
END_WHILE
newCodepointCount := codepointCount - whitespaceCount;
Tc2_System.MEMCPY(codepoints, ADR(codepoints[index]), (codepointcount - index)*SIZEOF(UnicodeCodePoint));
TrimLeftCodepoints := newCodepointCount;