MCPcopy Create free account
hub / github.com/documentdb/documentdb / GetCollationSortKey

Function GetCollationSortKey

pg_documentdb_core/src/collation/collation.c:533–555  ·  view source on GitHub ↗

* Convenience function to generate a collation aware sortkey that can be used in strcmp(). * * Two calls to ucol_getSortKey() is a pattern used in pg code. This is to know the expected size * of the sort key so that we allocate a larger buffer if needed. * Reference: https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/ucol_8h.html#a58be2c76d01184cb1821ff0af28081c2 * Reference: https:

Source from the content-addressed store, hash-verified

531 * Reference: https://unicode-org.github.io/icu/userguide/collation/api.html
532 */
533inline char *
534GetCollationSortKey(const char *collationString, char *key, int keyLength)
535{
536 ucollator_cache_entry *collation_entry = LookupUCollatorCache(collationString);
537
538 uint8_t *sortKeyPtr = palloc(DEFAULT_ICU_COLLATION_SORT_KEY_LENGTH);
539 UChar *uchar;
540 int32_t ulen;
541
542 ulen = icu_to_uchar_core(&uchar, key, keyLength);
543 Size expectedLength = ucol_getSortKey(collation_entry->collator, uchar, ulen,
544 sortKeyPtr,
545 DEFAULT_ICU_COLLATION_SORT_KEY_LENGTH);
546 if (expectedLength > DEFAULT_ICU_COLLATION_SORT_KEY_LENGTH)
547 {
548 sortKeyPtr = repalloc(sortKeyPtr, expectedLength);
549 ucol_getSortKey(collation_entry->collator, uchar, ulen, sortKeyPtr,
550 expectedLength);
551 }
552
553 pfree(uchar);
554 return (char *) sortKeyPtr;
555}
556
557
558/*

Callers 2

BsonValueHashFuncCoreFunction · 0.85
HashBsonValueCompareFunction · 0.85

Calls 2

LookupUCollatorCacheFunction · 0.85
icu_to_uchar_coreFunction · 0.85

Tested by

no test coverage detected