'Get a unique reference if there are duplicates.'

def unique_ref(self, reference, found=False):

    if (not found):
        return reference
    original_ref = reference
    while (reference in self.used_refs):
        (ref, rest) = reference.split(self.get_separator(), 1)
        m = RE_REF_ID.match(ref)
        if m:
            reference = (u'%s%d%s%s' % (m.group(1), (int(m.group(2)) + 1), self.get_separator(), rest))
        else:
            reference = (u'%s%d%s%s' % (ref, 2, self.get_separator(), rest))
    self.used_refs.add(reference)
    if (original_ref in self.found_refs):
        self.found_refs[original_ref] += 1
    else:
        self.found_refs[original_ref] = 1
    return reference
