static void
test_Cat(TestBatchRunner *runner) {
    ByteBuf *bb = BB_new_bytes("foo", 3);

    {
        Blob *blob = Blob_new("bar", 3);
        BB_Cat(bb, blob);
        TEST_TRUE(runner, BB_Equals_Bytes(bb, "foobar", 6), "Cat");
        DECREF(blob);
    }

    BB_Cat_Bytes(bb, "baz", 3);
    TEST_TRUE(runner, BB_Equals_Bytes(bb, "foobarbaz", 9), "Cat_Bytes");

    DECREF(bb);
}
示例#2
0
static void
test_Cat(TestBatchRunner *runner) {
    ByteBuf *wanted  = BB_new_bytes("foobar", 6);
    ByteBuf *got     = BB_new_bytes("foo", 3);
    ByteBuf *scratch = BB_new_bytes("bar", 3);

    BB_Cat(got, scratch);
    TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Cat");

    BB_Mimic_Bytes(wanted, "foobarbaz", 9);
    BB_Cat_Bytes(got, "baz", 3);
    TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Cat_Bytes");

    DECREF(scratch);
    DECREF(got);
    DECREF(wanted);
}
示例#3
0
文件: DocVector.c 项目: unlobe/lucy
static Hash*
S_extract_tv_cache(Blob *field_buf) {
    Hash       *tv_cache  = Hash_new(0);
    const char *tv_string = Blob_Get_Buf(field_buf);
    int32_t     num_terms = NumUtil_decode_ci32(&tv_string);
    ByteBuf    *text_buf  = BB_new(0);

    // Read the number of highlightable terms in the field.
    for (int32_t i = 0; i < num_terms; i++) {
        size_t   overlap = NumUtil_decode_cu32(&tv_string);
        size_t   len     = NumUtil_decode_cu32(&tv_string);

        // Decompress the term text.
        BB_Set_Size(text_buf, overlap);
        BB_Cat_Bytes(text_buf, tv_string, len);
        tv_string += len;

        // Get positions & offsets string.
        const char *bookmark_ptr  = tv_string;
        int32_t     num_positions = NumUtil_decode_ci32(&tv_string);
        while (num_positions--) {
            // Leave nums compressed to save a little mem.
            NumUtil_skip_cint(&tv_string);
            NumUtil_skip_cint(&tv_string);
            NumUtil_skip_cint(&tv_string);
        }
        len = tv_string - bookmark_ptr;

        // Store the $text => $posdata pair in the output hash.
        String *text = BB_Trusted_Utf8_To_String(text_buf);
        Hash_Store(tv_cache, text, (Obj*)Blob_new(bookmark_ptr, len));
        DECREF(text);
    }
    DECREF(text_buf);

    return tv_cache;
}