+
+
+def FormatOrdinal(value):
+ """Formats a number as an ordinal in the English language.
+
+ E.g. the number 1 becomes "1st", 22 becomes "22nd".
+
+ @type value: integer
+ @param value: Number
+ @rtype: string
+
+ """
+ tens = value % 10
+
+ if value > 10 and value < 20:
+ suffix = "th"
+ elif tens == 1:
+ suffix = "st"
+ elif tens == 2:
+ suffix = "nd"
+ elif tens == 3:
+ suffix = "rd"
+ else:
+ suffix = "th"
+
+ return "%s%s" % (value, suffix)
+
+
+def Truncate(text, length):
+ """Truncate string and add ellipsis if needed.
+
+ @type text: string
+ @param text: Text
+ @type length: integer
+ @param length: Desired length
+ @rtype: string
+ @return: Truncated text
+
+ """
+ assert length > len(_ASCII_ELLIPSIS)
+
+ # Serialize if necessary
+ if not isinstance(text, basestring):
+ text = str(text)
+
+ if len(text) <= length:
+ return text
+ else:
+ return text[:length - len(_ASCII_ELLIPSIS)] + _ASCII_ELLIPSIS