Products Downloads


French version


 

This function compares two values with simple types (String/Number/Boolean/Date/Time/Date-time).

It returns 0 if the two values are equal. It returns a value lower than 0 if the first value is strictly lower than the second. It returns a value higher than 0 if the first value is higher than the second.

When the two values are String type, the comparison mode is lexicographic. The "opts" parameter can be used to define a comparison using a collation enabling two character strings to be compared according to a given language.

 

Parameters

String/Number/Boolean/Date/Time/Date-time

compVal1

Simple-type value to compare

Mandatory

String/Number/Boolean/Date/Time/Date-time

compVal2

Simple-type value to compare

Mandatory

Hash

opts

Definition of comparison options. This object can have the following attributes:

  • "stringComp": alphanumeric string. Used to define the comparison mode for two String-type values. Two possible values:
      • "lexico": lexicographic comparison (by default),
      • "localeBased": comparison using a collation.
  • "collator": if "stringComp" is "localeBased", this attribute describes the collation used. By default, the collation is associated with the template execution locale. By default, the "strength" and "decomposition" attributes have values which depend on the locale. The collation is a hash object with the following attributes:
      • "locale": string in IETF BCP 47 format identifying a locale for the comparison,
      • "strength": string representing the strength of the collation to determine the level of difference considered as significant in the comparisons. Five values are provided: "identical", "primary", "secondary", "tertiary" and "quaternary",
      • "decomposition": string representing the collation decomposition mode. It determines the processing of Unicode combining characters. Setting the decomposition mode enables the user to choose between a quicker and fuller classification behavior. Three values are provided: "no_decomposition", "canonical_decomposition" and "full_decomposition"

Optional.

 


For example

<#assign stringVal1 = "foo" />
<#assign stringVal2 = "bar" />
<#assign opts = {"stringComp": "localeBased",
	"collator": {"locale": "en-GB",
	"strength": "primary"}
	} /> 


<#assign compare = hardisCore.compare (stringVal1, stringVal2, opts) />
<#if compare == 0>
${stringVal1} equals ${stringVal2}
<#elseif compare > 0>
${stringVal1} is greater than ${stringVal2}
<#else>
${stringVal1} is less than ${stringVal2}
</#if> 

 

Another example

<#assign compare = hardisCore.compare ("2015-05-23"?date.xs, "2017-10-04"?date.xs) /> 


↑ Top of page