2

While reading the source code of TextMate, I come across a line of code that makes me confused:

match_t search (pattern_t const& ptrn, char const* first, char const* last, char const* from, char const* to, OnigOptionType options)
{
    if(ptrn)
    {
        struct helper_t { static void region_free (OnigRegion* r) { onig_region_free(r, 1); } };
        regexp::region_ptr region(onig_region_new(), &helper_t::region_free);
        if(ONIG_MISMATCH != onig_search(ptrn.get().get(), first, last, from ?: first, to ?: last, region.get(), options))
            return match_t(region, ptrn.get(), first);
    }
    return match_t();
}

What is the ?: operator means? Is "from ?: first" equivalent to "from ? default(decltype(from)) : first"?

Because I'm using Windows and just reading the code, this is really a puzzle to me. And I believe this is C++ code, since it's a *.cc file. (Should not be Objective-C)

You can view the code here: https://github.com/textmate/textmate/blob/master/Frameworks/regexp/src/regexp.cc#L115

Xin
  • 1,300
  • 2
  • 14
  • 27

0 Answers0