Package gnue :: Package common :: Package utils :: Module TextUtils
[show private | hide private]

Module gnue.common.utils.TextUtils

Common text-related utilities
Function Summary
string comify(num, decimals, parenthesis)
Comify a number (e.g., print -9900 as -9,900.00)
string dollarToText(num)
Convert a number to "dollar" notation (suitable for use on checks) e.g., 123.24 --> "One Hundred Twenty Three and 24/100"
string intToRoman(num)
Convert an integer to a roman numeral.
string lineWrap(message, maxWidth, preserveNewlines, alignment, eol)
A simple linewrap function.
String stripHTML(htmlString)
Removes all html mark-up from a text string.
number textToMeasurement(text, multiplier)
Converts most standard measurements to inches.

Variable Summary
str __revision__ = '$Id'
int ALIGN_CENTER = 2                                                                     
int ALIGN_LEFT = 0                                                                     
int ALIGN_RIGHT = 1                                                                     

Function Details

comify(num, decimals=2, parenthesis=False)

Comify a number (e.g., print -9900 as -9,900.00)

Sample Usage:
>>> comify(-9999.934, 2)
'-9,999.93'

>>> comify(-9999.934, 2, 1)
'(9,999.93)'
Parameters:
num - The number to reformat
           (type=number)
decimals - The number of decimal places to retain
           (type=number)
parenthesis - If true then negative numbers will be returned inside parenthesis
           (type=boolean)
Returns:
A properly formatted number
           (type=string)

dollarToText(num)

Convert a number to "dollar" notation (suitable for use on checks) e.g., 123.24 --> "One Hundred Twenty Three and 24/100"

Sample Usage:
>>> dollarToText(1120.15)
'One Thousand One Hundred Twenty and 15/100'
Parameters:
num - The numeric amount
           (type=number)
Returns:
The full text equivalent of the number.
           (type=string)

intToRoman(num)

Convert an integer to a roman numeral.

Sample Usage:
>>> intToRoman(1999)
'MCMXCIX'
Parameters:
num - The number to convert
           (type=integer)
Returns:
The roman numeral equivalent.
           (type=string)

lineWrap(message, maxWidth, preserveNewlines=1, alignment=0, eol=1)

A simple linewrap function.
Parameters:
message - The string to wrap
maxWidth - The maximum string width allowed.
preserveNewlines - If true then newlines are left in the string otherwise they are removed.
alignment -

The alignment of the returned string based upon a width of maxWidth.

Possible values (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER)
eol - If true then the last character of the return value will be a newline
Returns:
The properly wrapped text string.
           (type=string)

stripHTML(htmlString)

Removes all html mark-up from a text string.
Parameters:
htmlString - The text containing the html mark up
           (type=String)
Returns:
The string minus any html markup
           (type=String)

textToMeasurement(text, multiplier=1)

Converts most standard measurements to inches.

Sample Usage:
>>> textToMeasurement('72pt')
1.0

>>> # convert to 72 point output
... textToMeasurement('1.27cm',72)
36.0
Parameters:
text - A string containing the measurement to convert The following measurements are accepted (pt, cm, mm, in)
           (type=string)
multiplier - A multiplier used to adjust the output to values other inches.
           (type=number)
Returns:
The converted value
           (type=number)

Variable Details

__revision__

Type:
str
Value:
'$Id'                                                                  

ALIGN_CENTER

Type:
int
Value:
2                                                                     

ALIGN_LEFT

Type:
int
Value:
0                                                                     

ALIGN_RIGHT

Type:
int
Value:
1                                                                     


GNUe Home

Public API

Developer's Corner