本文整理汇总了C++中MatchData类的典型用法代码示例。如果您正苦于以下问题:C++ MatchData类的具体用法?C++ MatchData怎么用?C++ MatchData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MatchData类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MatchData
void PersonItem::setUid(QString id)
{
ItemEditor::setUid(id);
// load sql
QString er;
SqlDB *db = Sql::instance()->open(er);
if (db)
{
QString sql = "SELECT * FROM "+ MatchData().objectName() +
" WHERE uid = '" + uid + "'";
int rlt;
QList<QObject *> objs = db->executeQuery(sql,
MatchData().metaObject(),
rlt, er);
db->close();
if (objs.size() >= 1)
{
MatchData *md = qobject_cast<MatchData *>(objs.first());
if (md)
{
memoname = md->getEditname();
}
}
auto it = objs.begin();
while (it != objs.end())
{
QObject *obj = *it;
delete obj;
obj = nullptr;
++it;
}
}
}
示例2: MatchData
void FriendInfo::updateMemoName()
{
QString er;
SqlDB *db = Sql::instance()->open(er);
if (db)
{
QString sql = "SELECT * FROM "+ MatchData().objectName() +
" WHERE uid = '" + data->getUid() + "'";
int rlt;
QList<QObject *> objs = db->executeQuery(sql,
MatchData().metaObject(),
rlt, er);
db->close();
if (objs.size() >= 1)
{
MatchData *md = qobject_cast<MatchData *>(objs.first());
if (md)
{
editLbl->setText(md->getEditname());
}
}
auto it = objs.begin();
while (it != objs.end())
{
QObject *obj = *it;
delete obj;
obj = nullptr;
++it;
}
}
}
示例3: get_match_data
static Object* get_match_data(STATE, OnigRegion *region, String* string, Regexp* regexp, int pos) {
MatchData* md = state->new_object<MatchData>(G(matchdata));
md->source(state, string->string_dup(state));
md->regexp(state, regexp);
Tuple* tup = Tuple::from(state, 2,
Fixnum::from(region->beg[0] + pos),
Fixnum::from(region->end[0] + pos));
md->full(state, tup);
md->region(state, _md_region_to_tuple(state, region, pos));
return md;
}
示例4: test_match_region_without_matches
void test_match_region_without_matches() {
String *pat = String::create(state, "d");
Regexp* re = Regexp::create(state);
re->initialize(state, pat, Fixnum::from(0));
String *input = String::create(state, "abc");
Fixnum* start = Fixnum::from(0);
Fixnum* end = Fixnum::from(3);
Object* forward = cTrue;
MatchData* matches = (MatchData*)re->match_region(state, input, start, end, forward);
TS_ASSERT(matches->nil_p());
}
示例5: test_match_start
void test_match_start() {
String *pat = String::create(state, ".");
Regexp* re = Regexp::create(state);
re->initialize(state, pat, Fixnum::from(0));
String *input = String::create(state, "abc");
Fixnum* start = Fixnum::from(1);
MatchData* matches = (MatchData*)re->match_start(state, input, start);
TS_ASSERT(!matches->nil_p());
TS_ASSERT_EQUALS(matches->region()->num_fields(), 0);
TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 0))->to_native(), 1);
TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 1))->to_native(), 2);
}
示例6: last_match
Object* Regexp::last_match(STATE, Arguments& args, CallFrame* call_frame) {
MatchData* match = try_as<MatchData>(call_frame->scope->last_match(state));
if(!match) return Qnil;
if(args.total() == 0) return match;
if(args.total() > 1) return Primitives::failure();
native_int which = as<Fixnum>(args.get_argument(0))->to_native();
if(which == 0) {
return match->matched_string(state);
} else {
return match->nth_capture(state, which - 1);
}
}
示例7: test_match_region
void test_match_region() {
String *pat = String::create(state, ".");
Regexp* re = Regexp::create(state);
re->initialize(state, pat, Fixnum::from(0), Qnil);
String *input = String::create(state, "abc");
Fixnum* start = Fixnum::from(0);
Fixnum* end = Fixnum::from(3);
Object* forward = Qtrue;
MatchData* matches = (MatchData*)re->match_region(state, input, start, end, forward);
TS_ASSERT(!matches->nil_p());
TS_ASSERT_EQUALS(matches->region()->num_fields(), 0U);
TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 0))->to_native(), 0);
TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 1))->to_native(), 1);
}
示例8: test_match_region_with_backward_captures
void test_match_region_with_backward_captures() {
String *pat = String::create(state, ".(.)");
Regexp* re = Regexp::create(state);
re->initialize(state, pat, Fixnum::from(0));
String *input = String::create(state, "abc");
Fixnum* start = Fixnum::from(0);
Fixnum* end = Fixnum::from(3);
Object* forward = cFalse;
MatchData* matches = re->match_region(state, input, start, end, forward);
TS_ASSERT(!matches->nil_p());
TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 0))->to_native(), 1);
TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 1))->to_native(), 3);
TS_ASSERT_EQUALS(matches->region()->num_fields(), 1);
TS_ASSERT_EQUALS(as<Integer>(as<Tuple>(matches->region()->at(state, 0))->at(state, 0))->to_native(), 2);
TS_ASSERT_EQUALS(as<Integer>(as<Tuple>(matches->region()->at(state, 0))->at(state, 1))->to_native(), 3);
}
示例9: get_match_data
static Object* get_match_data(STATE, OnigRegion *region, String* string, Regexp* regexp, int pos) {
MatchData* md = state->new_object<MatchData>(G(matchdata));
md->source(state, string->string_dup(state));
md->regexp(state, regexp);
// Unsure if the first region (the full match) can be less than 0 (meaning
// the match was length length but did still match). We have to support
// that for the > 0 case, so we'll do the same for 0.
//
if(region->beg[0] < 0) {
Tuple* tup = Tuple::from(state, 2,
Fixnum::from(region->beg[0]),
Fixnum::from(region->end[0]));
md->full(state, tup);
} else {
Tuple* tup = Tuple::from(state, 2,
Fixnum::from(region->beg[0] + pos),
Fixnum::from(region->end[0] + pos));
md->full(state, tup);
}
md->region(state, _md_region_to_tuple(state, region, pos));
return md;
}
示例10: ItemEditor
//.........这里部分代码省略.........
ui->setFirstTxt(jsondata->getNickname());
ui->setSecondTxt(memoname);
ui->setVersion(jsondata->getVersion());
ui->setThirdTxt(jsondata->getGsoapip());
ui->setIntroduceTxt(jsondata->getFeel());
ui->showAnimation();
// ui->activateWindow();
ui->move(mapToGlobal(this->pos()).x() - 360, QCursor::pos().y() - 50);
connect(emoji, &EmojiLabel::leaveEmoji, ui, [=] () {
// disconnect(emoji, &EmojiLabel::leaveEmoji, 0, 0);
ui->hideAnimation();
});
});
menu = new SelfMenu(this);
connect(menu->addAction(cns("备注名")), &QAction::triggered, this, [=] () {
bool ok;
QString name = InputBox::GetInput(cns("输入备注名"), &ok);
if (!ok)
return;
if (name.trimmed().isEmpty())
{
MsgBox::ShowMsgBox(cn("提示"), cn("不能为空"), cn("确定"));
return;
}
if (name.trimmed().length() >= 18)
{
MsgBox::ShowMsgBox(cn("错误"), cn("昵称长度18限制"), cn("确定"));
return;
}
QString er;
SqlDB *db = Sql::instance()->open(er);
if (!db)
{
MsgBox::ShowMsgBox(cn("失败"), cn("数据库错误\n") + er, cn("确定"));
return;
}
QString sql = "SELECT * FROM "+ MatchData().objectName() +
" WHERE uid = '" + uid + "'";
int rlt;
QList<QObject *> objs = db->executeQuery(sql,
MatchData().metaObject(),
rlt, er);
if (rlt != 0)
{
MsgBox::ShowMsgBox(cn("失败"), cn("数据库读取错误\n") + er, cn("确定"));
return;
}
bool b = true;
if (objs.isEmpty())
{
// insert
MatchData md;
md.setUid(uid);
md.setEditname(name);
md.setNickname(jsondata->getNickname());
md.setEdittime(QDateTime::currentDateTime().toTime_t());
md.setIp(jsondata->getGsoapip());
md.setModifycounts(1);
b = db->insert(&md, er);
}
else
{
// update
MatchData *md = qobject_cast<MatchData *>(objs.first());
if (md)
{
md->setEditname(name);
md->setNickname(jsondata->getNickname());
md->setEdittime(QDateTime::currentDateTime().toTime_t());
md->setIp(jsondata->getGsoapip());
md->setModifycounts(md->getModifycounts() + 1);
b = db->update(md, "uid", er);
}
else
{
b = false;
er = cn("无法修改,读取错误!!!");
}
auto it = objs.begin();
while (it != objs.end())
{
QObject *obj = *it;
delete obj;
obj = nullptr;
++it;
}
}
db->close();
if (!b)
{
MsgBox::ShowMsgBox(cn("修改失败"), er, cn("确定"));
}
else
{
memoname = name;
}
showMemoName();
});
}