1.1 --- a/ImprovedTableParser.py Sun Feb 19 21:07:13 2012 +0100
1.2 +++ b/ImprovedTableParser.py Sun Feb 19 21:42:32 2012 +0100
1.3 @@ -328,9 +328,15 @@
1.4
1.5 def to_number(s, request):
1.6
1.7 - "Convert 's' to a number, discarding any non-numeric trailing data."
1.8 + """
1.9 + Convert 's' to a number, discarding any non-numeric trailing data.
1.10 + Return an empty string if 's' is empty.
1.11 + """
1.12
1.13 - return int(get_number(s))
1.14 + if s:
1.15 + return int(get_number(s))
1.16 + else:
1.17 + return s
1.18
1.19 def to_plain_text(s, request):
1.20
1.21 @@ -370,9 +376,17 @@
1.22 # Ignore a column when a conversion is not possible.
1.23
1.24 try:
1.25 - text1 = fn(text1, self.request)
1.26 - text2 = fn(text2, self.request)
1.27 - result = cmp(text1, text2)
1.28 + value1 = fn(text1, self.request)
1.29 + value2 = fn(text2, self.request)
1.30 +
1.31 + # Avoid empty strings appearing earlier than other values.
1.32 +
1.33 + if value1 == "" and value2 != "":
1.34 + result = 1
1.35 + elif value1 != "" and value2 == "":
1.36 + result = -1
1.37 + else:
1.38 + result = cmp(value1, value2)
1.39
1.40 # Where the columns differ, return a result observing the sense
1.41 # (ascending or descending) of the comparison for the column.