icu_ext.c
/*
 * Compare two strings with the given collation.
 * Return the result as a signed integer, similarly to strcoll().
 */
Compare two strings with the given collation.
Return the result as a signed integer, similarly to strcoll().
Compare two strings with the given collation . Return the result as a signed integer similarly to strcoll () .
Datum
icu_compare_coll(PG_FUNCTION_ARGS)
{
	text *txt1 = PG_GETARG_TEXT_PP(0);
	text *txt2 = PG_GETARG_TEXT_PP(1);	
	const char *collname = text_to_cstring(PG_GETARG_TEXT_P(2));
	UCollator	*collator = NULL;
	UErrorCode	status = U_ZERO_ERROR;
	UCollationResult result;
	collator = ucol_open(collname, &status);
	if (!collator || U_FAILURE(status)) {
		elog(ERROR, "failed to open collation: %s", u_errorName(status));
	}
	result = our_strcoll(txt1, txt2, collator);
	ucol_close(collator);
	PG_RETURN_INT32(result == UCOL_EQUAL ? 0 :
					(result == UCOL_GREATER ? 1 : -1));
}
Datum icu_compare_coll ( PG_FUNCTION_ARGS ) { text * txt1 = PG_GETARG_TEXT_PP ( 0 ) ; text * txt2 = PG_GETARG_TEXT_PP ( 1 ) ; const char * collname = text_to_cstring ( PG_GETARG_TEXT_P ( 2 ) ) ; UCollator * collator = NULL ; UErrorCode status = U_ZERO_ERROR ; UCollationResult result ; collator = ucol_open ( collname , & status ) ; if ( ! collator || U_FAILURE ( status ) ) { elog ( ERROR , " " , u_errorName ( status ) ) ; } result = our_strcoll ( txt1 , txt2 , collator ) ; ucol_close ( collator ) ; PG_RETURN_INT32 ( result == UCOL_EQUAL ? 0 : ( result == UCOL_GREATER ? 1 : -1 ) ) ; }
Compare two strings with the given collation.
Compare two strings with the given collation .