本文整理汇总了C++中STRPTR函数的典型用法代码示例。如果您正苦于以下问题:C++ STRPTR函数的具体用法?C++ STRPTR怎么用?C++ STRPTR使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了STRPTR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find_wordentry
/*
* Returns a pointer to a WordEntry's array corresponding to 'item' from
* tsvector 't'. 'q' is the TSQuery containing 'item'.
* Returns NULL if not found.
*/
static WordEntry *
find_wordentry(TSVector t, TSQuery q, QueryOperand *item, int32 *nitem)
{
WordEntry *StopLow = ARRPTR(t);
WordEntry *StopHigh = (WordEntry *) STRPTR(t);
WordEntry *StopMiddle = StopHigh;
int difference;
*nitem = 0;
/* Loop invariant: StopLow <= item < StopHigh */
while (StopLow < StopHigh)
{
StopMiddle = StopLow + (StopHigh - StopLow) / 2;
difference = WordECompareQueryItem(STRPTR(t), GETOPERAND(q), StopMiddle, item, false);
if (difference == 0)
{
StopHigh = StopMiddle;
*nitem = 1;
break;
}
else if (difference > 0)
StopLow = StopMiddle + 1;
else
StopHigh = StopMiddle;
}
if (item->prefix)
{
if (StopLow >= StopHigh)
StopMiddle = StopHigh;
*nitem = 0;
while (StopMiddle < (WordEntry *) STRPTR(t) &&
WordECompareQueryItem(STRPTR(t), GETOPERAND(q), StopMiddle, item, true) == 0)
{
(*nitem)++;
StopMiddle++;
}
}
return (*nitem > 0) ? StopHigh : NULL;
}
示例2: hstore_delete
Datum
hstore_delete(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
text *key = PG_GETARG_TEXT_PP(1);
char *keyptr = VARDATA_ANY(key);
int keylen = VARSIZE_ANY_EXHDR(key);
HStore *out = palloc(VARSIZE(hs));
char *bufs,
*bufd,
*ptrd;
HEntry *es,
*ed;
int i;
int count = HS_COUNT(hs);
int outcount = 0;
SET_VARSIZE(out, VARSIZE(hs));
HS_SETCOUNT(out, count); /* temporary! */
bufs = STRPTR(hs);
es = ARRPTR(hs);
bufd = ptrd = STRPTR(out);
ed = ARRPTR(out);
for (i = 0; i < count; ++i)
{
int len = HS_KEYLEN(es, i);
char *ptrs = HS_KEY(es, bufs, i);
if (!(len == keylen && memcmp(ptrs, keyptr, keylen) == 0))
{
int vallen = HS_VALLEN(es, i);
HS_COPYITEM(ed, bufd, ptrd, ptrs, len, vallen, HS_VALISNULL(es, i));
++outcount;
}
}
HS_FINALIZE(out, outcount, bufd, ptrd);
PG_RETURN_POINTER(out);
}
示例3: hstore_contains
Datum
hstore_contains(PG_FUNCTION_ARGS)
{
HStore *val = PG_GETARG_HS(0);
HStore *tmpl = PG_GETARG_HS(1);
bool res = true;
HEntry *te = ARRPTR(tmpl);
char *tstr = STRPTR(tmpl);
HEntry *ve = ARRPTR(val);
char *vstr = STRPTR(val);
int tcount = HS_COUNT(tmpl);
int lastidx = 0;
int i;
/*
* we exploit the fact that keys in "tmpl" are in strictly increasing
* order to narrow the hstoreFindKey search; each search can start one
* entry past the previous "found" entry, or at the lower bound of the
* search
*/
for (i = 0; res && i < tcount; ++i)
{
int idx = hstoreFindKey(val, &lastidx,
HS_KEY(te, tstr, i), HS_KEYLEN(te, i));
if (idx >= 0)
{
bool nullval = HS_VALISNULL(te, i);
int vallen = HS_VALLEN(te, i);
if (nullval != HS_VALISNULL(ve, idx)
|| (!nullval
&& (vallen != HS_VALLEN(ve, idx)
|| memcmp(HS_VAL(te, tstr, i), HS_VAL(ve, vstr, idx), vallen))))
res = false;
}
else
res = false;
}
PG_RETURN_BOOL(res);
}
示例4: hstore_index
static int hstore_index(lua_State *L) {
HStore *hs;
char *base;
HEntry *entries;
const char *key;
char *k_str;
int idx;
Lua_Hstore *strg;
BEGINLUA;
strg = lua_touserdata(L, 1);
hs = strg->hstore;
base = STRPTR(hs);
entries = ARRPTR(hs);
key = luaL_checkstring(L, 2);
lua_pushlightuserdata(L, strg);
lua_gettable(L, LUA_REGISTRYINDEX);
lua_pushstring(L, key);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
char *data_ptr = lua_touserdata (L, -1);
lua_pop(L,2);
if (data_ptr){
lua_pushstring(L, data_ptr);
}else {
lua_pushnil(L);
}
ENDLUAV(1);
return 1;
}
lua_pop(L,2);
k_str = strdup(key);
idx = hstoreFindKey(hs, NULL, k_str, strlen(k_str));
free(k_str);
if (idx<0|| HS_VALISNULL(entries, idx)){
lua_pushnil(L);
ENDLUAV(1);
return 1;
}
lua_pushlstring(L, HS_VAL(entries, base, idx),HS_VALLEN(entries, idx));
ENDLUAV(1);
return 1;
}
示例5: hstore_out
Datum
hstore_out(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
int buflen,
i;
char *out,
*ptr;
char *base = STRPTR(in);
HEntry *entries = ARRPTR(in);
if (in->size == 0)
{
out = palloc(1);
*out = '\0';
PG_FREE_IF_COPY(in, 0);
PG_RETURN_CSTRING(out);
}
buflen = (4 /* " */ + 2 /* => */ + 2 /* , */ ) * in->size +
2 /* esc */ * (in->len - CALCDATASIZE(in->size, 0));
out = ptr = palloc(buflen);
for (i = 0; i < in->size; i++)
{
*ptr++ = '"';
ptr = cpw(ptr, base + entries[i].pos, entries[i].keylen);
*ptr++ = '"';
*ptr++ = '=';
*ptr++ = '>';
if (entries[i].valisnull)
{
*ptr++ = 'N';
*ptr++ = 'U';
*ptr++ = 'L';
*ptr++ = 'L';
}
else
{
*ptr++ = '"';
ptr = cpw(ptr, base + entries[i].pos + entries[i].keylen, entries[i].vallen);
*ptr++ = '"';
}
if (i + 1 != in->size)
{
*ptr++ = ',';
*ptr++ = ' ';
}
}
*ptr = '\0';
PG_FREE_IF_COPY(in, 0);
PG_RETURN_CSTRING(out);
}
示例6: hstore_each
Datum
hstore_each(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
HStore *hs;
int i;
if (SRF_IS_FIRSTCALL())
{
hs = PG_GETARG_HS(0);
funcctx = SRF_FIRSTCALL_INIT();
setup_firstcall(funcctx, hs, fcinfo);
}
funcctx = SRF_PERCALL_SETUP();
hs = (HStore *) funcctx->user_fctx;
i = funcctx->call_cntr;
if (i < HS_COUNT(hs))
{
HEntry *entries = ARRPTR(hs);
char *ptr = STRPTR(hs);
Datum res,
dvalues[2];
bool nulls[2] = {false, false};
text *item;
HeapTuple tuple;
item = cstring_to_text_with_len(HS_KEY(entries, ptr, i),
HS_KEYLEN(entries, i));
dvalues[0] = PointerGetDatum(item);
if (HS_VALISNULL(entries, i))
{
dvalues[1] = (Datum) 0;
nulls[1] = true;
}
else
{
item = cstring_to_text_with_len(HS_VAL(entries, ptr, i),
HS_VALLEN(entries, i));
dvalues[1] = PointerGetDatum(item);
}
tuple = heap_form_tuple(funcctx->tuple_desc, dvalues, nulls);
res = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, PointerGetDatum(res));
}
SRF_RETURN_DONE(funcctx);
}
示例7: svals
Datum
svals(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
AKStore *st;
if (SRF_IS_FIRSTCALL())
{
HStore *hs = PG_GETARG_HS(0);
funcctx = SRF_FIRSTCALL_INIT();
setup_firstcall(funcctx, hs);
PG_FREE_IF_COPY(hs, 0);
}
funcctx = SRF_PERCALL_SETUP();
st = (AKStore *) funcctx->user_fctx;
if (st->i < st->hs->size)
{
HEntry *ptr = &(ARRPTR(st->hs)[st->i]);
if (ptr->valisnull)
{
ReturnSetInfo *rsi;
st->i++;
(funcctx)->call_cntr++;
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
rsi->isDone = ExprMultipleResult;
PG_RETURN_NULL();
}
else
{
int vallen = ptr->vallen;
text *item = (text *) palloc(VARHDRSZ + vallen);
SET_VARSIZE(item, VARHDRSZ + vallen);
memcpy(VARDATA(item), STRPTR(st->hs) + ptr->pos + ptr->keylen, vallen);
st->i++;
SRF_RETURN_NEXT(funcctx, PointerGetDatum(item));
}
}
pfree(st->hs);
pfree(st);
SRF_RETURN_DONE(funcctx);
}
示例8: hs_contains
Datum
hs_contains(PG_FUNCTION_ARGS)
{
HStore *val = PG_GETARG_HS(0);
HStore *tmpl = PG_GETARG_HS(1);
bool res = true;
HEntry *te = ARRPTR(tmpl);
char *vv = STRPTR(val);
char *tv = STRPTR(tmpl);
while (res && te - ARRPTR(tmpl) < tmpl->size)
{
HEntry *entry = findkey(val, tv + te->pos, te->keylen);
if (entry)
{
if (te->valisnull || entry->valisnull)
{
if (!(te->valisnull && entry->valisnull))
res = false;
}
else if (te->vallen != entry->vallen ||
strncmp(vv + entry->pos + entry->keylen,
tv + te->pos + te->keylen,
te->vallen))
res = false;
}
else
res = false;
te++;
}
PG_FREE_IF_COPY(val, 0);
PG_FREE_IF_COPY(tmpl, 1);
PG_RETURN_BOOL(res);
}
示例9: find_wordentry
static WordEntry *
find_wordentry(tsvector * t, QUERYTYPE * q, ITEM * item)
{
WordEntry *StopLow = ARRPTR(t);
WordEntry *StopHigh = (WordEntry *) STRPTR(t);
WordEntry *StopMiddle;
int difference;
/* Loop invariant: StopLow <= item < StopHigh */
while (StopLow < StopHigh)
{
StopMiddle = StopLow + (StopHigh - StopLow) / 2;
difference = WordECompareITEM(STRPTR(t), GETOPERAND(q), StopMiddle, item);
if (difference == 0)
return StopMiddle;
else if (difference < 0)
StopLow = StopMiddle + 1;
else
StopHigh = StopMiddle;
}
return NULL;
}
示例10: hstore_to_array_internal
static ArrayType *
hstore_to_array_internal(HStore *hs, int ndims)
{
HEntry *entries = ARRPTR(hs);
char *base = STRPTR(hs);
int count = HS_COUNT(hs);
int out_size[2] = {0, 2};
int lb[2] = {1, 1};
Datum *out_datums;
bool *out_nulls;
int i;
Assert(ndims < 3);
if (count == 0 || ndims == 0)
return construct_empty_array(TEXTOID);
out_size[0] = count * 2 / ndims;
out_datums = palloc(sizeof(Datum) * count * 2);
out_nulls = palloc(sizeof(bool) * count * 2);
for (i = 0; i < count; ++i)
{
text *key = cstring_to_text_with_len(HS_KEY(entries, base, i),
HS_KEYLEN(entries, i));
out_datums[i * 2] = PointerGetDatum(key);
out_nulls[i * 2] = false;
if (HS_VALISNULL(entries, i))
{
out_datums[i * 2 + 1] = (Datum) 0;
out_nulls[i * 2 + 1] = true;
}
else
{
text *item = cstring_to_text_with_len(HS_VAL(entries, base, i),
HS_VALLEN(entries, i));
out_datums[i * 2 + 1] = PointerGetDatum(item);
out_nulls[i * 2 + 1] = false;
}
}
return construct_md_array(out_datums, out_nulls,
ndims, out_size, lb,
TEXTOID, -1, false, 'i');
}
示例11: gin_extract_hstore
Datum
gin_extract_hstore(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL;
*nentries = 2 * hs->size;
if (hs->size > 0)
{
HEntry *ptr = ARRPTR(hs);
char *words = STRPTR(hs);
int i = 0;
entries = (Datum *) palloc(sizeof(Datum) * 2 * hs->size);
while (ptr - ARRPTR(hs) < hs->size)
{
text *item;
item = makeitem(words + ptr->pos, ptr->keylen);
*VARDATA(item) = KEYFLAG;
entries[i++] = PointerGetDatum(item);
if (ptr->valisnull)
{
item = makeitem(NULL, 0);
*VARDATA(item) = NULLFLAG;
}
else
{
item = makeitem(words + ptr->pos + ptr->keylen, ptr->vallen);
*VARDATA(item) = VALFLAG;
}
entries[i++] = PointerGetDatum(item);
ptr++;
}
}
PG_FREE_IF_COPY(hs, 0);
PG_RETURN_POINTER(entries);
}
示例12: hstore_svals
Datum
hstore_svals(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
HStore *hs;
int i;
if (SRF_IS_FIRSTCALL())
{
hs = PG_GETARG_HS(0);
funcctx = SRF_FIRSTCALL_INIT();
setup_firstcall(funcctx, hs, NULL);
}
funcctx = SRF_PERCALL_SETUP();
hs = (HStore *) funcctx->user_fctx;
i = funcctx->call_cntr;
if (i < HS_COUNT(hs))
{
HEntry *entries = ARRPTR(hs);
if (HS_VALISNULL(entries, i))
{
ReturnSetInfo *rsi;
/* ugly ugly ugly. why no macro for this? */
(funcctx)->call_cntr++;
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
rsi->isDone = ExprMultipleResult;
PG_RETURN_NULL();
}
else
{
text *item;
item = cstring_to_text_with_len(HS_VAL(entries, STRPTR(hs), i),
HS_VALLEN(entries, i));
SRF_RETURN_NEXT(funcctx, PointerGetDatum(item));
}
}
SRF_RETURN_DONE(funcctx);
}
示例13: hstore_to_jsonb
Datum
hstore_to_jsonb(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
HEntry *entries = ARRPTR(in);
JsonbParseState *state = NULL;
JsonbValue *res;
res = pushJsonbValue(&state, WJB_BEGIN_OBJECT, NULL);
for (i = 0; i < count; i++)
{
JsonbValue key, val;
key.estSize = sizeof(JEntry);
key.type = jbvString;
key.val.string.len = HS_KEYLEN(entries, i);
key.val.string.val = pnstrdup(HS_KEY(entries, base, i), key.val.string.len);
key.estSize += key.val.string.len;
res = pushJsonbValue(&state, WJB_KEY, &key);
if (HS_VALISNULL(entries, i))
{
val.estSize = sizeof(JEntry);
val.type = jbvNull;
}
else
{
val.estSize = sizeof(JEntry);
val.type = jbvString;
val.val.string.len = HS_VALLEN(entries, i);
val.val.string.val = pnstrdup(HS_VAL(entries, base, i), val.val.string.len);
val.estSize += val.val.string.len;
}
res = pushJsonbValue(&state, WJB_VALUE, &val);
}
res = pushJsonbValue(&state, WJB_END_OBJECT, NULL);
PG_RETURN_POINTER(JsonbValueToJsonb(res));
}
示例14: hstore_fetchval
Datum
hstore_fetchval(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
text *key = PG_GETARG_TEXT_PP(1);
HEntry *entries = ARRPTR(hs);
text *out;
int idx = hstoreFindKey(hs, NULL,
VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
if (idx < 0 || HS_VALISNULL(entries, idx))
PG_RETURN_NULL();
out = cstring_to_text_with_len(HS_VAL(entries, STRPTR(hs), idx),
HS_VALLEN(entries, idx));
PG_RETURN_TEXT_P(out);
}
示例15: hstore_avals
Datum
hstore_avals(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
Datum *d;
bool *nulls;
ArrayType *a;
HEntry *entries = ARRPTR(hs);
char *base = STRPTR(hs);
int count = HS_COUNT(hs);
int lb = 1;
int i;
if (count == 0)
{
a = construct_empty_array(TEXTOID);
PG_RETURN_POINTER(a);
}
d = (Datum *) palloc(sizeof(Datum) * count);
nulls = (bool *) palloc(sizeof(bool) * count);
for (i = 0; i < count; ++i)
{
if (HS_VALISNULL(entries, i))
{
d[i] = (Datum) 0;
nulls[i] = true;
}
else
{
text *item = cstring_to_text_with_len(HS_VAL(entries, base, i),
HS_VALLEN(entries, i));
d[i] = PointerGetDatum(item);
nulls[i] = false;
}
}
a = construct_md_array(d, nulls, 1, &count, &lb,
TEXTOID, -1, false, 'i');
PG_RETURN_POINTER(a);
}