isNotEqualTo
Short summary
This assertion method for utf-16 strings checks if the current string stringToCheck is not equal to the unexpected string
Attention: All strings are handled as null terminated word streams. For UTF-16 is end of the string 16#00_00
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| stringToCheck | POINTER TO WORD | current string to check | input |
| unexpected | POINTER TO WORD | stringToCheck must be not equal to unexpected | input |
| ignoreCases | BOOL | TRUE means ignore cases; FALSE means cases must be equal too | input |
| message | AssertMessage | message if the assertion is false | input |
| normalizeStrings | BOOL | normalize both strings for check | input |
Code
Declaration
METHOD isNotEqualTo
VAR_INPUT
(* current string to check *)
stringToCheck :POINTER TO WORD;
(* ``stringToCheck`` must be not equal to unexpected *)
unexpected :POINTER TO WORD;
(* ``TRUE`` means ignore cases; ``FALSE`` means 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 ``stringToCheck`` in characters *)
lengthStringToCheck :UDINT;
(* length of ``stringToCheck`` in bytes *)
lengthStringToCheckInByte :UDINT;
(* length of ``stringToCheck`` in words *)
lengthStringToCheckInWord :UDINT;
(* length of ``expected`` in characters *)
lengthUnexpectedString :UDINT;
(* length of ``expected`` in characters *)
lengthUnexpectedStringInByte :UDINT;
(* length of ``expected`` in characters *)
lengthUnexpectedStringInWord :UDINT;
(* string address we use to compare, if it's case sensitive it's equal to ``stringToCheck`` *)
usedStringToCheck :POINTER TO WORD;
(* seacrch string address we use to compare, if it's case sensitive it's equal to ``expected`` *)
usedUnexpectedString :POINTER TO WORD;
(* DWORD array we use to check *)
usedCodePointsToCheck, normalizedUsedCodePointsToCheck :POINTER TO CNM_UnicodeUtilities.UnicodeCodePoint;
usedCodePointToCheckCount :UDINT;
(* DWORD array we use to compare *)
usedUnexpectedCodePoints, normalizedUsedUnexpectedCodePointCount :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
CNM_UnicodeUtilities.GetUtf16StringLength(
stringToCheck,
wordCount => lengthStringToCheckInWord,
characterCount => lengthStringToCheck
);
CNM_UnicodeUtilities.GetUtf16StringLength(
unexpected,
wordCount => lengthUnexpectedStringInWord,
characterCount => lengthUnexpectedString
);
RETURN ((
lengthStringToCheckInWord = 0 OR_ELSE lengthUnexpectedStringInWord = 0
) OR_ELSE (
(lengthStringToCheckInWord <> lengthUnexpectedStringInWord) AND_THEN (NOT normalizeStrings)
)
);
usedCodePointsToCheck := __NEW(CNM_UnicodeUtilities.UnicodeCodePoint, (lengthStringToCheckInWord+1));
IF (usedCodePointsToCheck = 0) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('utf16IsNotEqualTo, malloc failed'));
RETURN;
END_IF
usedUnexpectedCodePoints := __NEW(CNM_UnicodeUtilities.UnicodeCodePoint, (lengthUnexpectedStringInWord+1));
IF (usedUnexpectedCodePoints = 0) THEN
__DELETE(usedCodePointsToCheck);
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('utf16IsNotEqualTo, malloc failed'));
RETURN;
END_IF
(* convert ``stringToCheck`` to code points *)
CNM_UnicodeUtilities.GetCodepointsFromUtf16String(
utf16StringAddress := stringToCheck,
utf16StringWordCount := lengthStringToCheckInWord,
codepointBuffer := usedCodePointsToCheck,
bufferSize := SIZEOF(CNM_UnicodeUtilities.UnicodeCodePoint)*(lengthStringToCheckInWord+1),
codePointCount => usedCodePointToCheckCount);
(* convert ``searchString`` to code points *)
CNM_UnicodeUtilities.GetCodepointsFromUtf16String(
utf16StringAddress := unexpected,
utf16StringWordCount := lengthUnexpectedStringInWord,
codepointBuffer := usedUnexpectedCodePoints,
bufferSize := SIZEOF(CNM_UnicodeUtilities.UnicodeCodePoint)*(lengthUnexpectedStringInWord+1),
codePointCount => usedUnexpectedCodePointCount);
IF normalizeStrings THEN
normalizedUsedCodePointsToCheck := __NEW(CNM_UnicodeUtilities.UnicodeCodePoint, (lengthStringToCheckInWord * NORMALIZATION_FACTOR));
IF (normalizedUsedCodePointsToCheck = 0) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('utf16IsNotEqualTo'));
__DELETE(usedCodePointsToCheck);
__DELETE(usedUnexpectedCodePoints);
RETURN;
END_IF
normalizedUsedUnexpectedCodePointCount := __NEW(CNM_UnicodeUtilities.UnicodeCodePoint, (lengthUnexpectedStringInWord * NORMALIZATION_FACTOR));
IF (normalizedUsedUnexpectedCodePointCount = 0) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('utf16IsNotEqualTo'));
__DELETE(usedCodePointsToCheck);
__DELETE(usedUnexpectedCodePoints);
__DELETE(normalizedUsedCodePointsToCheck);
RETURN;
END_IF
CNM_UnicodeUtilities.NormalizeCodepointsFormD(
codePoints := usedCodePointsToCheck,
codePointsCount := usedCodePointToCheckCount,
normalizedCodepoints := normalizedUsedCodePointsToCheck,
bufferSize := (lengthStringToCheckInWord * NORMALIZATION_FACTOR) * SIZEOF(CNM_UnicodeUtilities.UnicodeCodePoint),
normalizedCodepointsCount => usedCodePointToCheckCount
);
__DELETE(usedCodePointsToCheck);
usedCodePointsToCheck := normalizedUsedCodePointsToCheck;
CNM_UnicodeUtilities.NormalizeCodepointsFormD(
codePoints := usedUnexpectedCodePoints,
codePointsCount := usedUnexpectedCodePointCount,
normalizedCodepoints := normalizedUsedUnexpectedCodePointCount,
bufferSize := (lengthUnexpectedStringInWord * NORMALIZATION_FACTOR) * SIZEOF(CNM_UnicodeUtilities.UnicodeCodePoint),
normalizedCodepointsCount => usedUnexpectedCodePointCount
);
__DELETE(usedUnexpectedCodePoints);
usedUnexpectedCodePoints := normalizedUsedUnexpectedCodePointCount;
IF (usedCodePointToCheckCount <> usedUnexpectedCodePointCount) THEN
__DELETE(usedCodePointsToCheck);
__DELETE(usedUnexpectedCodePoints);
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('utf16IsNotEqualTo'));
END_IF;
__DELETE(usedCodePointsToCheck);
__DELETE(usedUnexpectedCodePoints);