def getCharOverlapCount(from1, to1, from2, to2):
    """Calculates the number of overlapping characters of the two given areas."""

    #order such that from1 is always prior from2
    if from1 > from2:
        tmp = from1
        from1 = from2
        from2 = tmp
        tmp = to1
        to1 = to2
        to2 = tmp

    if from2 >= from1 and from2 <= to1:
        if to2 > to1:
            return to1 - from2 + 1
        else:
            return to2 - from2 + 1
    else:
        return 0