Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created November 13, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennadel/4c634f607135dae90b6f50fc69fc9239 to your computer and use it in GitHub Desktop.
Save bennadel/4c634f607135dae90b6f50fc69fc9239 to your computer and use it in GitHub Desktop.
Adding Differ() And DifferNoCase() Built-In Function Extensions In Lucee CFML 5.3.7.47
<cfscript>
/**
* I determine if the two values are different use a CASE SENSITIVE operation.
*
* @valueA I am the first value to compare.
* @valueB I am the second value to compare.
*/
public boolean function differ(
required string valueA,
required string valueB
) {
// The compare() method performs a CASE SENSITIVE operation and returns 0 if the
// values are the SAME; and, a non-zero result if the two values are different.
var isSameValue = ( compare( valueA, valueB ) == 0 );
return( ! isSameValue );
}
</cfscript>
<cfscript>
/**
* I determine if the two values are different use a CASE INSENSITIVE operation.
*
* @valueA I am the first value to compare.
* @valueB I am the second value to compare.
*/
public boolean function differNoCase(
required string valueA,
required string valueB
) {
// The compareNoCase() method performs a CASE INSENSITIVE operation and returns 0
// if the values are the SAME; and, a non-zero result if the two values are different.
var isSameValue = ( compareNoCase( valueA, valueB ) == 0 );
return( ! isSameValue );
}
</cfscript>
<cfscript>
// Testing prior to deploying the .lex file.
// --
// include "./ext/functions/differ.cfm";
// include "./ext/functions/differNoCase.cfm";
echoMany( "differ( a, A ) &rarr;", differ( "a", "A" ) );
echoMany( "differ( A, A ) &rarr;", differ( "A", "A" ) );
echoMany( "differ( A, Z ) &rarr;", differ( "A", "Z" ) );
echoMany();
echoMany( "differNoCase( a, A ) &rarr;", differNoCase( "a", "A" ) );
echoMany( "differNoCase( A, A ) &rarr;", differNoCase( "A", "A" ) );
echoMany( "differNoCase( A, Z ) &rarr;", differNoCase( "A", "Z" ) );
// ------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------- //
/**
* I collapse the variadic arguments down into a space-delimited list and echo them to
* the output. A <BR> tag is added automatically.
*
* @1...N Simple values to output.
*/
public void function echoMany() {
echo( arrayToList( arguments, " " ) & "<br />" );
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment