Ignore:
Timestamp:
Jun 20, 2015, 3:52:41 PM (4 years ago)
Author:
nmedfort
Message:

Temporary check-in

Location:
icGREP/icgrep-devel/icgrep/re
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_cc.cpp

    r4519 r4611  
    146146    return cci;
    147147}
     148
     149/** ------------------------------------------------------------------------------------------------------------- *
     150 * @brief rangeIntersect
     151 * @param cc
     152 * @param lo
     153 * @param hi
     154 ** ------------------------------------------------------------------------------------------------------------- */
     155CC * rangeIntersect(const CC * cc, const CodePointType lo, const CodePointType hi) {
     156    assert ("cc cannot be null" && cc);
     157    CC * intersect = makeCC();
     158    for (const auto & p : *cc) {
     159        if ((p.lo_codepoint <= hi) && (p.hi_codepoint >= lo)) {
     160            intersect->insert_range(std::max(lo, p.lo_codepoint), std::min(hi, p.hi_codepoint));
     161        }
     162    }
     163    return intersect;
     164}
     165
     166/** ------------------------------------------------------------------------------------------------------------- *
     167 * @brief rangeGaps
     168 * @param cc
     169 * @param lo
     170 * @param hi
     171 ** ------------------------------------------------------------------------------------------------------------- */
     172CC * rangeGaps(const CC * cc, const CodePointType lo, const CodePointType hi) {
     173    assert ("cc cannot be null" && cc);
     174    CC * gaps = makeCC();
     175    CodePointType cp = lo;
     176    if (cp < hi) {
     177        auto i = cc->cbegin(), end = cc->cend();
     178        for (; i != end && cp < hi; ++i) {
     179            if (i->hi_codepoint < cp) {
     180                continue;
     181            }
     182            else if (i->lo_codepoint > cp) {
     183                gaps->insert_range(cp, i->lo_codepoint - 1);
     184            }
     185            cp = i->hi_codepoint + 1;
     186        }
     187        if (cp < hi) {
     188            gaps->insert_range(cp, hi);
     189        }
     190    }
     191    return gaps;
     192}
     193
     194/** ------------------------------------------------------------------------------------------------------------- *
     195 * @brief outerRanges
     196 * @param cc
     197 ** ------------------------------------------------------------------------------------------------------------- */
     198CC * outerRanges(const CC * cc) {
     199    assert ("cc cannot be null" && cc);
     200    CC * ranges = makeCC();
     201    auto i = cc->cbegin();
     202    const auto end = cc->cend();
     203    for (auto j = i; ++j != end; ) {
     204        if (j->hi_codepoint > i->hi_codepoint) {
     205            ranges->insert_range(i->lo_codepoint, i->hi_codepoint);
     206            i = j;
     207        }
     208    }
     209    return ranges;
     210}
     211
     212/** ------------------------------------------------------------------------------------------------------------- *
     213 * @brief innerRanges
     214 * @param cc
     215 ** ------------------------------------------------------------------------------------------------------------- */
     216CC * innerRanges(const CC * cc) {
     217    assert ("cc cannot be null" && cc);
     218    CC * ranges = makeCC();
     219    auto i = cc->cbegin();
     220    const auto end = cc->cend();
     221    for (auto j = i; ++j != end; ) {
     222        if (j->hi_codepoint <= i->hi_codepoint) {
     223            ranges->insert_range(j->lo_codepoint, j->hi_codepoint);
     224        }
     225        else {
     226            i = j;
     227        }
     228    }
     229    return ranges;
     230}
    148231   
    149232}
  • icGREP/icgrep-devel/icgrep/re/re_cc.h

    r4516 r4611  
    187187
    188188CC * caseInsensitize(const CC * cc);
     189
     190CC * rangeIntersect(const CC * cc, const CodePointType lo, const CodePointType hi);
     191
     192CC * rangeGaps(const CC * cc, const CodePointType lo, const CodePointType hi);
     193
     194CC * outerRanges(const CC * cc);
     195
     196CC * innerRanges(const CC * cc);
     197
    189198}
    190199
Note: See TracChangeset for help on using the changeset viewer.