Final fix of issue 2843 for any number of references.
svn: r12370
This commit is contained in:
parent
cab9de8d62
commit
71139e3522
@ -23,7 +23,7 @@
|
|||||||
Contain and organize bibliographic information.
|
Contain and organize bibliographic information.
|
||||||
"""
|
"""
|
||||||
import string
|
import string
|
||||||
|
import math
|
||||||
from gen.lib import SourceRef as SourceRef
|
from gen.lib import SourceRef as SourceRef
|
||||||
|
|
||||||
class Citation:
|
class Citation:
|
||||||
@ -74,17 +74,28 @@ class Citation:
|
|||||||
@return: The key of the added reference among all the references.
|
@return: The key of the added reference among all the references.
|
||||||
@rtype: char
|
@rtype: char
|
||||||
"""
|
"""
|
||||||
first_letter = ''
|
|
||||||
second_letter = ''
|
|
||||||
letter_count = len(string.lowercase)
|
letter_count = len(string.lowercase)
|
||||||
ref_count = len(self.__ref_list)
|
ref_count = len(self.__ref_list)
|
||||||
if ref_count > letter_count:
|
x_ref_count = ref_count
|
||||||
# If there are more than 26 references, we need to use two
|
# Return "a" for ref_count = 0, otherwise log(0) does not work
|
||||||
# characters to uniquely identify them all.
|
if ref_count == 0:
|
||||||
first_letter = string.lowercase[ ref_count / letter_count ]
|
self.__ref_list.append(("a", source_ref))
|
||||||
second_letter = string.lowercase[ ref_count % letter_count ]
|
return "a"
|
||||||
|
last_letter = string.lowercase[ ref_count % letter_count ]
|
||||||
key = first_letter + second_letter
|
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))
|
self.__ref_list.append((key, source_ref))
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user