Example #1
0
def countunbalanced():
    import xmllexer
    import xmlfixup

    unbalancedcg = 0
    brokenmarkup = 0
    for cg in clones.clonegroups:
        bmp = False
        (ifn, ib, ie) = cg.instances[0]
        ifl = clones.inputfiles[ifn]
        il = ie - ib + 1
        covint, bf, bl = xmllexer.find_covered_intervals(
            ib, il, ifl.lexintervals)

        if bf and covint[0].int_type != xmllexer.IntervalType.general \
                or bl and covint[-1].int_type != xmllexer.IntervalType.general:
            brokenmarkup += 1
            bmp = True

        if not bmp:
            pb, ab, pr, ar = xmlfixup.balance_unbalanced_text(covint)
            if len(pb) != 0 or len(ab) != 0:
                unbalancedcg += 1

    return brokenmarkup, unbalancedcg
Example #2
0
def shrink_broken_markup_interval(offset, length, all_intervals):
    covered, broken_1st, broken_last = xmllexer.find_covered_intervals(offset, length, all_intervals)
    end = offset + length

    if broken_1st:
        if covered[0].int_type != xmllexer.IntervalType.general:
            # general text can be broken
            if len(covered) < 2:
                return None
            else:
                offset = covered[1].offs
    if broken_last:
        if covered[-1].int_type != xmllexer.IntervalType.general:
            # general text can be broken
            if len(covered) < 2:
                return None
            else:
                end = covered[-2].end
    rlen = end - offset
    if rlen <= 0:
        return None
    return offset, rlen
Example #3
0
def shrink_broken_markup_interval(offset, length, all_intervals):
    covered, broken_1st, broken_last = xmllexer.find_covered_intervals(
        offset, length, all_intervals)
    end = offset + length

    if broken_1st:
        if covered[0].int_type != xmllexer.IntervalType.general:
            # general text can be broken
            if len(covered) < 2:
                return None
            else:
                offset = covered[1].offs
    if broken_last:
        if covered[-1].int_type != xmllexer.IntervalType.general:
            # general text can be broken
            if len(covered) < 2:
                return None
            else:
                end = covered[-2].end
    rlen = end - offset
    if rlen <= 0:
        return None
    return offset, rlen
Example #4
0
def countunbalanced():
    import xmllexer
    import xmlfixup

    unbalancedcg = 0
    brokenmarkup = 0
    for cg in clones.clonegroups:
        bmp = False
        (ifn, ib, ie) = cg.instances[0]
        ifl = clones.inputfiles[ifn]
        il = ie - ib + 1
        covint, bf, bl = xmllexer.find_covered_intervals(ib, il, ifl.lexintervals)

        if bf and covint[0].int_type != xmllexer.IntervalType.general \
                or bl and covint[-1].int_type != xmllexer.IntervalType.general:
            brokenmarkup += 1
            bmp = True

        if not bmp:
            pb, ab, pr, ar = xmlfixup.balance_unbalanced_text(covint)
            if len(pb) != 0 or len(ab) != 0:
                unbalancedcg += 1

    return brokenmarkup, unbalancedcg