From 71139e3522229db128057a3050b4969d8fec9035 Mon Sep 17 00:00:00 2001 From: Peter Landgren Date: Sat, 21 Mar 2009 08:10:09 +0000 Subject: [PATCH] Final fix of issue 2843 for any number of references. svn: r12370 --- src/ReportBase/_Bibliography.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/ReportBase/_Bibliography.py b/src/ReportBase/_Bibliography.py index 0af8b882e..8c7fc6e6a 100644 --- a/src/ReportBase/_Bibliography.py +++ b/src/ReportBase/_Bibliography.py @@ -23,7 +23,7 @@ Contain and organize bibliographic information. """ import string - +import math from gen.lib import SourceRef as SourceRef class Citation: @@ -74,17 +74,28 @@ class Citation: @return: The key of the added reference among all the references. @rtype: char """ - first_letter = '' - second_letter = '' letter_count = len(string.lowercase) ref_count = len(self.__ref_list) - if ref_count > letter_count: - # If there are more than 26 references, we need to use two - # characters to uniquely identify them all. - first_letter = string.lowercase[ ref_count / letter_count ] - second_letter = string.lowercase[ ref_count % letter_count ] - - key = first_letter + second_letter + x_ref_count = ref_count + # Return "a" for ref_count = 0, otherwise log(0) does not work + if ref_count == 0: + self.__ref_list.append(("a", source_ref)) + return "a" + last_letter = string.lowercase[ ref_count % letter_count ] + key = "" + # Calculate prek number of digits. + number_of_letters = int(math.log(float(ref_count),float(letter_count)))+1 + # Exclude index for number_of_letters-1 + for n in range(1, number_of_letters-1): + ref_count = ref_count - pow(letter_count, n) + # Adjust number_of_letters for new index + number_of_letters = int(math.log(float(ref_count),float(letter_count))) +1 + for n in range(1, number_of_letters): + x_ref_count = x_ref_count - pow(letter_count, n) + for letter in range(1, number_of_letters): + index = x_ref_count / pow(letter_count, letter) % letter_count + key += string.lowercase[ index ] + key = key + last_letter self.__ref_list.append((key, source_ref)) return key @@ -228,4 +239,4 @@ class Bibliography: if notehandle not in nl2: return False # Can't find anything different. They must be equal. - return True \ No newline at end of file + return True