Skip to main content

startsWith

Short summary

This assertion method checks if the current string stringToCheck starts with start

Attention: All strings are handled as null terminated byte/word streams. For UTF-8 is end of the string 16#00 For UTF-16 is end of the string 16#00_00

Attention: The interface IUnicodeAssertions uses ANY_STRING, for this it's not possible to use literals/constants, because for ANY types generates the compiler __SYSTEM.AnyType and __SYSTEM.AnyType contains a pointer

Attention: start of the string is ALWAYS the left side of the string even for writings which written from right to left like Hebrew or Arabic

Parameters

NameTypeCommentKind
stringToCheckANY_STRINGcurrent string to checkinput
startANY_STRINGexpected start of stringToCheckinput
messageAssertMessagemessage if the assertion is falseinput
ignoreCasesBOOLTRUE means ignore cases; FALSE means cases must be equal tooinput
trimBOOLTRUE means truncation of spaces on the left side of stringToCheckinput
normalizeStringsBOOLnormalize both strings for checkinput

Code

Declaration

METHOD startsWith
VAR_INPUT
(* current string to check *)
stringToCheck :ANY_STRING;
(* expected start of ``stringToCheck`` *)
start :ANY_STRING;
(* message if the assertion is false *)
message :AssertMessage;
(* ``TRUE`` means ignore cases; ``FALSE`` means cases must be equal too *)
ignoreCases :BOOL := FALSE;
(* ``TRUE`` means truncation of spaces on the left side of ``stringToCheck``*)
trim :BOOL := FALSE;
(*normalize both strings for check*)
normalizeStrings :BOOL := TRUE;
END_VAR

Implementation

IF ((
stringToCheck.TypeClass <> start.TypeClass
) OR_ELSE (
stringToCheck.diSize = 0
) OR_ELSE (
start.diSize = 0
)
) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('startsWith'));
RETURN;
END_IF

CASE stringToCheck.TypeClass OF
TYPE_CLASS.TYPE_STRING:
THIS^.utf8Assertions.startsWith(
stringToCheck := stringToCheck.pValue,
start := start.pValue,
ignoreCases := ignoreCases,
trim := trim,
message := message,
normalizeStrings := normalizeStrings
);
TYPE_CLASS.TYPE_WSTRING:
THIS^.utf16Assertions.startsWith(
stringToCheck := stringToCheck.pValue,
start := start.pValue,
ignoreCases := ignoreCases,
trim := trim,
message := message,
normalizeStrings := normalizeStrings
);
ELSE
; // do nothing
END_CASE