本文整理汇总了C++中CStr::SafeP方法的典型用法代码示例。如果您正苦于以下问题:C++ CStr::SafeP方法的具体用法?C++ CStr::SafeP怎么用?C++ CStr::SafeP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CStr
的用法示例。
在下文中一共展示了CStr::SafeP方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReplaceStrI
CStr ReplaceStrI(CStr in, CStr from, CStr to)
{
char *p;
int fl = from.Length(), tl = to.Length(), il = in.Length();
if (fl <= 0 || fl > il)
return in;
if (fl == tl) {
char *i = in.SafeP();
char *b = i;
while ((p = stristr(i, (il-(i-b)), from, fl))) {
memcpy(p, to.Data(), tl);
i = p + fl;
}
return in;
} else {
CStr res;
char *i = in.SafeP();
while ((p = stristr(i, il-(i-in.Data()), from, fl))) {
res.Append(i, p - i);
if (tl > 0)
res << to;
i = p + fl;
}
if (i != in.Data()) {
res.Append(i, il - (i - in.Data()));
return res;
} else {
return in;
}
}
}
示例2: EvalMid
void EvalMid(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
if (args->Count() >= 2) {
CStr tmp = (*args)[0];
int index = ParseInt((*args)[1]);
if (args->Count() >= 3) {
int len = ParseInt((*args)[2]);
if (abs(index) < tmp.Length()) {
if (index >= 0) {
out->PutS(tmp.SafeP() + index, min(tmp.Length()-index, len));
} else {
out->PutS(tmp.SafeP() + max(tmp.Length() + index - abs(len), 0), min(tmp.Length(), len));
}
}
} else {
if (abs(index) < tmp.Length()) {
if (index >= 0) {
out->PutS(tmp.SafeP() + index, tmp.Length()-index);
} else {
out->PutS(tmp.SafeP(), tmp.Length() + index);
}
}
}
}
}
示例3: EvalWcmX
void EvalWcmX(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
if (args->Count() > 1) {
CStr a = (*args)[0];
CStr b = (*args)[1];
if (IsWcmX(a.SafeP(),b.SafeP())) {
out->PutC('T');
}
}
}
示例4: EvalCsvQuote
void EvalCsvQuote(const void *data, qCtx *ctx, qStr *out, qArgAry *args)
{
if (args->Count() > 0) {
CStr s = (*args)[0];
char *bi = s.SafeP();
const char *pi = bi;
while (*pi) {
if (*pi == '\"' || *pi == ',') {
CStr o(s.Length()*2 + 2);
char *po = o.SafeP();
*po++ = '\"';
memcpy(po, s.Data(), pi-bi);
CsvQuoteQ(pi, po);
*po++ = '\"';
o.Grow(po - o.Data());
out->PutS(o,o.Length());
return;
}
++pi;
}
out->PutS(s,s.Length());
}
}
示例5: EvalFmt
void EvalFmt(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
CStr val = (*args)[0];
ColFmt col;
memset(&col, 0, sizeof(col));
col.dec = args->Count() > 1 ? ParseInt((*args)[1]) : 2;
if (args->Count() > 2) {
CStr dch = (*args)[2];
col.dch = (dch.IsEmpty()) ? 0 : *dch;
} else
col.dch = '.';
if (args->Count() > 3) {
CStr tho = (*args)[3];
col.tho = (tho.IsEmpty()) ? 0 : *tho;
} else
col.tho = ',';
CStr res(256);
double dval;
const char *p = CTabFmt::NumFmt(col, val.SafeP(), res.GetBuffer(), 256, &dval);
out->PutS(p);
}
示例6: EVP_decrypt
CStr EVP_decrypt(CStr passw, CStr strin, const char *cipher)
{
int len = strin.Length();
if (len > 0 && passw.Length() > 0) {
strin.Grow(len + EVP_MAX_IV_LENGTH);
return strin.Grow(
EVP_decrypt(passw.SafeP(), passw.Length(), strin.GetBuffer(), len, cipher)
);
} else
return strin;
}
示例7: EvalEnumToken
void EvalEnumToken(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
if (args->Count() >= 3) {
// todo, ParseFork arg zero into a blocking i/o stream...
CStr dat = (*args)[0];
CStr toks = (*args)[1];
qCtxTmp sub(ctx);
char *b = dat.SafeP();
char *t = toks.SafeP();
const char *p = b + strspn(b, t);
char *e;
bool ok = true;
int skip = 0;
sub.MapObj(&p, "token");
sub.MapObj(&ok, (QOBJFUNC) EvalBreak, "break");
sub.MapObj(&skip, (QOBJFUNC) EvalSkipTokens, "skip-tokens");
while (p && *p && ok) {
e = strpbrk(p, t);
if (e) {
*e = 0;
if (!skip)
sub.Parse(args->GetAt(2),out);
else
--skip;
p = (++e) + strspn(e, t);
} else {
if (!skip)
sub.Parse(args->GetAt(2),out);
else
--skip;
break;
}
}
}
}
示例8: EvalLeft
void EvalLeft(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
if (args->Count() >= 2) {
CStr tmp = (*args)[0];
int index = ParseInt((*args)[1]);
if (index > 0) {
if (index < tmp.Length()) {
out->PutS(tmp.SafeP(), index);
} else {
out->PutS(tmp);
}
}
}
}
示例9: EvalGetToken
void EvalGetToken(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
if (args->Count() >= 3) {
// todo, ParseFork arg zero into a blocking i/o stream...
CStr dat = (*args)[0];
CStr toks = (*args)[1];
int ind = ParseInt((*args)[2]);
qCtxTmp sub(ctx);
char *b = dat.SafeP();
char *t = toks.SafeP();
const char *p = b + strspn(b, t);
char *e;
sub.MapObj(&p, "token");
while (p && *p) {
e = strpbrk(p, t);
if (e) {
*e = 0;
if (--ind < 0)
break;
p = (++e) + strspn(e, t);
} else {
if (ind > 0)
return;
else
break;
}
}
if (p) {
out->PutS(p);
}
}
}
示例10: EvalCsvQuoteQ
void EvalCsvQuoteQ(const void *data, qCtx *ctx, qStr *out, qArgAry *args)
{
if (args->Count() > 0) {
CStr s = (*args)[0];
CStr o(s.Length()*2 + 2);
char *bi = s.SafeP();
const char *pi = bi;
char *po = o.SafeP();
*po++ = '\"';
CsvQuoteQ(pi, po);
*po++ = '\"';
o.Grow(po - o.Data());
out->PutS(o,o.Length());
}
}
示例11: Connect
CDbConn CDbLib::Connect(char *dsn)
{
char *uid, *pwd, *etc;
ParseDSN(dsn, dsn, uid, pwd, etc);
qObjTSRef ts = GetRef();
if (myHENV) {
TRACE("sql: spawning connection\n");
SQLHDBC hdbc;
SQLRETURN nResult;
if ((nResult = SQLAllocHandle(SQL_HANDLE_DBC, myHENV, &hdbc) != SQL_SUCCESS)) {
return CDbConn(this, (SQLHDBC)NULL);
}
if (etc && *etc) {
CStr connIn;
connIn = CStr("DSN=")<<dsn<<";UID="<<uid<<";PWD="<<pwd<<';'<<etc;
CStr connOut(1024);
short totLen;
nResult = SQLDriverConnect(hdbc, NULL, (LPSQLC) connIn.SafeP(), connIn.Length(), (LPSQLC) connOut.SafeP(), connOut.Length(), &totLen, SQL_DRIVER_NOPROMPT);
} else {
nResult = SQLConnect(hdbc, (LPSQLC) dsn, SQL_NTS, (LPSQLC) uid, SQL_NTS, (LPSQLC) pwd, SQL_NTS);
}
// if failed to connect, free the allocated hdbc before return
if (!SQL_SUCCEEDED(nResult)) {
CDbConn conn(this, hdbc);
conn.SetError(nResult);
return conn;
}
return CDbConn(this, hdbc);
} else {
return CDbConn(this, (SQLHDBC)NULL);
}
}
示例12: EvalPcase
void EvalPcase(const void *data, qCtx *ctx, qStr *out, qArgAry *args)
{
if (args->Count() > 0) {
CStr s = (*args)[0];
char *p = s.SafeP();
char *c=0;
while (*p) {
if (c) {
if (!isalnum(*p)) {
pcasew(c, p);
c = 0;
}
} else {
if (isalpha(*p))
c = p;
}
++p;
}
if (c) {
pcasew(c,p);
}
out->PutS(s,s.Length());
}
}
示例13: ParseDbl
double ParseDbl(const CStr &str) {
char *ep;
return strtod(str.SafeP(), &ep);
}
示例14: ParseInt
int ParseInt(const CStr &str) {
return atoi(str.SafeP());
}