Skip to main content

TrimCodepoints

Short summary

This function removes whitespace both from the start and the 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 TrimCodepoints :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;
TrimCodepoints := codepointCount;
RETURN ((codepoints = 0) OR_ELSE (codepointcount = 0));

newCodepointCount := TrimRightCodepoints(
codepoints := codepoints,
codepointCount := codepointCount
);

newCodepointCount := TrimLeftCodepoints(
codepoints := codepoints,
codepointCount := newCodepointCount
);
TrimCodepoints := newCodepointCount;