Example #1
0
MojErr MojDbTextCollator::sortKey(const UChar* chars, MojSize size, MojDbKey& keyOut) const
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

	MojErr err = MojErrNone;
	MojObjectWriter writer;

	if (size == 0) {
		err = writer.stringValue(_T(""), 0);
		MojErrCheck(err);
	} else {
		// get sort key
		MojInt32 destCapacity = 0;
		MojInt32 destLength = 0;
		MojDbKey::ByteVec vec;
		err = vec.resize(size * 3);
		MojErrCheck(err);
		do {
			MojByte* dest = NULL;
			err = vec.begin(dest);
			MojErrCheck(err);
			destCapacity = (MojInt32) vec.size();
			destLength = ucol_getSortKey(m_ucol, chars, (MojInt32) size, dest, destCapacity);
			if (destLength == 0) {
				MojErrThrow(MojErrDbUnicode);
			}
			err = vec.resize(destLength);
			MojErrCheck(err);
		} while (destLength > destCapacity);
		// write it
		MojAssert(vec.size() >= 1 && vec.back() == _T('\0'));
		err = writer.stringValue((const MojChar*) vec.begin(), vec.size() - 1);
		MojErrCheck(err);
	}
	err = keyOut.assign(writer.buf());
	MojErrCheck(err);

	return MojErrNone;
}
Example #2
0
MojErr MojDbIndexTest::assertContains(TestIndex& ti, MojObject id, const MojDbKey& key)
{
	MojDbKey prefixedKey(key);
	MojErr err = prefixedKey.byteVec().insert(0, 1, MojObjectWriter::MarkerZeroIntValue);
	MojErrCheck(err);
	if (ti.m_incDel) {
		MojDbKey::ByteVec vec = prefixedKey.byteVec();
		MojErr err = vec.insert(1, 1, MojObjectWriter::MarkerTrueValue);
		MojTestErrCheck(err);
		MojDbKey keyTrue;
		err = keyTrue.assign(vec.begin(), vec.size());
		MojTestErrCheck(err);

		err = vec.setAt(1, MojObjectWriter::MarkerFalseValue);
		MojTestErrCheck(err);
		MojDbKey keyFalse;
		err = keyFalse.assign(vec.begin(), vec.size());
		MojTestErrCheck(err);
		MojTestAssert(ti.m_set.contains(keyTrue) || ti.m_set.contains(keyFalse));
	} else {
		MojTestAssert(ti.m_set.contains(prefixedKey));
	}
	return MojErrNone;
}