Changeset View
Changeset View
Standalone View
Standalone View
src/services/ktraderparsetree.cpp
Show First 20 Lines • Show All 417 Lines • ▼ Show 20 Line(s) | 417 | if (c1.type != ParseContext::T_STRING || c2.type != ParseContext::T_STRING) { | |||
---|---|---|---|---|---|
418 | return false; | 418 | return false; | ||
419 | } | 419 | } | ||
420 | 420 | | |||
421 | _context->b = c2.str.contains(c1.str, m_cs); | 421 | _context->b = c2.str.contains(c1.str, m_cs); | ||
422 | 422 | | |||
423 | return true; | 423 | return true; | ||
424 | } | 424 | } | ||
425 | 425 | | |||
426 | bool ParseTreeSubsequenceMATCH::eval(ParseContext *_context) const | ||||
427 | { | ||||
428 | _context->type = ParseContext::T_BOOL; | ||||
429 | | ||||
430 | ParseContext c1(_context); | ||||
431 | ParseContext c2(_context); | ||||
432 | if (!m_pLeft->eval(&c1)) { | ||||
433 | return false; | ||||
434 | } | ||||
435 | if (!m_pRight->eval(&c2)) { | ||||
436 | return false; | ||||
437 | } | ||||
438 | if (c1.type != ParseContext::T_STRING || c2.type != ParseContext::T_STRING) { | ||||
439 | return false; | ||||
440 | } | ||||
441 | _context->b = ParseTreeSubsequenceMATCH::isSubseq(c1.str, c2.str, m_cs); | ||||
442 | return true; | ||||
443 | } | ||||
dfaure: Nothing is being modified, so this should use constBegin(), constEnd(), and const_iterator. | |||||
444 | | ||||
This code (the actual algorithm) should be extracted into a function, and a unittest should be written for it (to make sure all corner cases are correctly handled). Good opportunity to document the kind of matching being done, too, as you had to explain to me in this review request. And then once this commit is in, it should be documented on https://techbase.kde.org/Development/Tutorials/Services/Traders, please remember to do so. dfaure: This code (the actual algorithm) should be extracted into a function, and a unittest should be… | |||||
445 | bool ParseTreeSubsequenceMATCH:: | ||||
446 | isSubseq(const QString& pattern, const QString& text, Qt::CaseSensitivity cs) | ||||
447 | { | ||||
448 | if (pattern.isEmpty()) { | ||||
449 | return false; | ||||
450 | } | ||||
451 | bool chk_case = cs == Qt::CaseSensitive; | ||||
452 | | ||||
453 | QString::const_iterator i = text.constBegin(), j = pattern.constBegin(); | ||||
454 | for (; i != text.constEnd() && j != pattern.constEnd(); ++i) { | ||||
455 | if ((chk_case && *i == *j) || (!chk_case && i->toLower() == j->toLower())) { | ||||
456 | ++j; | ||||
457 | } | ||||
458 | } | ||||
459 | return j == pattern.constEnd(); | ||||
460 | } | ||||
461 | | ||||
426 | bool ParseTreeIN::eval(ParseContext *_context) const | 462 | bool ParseTreeIN::eval(ParseContext *_context) const | ||
427 | { | 463 | { | ||
428 | _context->type = ParseContext::T_BOOL; | 464 | _context->type = ParseContext::T_BOOL; | ||
429 | 465 | | |||
430 | ParseContext c1(_context); | 466 | ParseContext c1(_context); | ||
431 | ParseContext c2(_context); | 467 | ParseContext c2(_context); | ||
432 | if (!m_pLeft->eval(&c1)) { | 468 | if (!m_pLeft->eval(&c1)) { | ||
433 | return false; | 469 | return false; | ||
▲ Show 20 Lines • Show All 339 Lines • Show Last 20 Lines |
Nothing is being modified, so this should use constBegin(), constEnd(), and const_iterator.