Skip to main content

isNotEqualTo

Short summary

This assertion method checks if the current string stringToCheck is not equal to unexpected. Processed strings must be in UTF-8 encoding

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

Parameters

NameTypeCommentKind
stringToCheckPOINTER TO BYTEcurrent string to checkinput
unexpectedPOINTER TO BYTEstringToCheck must be not equal to expectedinput
ignoreCasesBOOLTRUE means ignore cases; FALSE means that cases must be equal tooinput
messageAssertMessagemessage if the assertion is falseinput
normalizeStringsBOOLnormalize both strings for checkinput

Code

Declaration

METHOD isNotEqualTo
VAR_INPUT
(* current string to check *)
stringToCheck :POINTER TO BYTE;
(* ``stringToCheck`` must be not equal to expected *)
unexpected :POINTER TO BYTE;
(* ``TRUE`` means ignore cases; ``FALSE`` means that cases must be equal too *)
ignoreCases :BOOL;
(* message if the assertion is false *)
message :AssertMessage;
(*normalize both strings for check*)
normalizeStrings :BOOL := TRUE;
END_VAR
VAR
(* length of current string to check in bytes *)
stringToCheckByteCount :UDINT;
(* length of current string to check in characters *)
stringToCheckCodePointCount :UDINT;
(* length of ``unexpected`` in bytes *)
unexpectedStringByteCount :UDINT;
(* length of ``unexpected`` in characters *)
unexpectedStringCodePointCount :UDINT;

(* DWORD array we use to check *)
usedCodePointsToCheck, normalizedUsedCodePointsToCheck :POINTER TO CNM_UnicodeUtilities.UnicodeCodePoint;
usedCodePointToCheckCount :UDINT;

(* DWORD array we use to compare *)
usedUnexpectedCodePoints, normalizedUsedUnexpectedCodePoint :POINTER TO CNM_UnicodeUtilities.UnicodeCodePoint;
usedUnexpectedCodePointCount :UDINT;
END_VAR
VAR CONSTANT
(*After decomposition one codepoint can extend up to 4 codepoints*)
NORMALIZATION_FACTOR :UDINT := 4;
END_VAR

Implementation

stringToCheckByteCount := CNM_UnicodeUtilities.GetUtf8StringLength(
stringToCheck,
byteCount => stringToCheckByteCount,
characterCount => stringToCheckCodePointCount
);

unexpectedStringByteCount := CNM_UnicodeUtilities.GetUtf8StringLength(unexpected);

RETURN ((
NOT normalizeStrings
) AND_THEN (
stringToCheckCodePointCount <> unexpectedStringCodePointCount
) AND_THEN (
NOT THIS^.isContainsNoCheckNecessary(
stringToCheck := stringToCheck,
searchString := unexpected,
lengthStringToCheck := stringToCheckByteCount,
lengthSearchString := unexpectedStringByteCount,
additionalText := THIS^.getDebugInfo('isNotEqualTo'),
message := message
)
)
);

usedCodePointsToCheck := __NEW(CNM_UnicodeUtilities.UnicodeCodePoint, stringToCheckByteCount);
IF (usedCodePointsToCheck = 0) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('isNotEqualTo, malloc failed'));
RETURN;
END_IF

usedUnexpectedCodePoints := __NEW(CNM_UnicodeUtilities.UnicodeCodePoint, unexpectedStringByteCount);
IF (usedUnexpectedCodePoints = 0) THEN
__DELETE(usedCodePointsToCheck);
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('isNotEqualTo, malloc failed'));
RETURN;
END_IF

(* convert ``stringToCheck`` to code points *)
CNM_UnicodeUtilities.GetCodepointsFromUtf8String(
utf8StringAddress := stringToCheck,
utf8StringByteCount := stringToCheckByteCount,
codePointBuffer := usedCodePointsToCheck,
bufferSize := SIZEOF(CNM_UnicodeUtilities.UnicodeCodePoint)*stringToCheckByteCount,
codePointsCount => usedCodePointToCheckCount);

(* convert ``searchString`` to code points *)
CNM_UnicodeUtilities.GetCodepointsFromUtf8String(
utf8StringAddress := unexpected,
utf8StringByteCount := unexpectedStringByteCount,
codePointBuffer := usedUnexpectedCodePoints,
bufferSize := SIZEOF(CNM_UnicodeUtilities.UnicodeCodePoint)*unexpectedStringByteCount,
codePointsCount => usedUnexpectedCodePointCount);



IF normalizeStrings THEN
normalizedUsedCodePointsToCheck := __NEW(
CNM_UnicodeUtilities.UnicodeCodePoint,
(stringToCheckByteCount * NORMALIZATION_FACTOR)
);
IF (normalizedUsedCodePointsToCheck = 0) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('isNotEqualTo, malloc failed'));
__DELETE(usedCodePointsToCheck);
__DELETE(usedUnexpectedCodePoints);
RETURN;
END_IF

normalizedUsedUnexpectedCodePoint := __NEW(
CNM_UnicodeUtilities.UnicodeCodePoint,
(unexpectedStringByteCount * NORMALIZATION_FACTOR)
);
IF (normalizedUsedUnexpectedCodePoint = 0) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('isNotEqualTo, malloc failed'));
__DELETE(usedCodePointsToCheck);
__DELETE(usedUnexpectedCodePoints);
__DELETE(normalizedUsedCodePointsToCheck);
RETURN;
END_IF

CNM_UnicodeUtilities.NormalizeCodepointsFormD(
codePoints := usedCodePointsToCheck,
codePointsCount := usedCodePointToCheckCount,
normalizedCodepoints := normalizedUsedCodePointsToCheck,
bufferSize := (stringToCheckByteCount * NORMALIZATION_FACTOR) * SIZEOF(CNM_UnicodeUtilities.UnicodeCodePoint),
normalizedCodepointsCount => usedCodePointToCheckCount
);
__DELETE(usedCodePointsToCheck);
usedCodePointsToCheck := normalizedUsedCodePointsToCheck;

CNM_UnicodeUtilities.NormalizeCodepointsFormD(
codePoints := usedUnexpectedCodePoints,
codePointsCount := usedUnexpectedCodePointCount,
normalizedCodepoints := normalizedUsedUnexpectedCodePoint,
bufferSize := (unexpectedStringByteCount * NORMALIZATION_FACTOR) * SIZEOF(CNM_UnicodeUtilities.UnicodeCodePoint),
normalizedCodepointsCount => usedUnexpectedCodePointCount
);
__DELETE(usedUnexpectedCodePoints);
usedUnexpectedCodePoints := normalizedUsedUnexpectedCodePoint;

IF ( usedUnexpectedCodePointCount <> usedCodePointToCheckCount) THEN
__DELETE(usedUnexpectedCodePoints);
__DELETE(usedCodePointsToCheck);
RETURN;
END_IF
END_IF


IF (ignoreCases) THEN
CNM_UnicodeUtilities.GetUpperCaseForCodepoint(usedCodePointsToCheck, usedCodePointToCheckCount);
CNM_UnicodeUtilities.GetUpperCaseForCodepoint(usedUnexpectedCodePoints, usedUnexpectedCodePointCount);
END_IF

IF (Tc2_System.MEMCMP(
usedCodePointsToCheck,
usedUnexpectedCodePoints,
usedUnexpectedCodePointCount * SIZEOF(CNM_UnicodeUtilities.UnicodeCodePoint)
) = CNM_ReturnTypes.ComparationResult.EQUAL
) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('isNotEqualTo'));
END_IF;

__DELETE(usedCodePointsToCheck);
__DELETE(usedUnexpectedCodePoints);