Given a path, returns the part to push to the stack. @param p_Path Path to locate part of. @return Part of p_Path to push to the stack.
| 565 | // @return Part of p_Path to push to the stack. |
| 566 | // |
| 567 | std::wstring PushToStackPipelineElement::PartToPush(const std::wstring& p_Path) const |
| 568 | { |
| 569 | std::wstring part; |
| 570 | |
| 571 | switch (m_Method) { |
| 572 | case PushToStackMethod::Entire: { |
| 573 | // Push the entire path. |
| 574 | part = p_Path; |
| 575 | break; |
| 576 | } |
| 577 | case PushToStackMethod::Range: { |
| 578 | // Push a range in the path. |
| 579 | if (m_Begin < p_Path.size() && m_Begin < m_End) { |
| 580 | part = p_Path.substr(m_Begin, m_End - m_Begin); |
| 581 | } |
| 582 | break; |
| 583 | } |
| 584 | case PushToStackMethod::Regex: { |
| 585 | // Push the first match for a regex. |
| 586 | try { |
| 587 | if (!m_Regex.empty()) { |
| 588 | #pragma warning(suppress: 26812) // std::regex_constants::syntax_option_type could be enum class |
| 589 | std::regex_constants::syntax_option_type reOptions = std::regex_constants::ECMAScript; |
| 590 | if (m_IgnoreCase) { |
| 591 | reOptions |= std::regex_constants::icase; |
| 592 | } |
| 593 | std::wregex regex(m_Regex, reOptions); |
| 594 | |
| 595 | std::wsmatch match; |
| 596 | if (std::regex_search(p_Path, match, regex)) { |
| 597 | part = match[m_Group]; |
| 598 | } |
| 599 | } |
| 600 | } catch (const std::regex_error&) { |
| 601 | } |
| 602 | break; |
| 603 | } |
| 604 | case PushToStackMethod::Fixed: { |
| 605 | part = m_FixedString; |
| 606 | break; |
| 607 | } |
| 608 | default: |
| 609 | assert(false); |
| 610 | } |
| 611 | |
| 612 | return part; |
| 613 | } |
| 614 | |
| 615 | // |
| 616 | // Constructor with pop location and no other information. |