endsWith
Short summary
This assertion method checks if the current string stringToCheck ends with the string end.
Processed strings must be in Windows-1252 or Windows-1251 encoding
Attention: All strings are handled as null-terminated byte streams
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| stringToCheck | POINTER TO BYTE | current string to check | input |
| end | POINTER TO BYTE | string must be the end of stringToCheck | input |
| ignoreCases | BOOL | TRUE means ignore cases; FALSE means that cases must be equal too | input |
| trim | BOOL | TRUE means truncation of spaces on the right side of stringToCheck | input |
| message | AssertMessage | message if the assertion is false | input |
| sbcsType | Tc2_Utilities.E_SBCSType | used Single Byte Character Set (SBCS), is set in Tc2_Utilities.GLOBAL_SBCS_TABLE | input |
Code
Declaration
METHOD endsWith
VAR_INPUT
(* current string to check *)
stringToCheck :POINTER TO BYTE;
(* string must be the end of ``stringToCheck`` *)
end :POINTER TO BYTE;
(* ``TRUE`` means ignore cases; ``FALSE`` means that cases must be equal too *)
ignoreCases :BOOL;
(* ``TRUE`` means truncation of spaces on the right 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 ``end`` *)
lengthOfEnd :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 ``end`` *)
usedEndString :POINTER TO BYTE;
END_VAR
Implementation
lengthStringToCheck := THIS^.getStringLength(stringToCheck);
lengthOfEnd := THIS^.getStringLength(end);
THIS^.trimRight(stringToCheck, lengthStringToCheck, trim);
THIS^.trimRight(end, lengthOfEnd, trim);
IF (
NOT THIS^.isContainsCheckNecessary(
stringToCheck := stringToCheck,
searchString := end,
lengthStringToCheck := lengthStringToCheck,
lengthSearchString := lengthOfEnd,
additionalText := THIS^.getDebugInfo('endsWith'),
message := message
)
) THEN
RETURN;
END_IF
usedStringToCheck := THIS^.getNewUpperCaseString(stringToCheck, lengthStringToCheck, ignoreCases, sbcsType := sbcsType);
usedEndString := THIS^.getNewUpperCaseString(end, lengthOfEnd, ignoreCases, sbcsType := sbcsType);
IF (Tc2_System.MEMCMP(
ADR(usedStringToCheck[lengthStringToCheck - lengthOfEnd]),
usedEndString,
lengthOfEnd
) <> CNM_ReturnTypes.ComparationResult.EQUAL
) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('endsWith'));
END_IF;
THIS^.freeMemory(usedStringToCheck, ignoreCases);
THIS^.freeMemory(usedEndString, ignoreCases);