| 11843 | |
| 11844 | |
| 11845 | ResultType RegExMatchObject::Invoke(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount) |
| 11846 | { |
| 11847 | switch (aID) |
| 11848 | { |
| 11849 | case M_Count: _o_return(mPatternCount - 1); |
| 11850 | case M_Mark: _o_return(mMark ? mMark : _T("")); |
| 11851 | case M___Enum: _o_return(new IndexEnumerator(this, ParamIndexToOptionalInt(0, 1) |
| 11852 | , static_cast<IndexEnumerator::Callback>(&RegExMatchObject::GetEnumItem))); |
| 11853 | } |
| 11854 | |
| 11855 | int p; |
| 11856 | if (ParamIndexIsOmitted(0)) |
| 11857 | p = 0; |
| 11858 | else if (ParamIndexIsNumeric(0)) |
| 11859 | p = ParamIndexToInt(0); |
| 11860 | else if (!mPatternName) // There are no named subpatterns, so param 0 is invalid. |
| 11861 | p = -1; |
| 11862 | else |
| 11863 | { |
| 11864 | auto name = ParamIndexToString(0); |
| 11865 | for (p = 0; p < mPatternCount; ++p) |
| 11866 | if (mPatternName[p] && !_tcsicmp(mPatternName[p], name)) |
| 11867 | { |
| 11868 | if (mOffset[2*p] < 0) |
| 11869 | // This pattern wasn't matched, so check for one with a duplicate name. |
| 11870 | for (int i = p + 1; i < mPatternCount; ++i) |
| 11871 | if (mPatternName[i] && !_tcsicmp(mPatternName[i], name) // It has the same name. |
| 11872 | && mOffset[2*i] >= 0) // It matched something. |
| 11873 | { |
| 11874 | // Prefer this pattern. |
| 11875 | p = i; |
| 11876 | break; |
| 11877 | } |
| 11878 | break; |
| 11879 | } |
| 11880 | } |
| 11881 | if (p < 0 || p >= mPatternCount) |
| 11882 | _o_throw_param(0); // p != 0 implies the parameter was not omitted. |
| 11883 | |
| 11884 | switch (aID) |
| 11885 | { |
| 11886 | case M___Get: |
| 11887 | if (auto arr = dynamic_cast<Array*>(ParamIndexToObject(1))) |
| 11888 | if (arr->Length()) |
| 11889 | _o_throw(ERR_INVALID_USAGE); |
| 11890 | // Otherwise, fall through: |
| 11891 | // Gives the correct result even if there was no match (because length is 0): |
| 11892 | case M_Value: _o_return(mHaystack - mHaystackStart + mOffset[p*2], mOffset[p*2+1]); |
| 11893 | case M_Pos: _o_return(mOffset[2*p] + 1); |
| 11894 | case M_Len: _o_return(mOffset[2*p + 1]); |
| 11895 | case M_Name: _o_return((mPatternName && mPatternName[p]) ? mPatternName[p] : _T("")); |
| 11896 | } |
| 11897 | return INVOKE_NOT_HANDLED; |
| 11898 | } |
| 11899 | |
| 11900 | |
| 11901 | void *pcret_resolve_user_callout(LPCTSTR aCalloutParam, int aCalloutParamLength) |
no test coverage detected