Beispiel #1
0
MojErr MojDbIndexTest::assertContainsText(TestIndex& ti, MojObject id, const MojChar* str)
{
	MojString strObj;
	MojErr err = strObj.assign(str);
	MojErrCheck(err);
	MojRefCountedPtr<MojDbTextCollator> collator(new MojDbTextCollator);
	MojAllocCheck(collator.get());
	err = collator->init(_T("en_US"), MojDbCollationPrimary);
	MojTestErrCheck(err);
	MojDbKey key;
	err = collator->sortKey(strObj, key);
	MojTestErrCheck(err);

	MojObjectWriter writer;
	err = id.visit(writer);
	MojTestErrCheck(err);
	const MojByte* idData = NULL;
	MojSize idSize = 0;
	err = writer.buf().data(idData, idSize);
	MojTestErrCheck(err);
	err = key.byteVec().append(idData, idData + idSize);
	MojTestErrCheck(err);
	err = assertContains(ti, id, key);
	MojTestErrCheck(err);

	return MojErrNone;
}
Beispiel #2
0
MojErr MojDbIndexTest::assertContains(TestIndex& ti, MojObject id, MojObject key)
{
	MojObjectWriter writer;
	MojErr err = key.visit(writer);
	MojTestErrCheck(err);
	err = id.visit(writer);
	MojTestErrCheck(err);
	MojDbKey compoundKey;
	err = compoundKey.assign(writer.buf());
	MojTestErrCheck(err);
	err = assertContains(ti, id, compoundKey);
	MojTestErrCheck(err);

	return MojErrNone;
}
Beispiel #3
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;
}