Skip to main content

contains

Short summary

This assertion method checks if the current string stringToCheck contains the search string

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

Parameters

NameTypeCommentKind
stringToCheckANY_STRINGcurrent string to checkinput
searchStringANY_STRINGstring must be found in stringToCheckinput
messageAssertMessagemessage if the assertion is falseinput
ignoreCasesBOOLTRUE means ignore cases; FALSE means cases must be equal tooinput
normalizeStringsBOOLnormalize both strings for checkinput

Code

Declaration

METHOD contains
VAR_INPUT
(* current string to check *)
stringToCheck :ANY_STRING;
(* string must be found in ``stringToCheck`` *)
searchString :ANY_STRING;
(* message if the assertion is false *)
message :AssertMessage;
(* ``TRUE`` means ignore cases; ``FALSE`` means cases must be equal too *)
ignoreCases :BOOL := FALSE;
(*normalize both strings for check*)
normalizeStrings :BOOL := TRUE;
END_VAR

Implementation

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

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