Skip to main content

startsWith

Short summary

This assertion method checks if the current string stringToCheck starts with string start. Processed strings must be in Windows-1252 or Windows-1251 encoding

Attention: All strings are handled as null-terminated byte streams

Parameters

NameTypeCommentKind
stringToCheckPOINTER TO BYTEcurrent string to checkinput
startPOINTER TO BYTEexpected start of stringToCheckinput
ignoreCasesBOOLTRUE means ignore cases; FALSE means that cases must be equal tooinput
trimBOOLTRUE means truncation of spaces on the left side of stringToCheckinput
messageAssertMessagemessage if the assertion is falseinput
sbcsTypeTc2_Utilities.E_SBCSTypeused Single Byte Character Set (SBCS), is set in Tc2_Utilities.GLOBAL_SBCS_TABLEinput

Code

Declaration

METHOD startsWith
VAR_INPUT
(* current string to check *)
stringToCheck :POINTER TO BYTE;
(* expected start of ``stringToCheck`` *)
start :POINTER TO BYTE;
(* ``TRUE`` means ignore cases; ``FALSE`` means that cases must be equal too *)
ignoreCases :BOOL;
(* ``TRUE`` means truncation of spaces on the left side of ``stringToCheck``*)
trim :BOOL;
(* message if the assertion is false *)
message :AssertMessage;
(* used Single Byte Character Set (SBCS), is set in Tc2_Utilities.GLOBAL_SBCS_TABLE *)
sbcsType :Tc2_Utilities.E_SBCSType := Tc2_Utilities.E_SBCSType.eSBCS_WesternEuropean;
END_VAR
VAR
(* length of current string to check *)
lengthStringToCheck :UDINT;
(* length of ``start`` *)
lengthOfStart :UDINT;
(* string address we use to compare, if it's case sensitive it's equal to ``stringToCheck`` *)
usedStringToCheck :POINTER TO BYTE;
(* seacrch string address we use to compare, if it's case sensitive it's equal to ``start`` *)
usedStartString :POINTER TO BYTE;
END_VAR

Implementation

lengthStringToCheck := THIS^.getStringLength(stringToCheck);
lengthOfStart := THIS^.getStringLength(start);

THIS^.trimLeft(stringToCheck, lengthStringToCheck, trim);
THIS^.trimLeft(start, lengthOfStart, trim);

IF (
NOT THIS^.isContainsCheckNecessary(
stringToCheck := stringToCheck,
searchString := start,
lengthStringToCheck := lengthStringToCheck,
lengthSearchString := lengthOfStart,
additionalText := THIS^.getDebugInfo('startsWith'),
message := message
)
) THEN
RETURN;
END_IF

usedStringToCheck := THIS^.getNewUpperCaseString(stringToCheck, lengthStringToCheck, ignoreCases, sbcsType := sbcsType);
usedStartString := THIS^.getNewUpperCaseString(start, lengthOfStart, ignoreCases, sbcsType := sbcsType);

IF (Tc2_System.MEMCMP(
usedStringToCheck,
usedStartString,
lengthOfStart
) <> CNM_ReturnTypes.ComparationResult.EQUAL
) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('startsWith'));
END_IF;

THIS^.freeMemory(usedStringToCheck, ignoreCases);
THIS^.freeMemory(usedStartString, ignoreCases);