Skip to main content

TrimRightCodepoints

Short summary

This function removes whitespace from the right side (end) 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 TrimRightCodepoints :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;
END_VAR
VAR
index, whitespaceCount :UDINT;
END_VAR

Implementation

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

index := codepointCount - 1;
WHILE (index >= 0) 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;
TrimRightCodepoints := newCodepointCount;