sortkey.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*****************************************************************************
* Copyright (C) 1996-2014, International Business Machines Corporation and others.
* All Rights Reserved.
*****************************************************************************
*
* File sortkey.h
*
* Created by: Helena Shih
*
* Modification History:
*
* Date Name Description
*
* 6/20/97 helena Java class name change.
* 8/18/97 helena Added internal API documentation.
* 6/26/98 erm Changed to use byte arrays and memcmp.
*****************************************************************************
*/
#ifndef SORTKEY_H
#define SORTKEY_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_COLLATION
#include "unicode/uobject.h"
#include "unicode/unistr.h"
#include "unicode/coll.h"
U_NAMESPACE_BEGIN
/* forward declaration */
class RuleBasedCollator;
class CollationKeyByteSink;
class U_I18N_API CollationKey : public UObject {
public:
CollationKey();
CollationKey(const uint8_t* values,
int32_t count);
CollationKey(const CollationKey& other);
virtual ~CollationKey();
const CollationKey& operator=(const CollationKey& other);
bool operator==(const CollationKey& source) const;
bool operator!=(const CollationKey& source) const;
UBool isBogus(void) const;
const uint8_t* getByteArray(int32_t& count) const;
#ifdef U_USE_COLLATION_KEY_DEPRECATES
uint8_t* toByteArray(int32_t& count) const;
#endif
#ifndef U_HIDE_DEPRECATED_API
Collator::EComparisonResult compareTo(const CollationKey& target) const;
#endif /* U_HIDE_DEPRECATED_API */
UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
int32_t hashCode(void) const;
virtual UClassID getDynamicClassID() const override;
static UClassID U_EXPORT2 getStaticClassID();
private:
uint8_t *reallocate(int32_t newCapacity, int32_t length);
void setLength(int32_t newLength);
uint8_t *getBytes() {
return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
}
const uint8_t *getBytes() const {
return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
}
int32_t getCapacity() const {
return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
}
int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
CollationKey& setToBogus(void);
CollationKey& reset(void);
friend class RuleBasedCollator;
friend class CollationKeyByteSink;
// Class fields. sizeof(CollationKey) is intended to be 48 bytes
// on a machine with 64-bit pointers.
// We use a union to maximize the size of the internal buffer,
// similar to UnicodeString but not as tight and complex.
// (implicit) *vtable;
int32_t fFlagAndLength;
mutable int32_t fHashCode;
union StackBufferOrFields {
uint8_t fStackBuffer[32];
struct {
uint8_t *fBytes;
int32_t fCapacity;
} fFields;
} fUnion;
};
inline bool
CollationKey::operator!=(const CollationKey& other) const
{
return !(*this == other);
}
inline UBool
CollationKey::isBogus() const
{
return fHashCode == 2; // kBogusHashCode
}
inline const uint8_t*
CollationKey::getByteArray(int32_t &count) const
{
count = getLength();
return getBytes();
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_COLLATION */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif
icu::CollationKey
Collation keys are generated by the Collator class.
Definition: sortkey.h:101
icu::CollationKey::~CollationKey
virtual ~CollationKey()
Sort key destructor.
icu::CollationKey::CollationKey
CollationKey(const CollationKey &other)
Copy constructor.
icu::CollationKey::getDynamicClassID
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::CollationKey::compareTo
UCollationResult compareTo(const CollationKey &target, UErrorCode &status) const
Convenience method which does a string(bit-wise) comparison of the two collation keys.
icu::CollationKey::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::CollationKey::CollationKey
CollationKey(const uint8_t *values, int32_t count)
Creates a collation key based on the collation key values.
icu::CollationKey::compareTo
Collator::EComparisonResult compareTo(const CollationKey &target) const
Convenience method which does a string(bit-wise) comparison of the two collation keys.
icu::CollationKey::CollationKey
CollationKey()
This creates an empty collation key based on the null string.
icu::CollationKey::operator=
const CollationKey & operator=(const CollationKey &other)
Assignment operator.
icu::CollationKey::operator==
bool operator==(const CollationKey &source) const
Compare if two collation keys are the same.
icu::CollationKey::hashCode
int32_t hashCode(void) const
Creates an integer that is unique to the collation key.
icu::Collator::EComparisonResult
EComparisonResult
LESS is returned if source string is compared to be less than target string in the compare() method.
Definition: coll.h:221
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition: tblcoll.h:115
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
coll.h
C++ API: Collation Service.
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
UCollationResult
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition: ucol.h:76
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
unistr.h
C++ API: Unicode String.
uobject.h
C++ API: Common ICU base class UObject.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301