Arena  1.0
A content management system
 All Classes Files Functions Variables Pages
Library.String.Utilities.String Class Reference

A utility class for working with strings. More...

Public Member Functions

def escape
 Escape special characters within a string. More...
 
def quote
 Return the quoted form of the specified string, using the specified beginning and end markers. More...
 
def implode
 Implode the list or dictionary object using the specified delimiters. More...
 
def explode
 Expand the specified string into a list or dictionary object. More...
 
def formatPrescan
 Perform a first pass of a format string, collecting the names (or indices) of fields specified in the string. More...
 
def formatUsing
 Format a string using a helper function. More...
 
def handleFormatField
 The default behavior for formatting a string. More...
 
def format
 Format a string. More...
 
def isNumeric
 Determine whether the specified string consists of only numeric characters. More...
 
def hash
 Construct a hash value for the specified string. More...
 
def toInteger
 Attempt to convert the specified string to an integer value. More...
 
def toLong
 Attempt to convert the specified string to a long integer value. More...
 
def toFloat
 Attempt to convert the specified string to an floating-point value. More...
 
def fileSize
 Format the specified value as a human-readable file size. More...
 
def isEmpty
 Determine whether the specified string value is empty.
 

Static Public Member Functions

def obfuscate
 Obfuscate the specified string. More...
 

Detailed Description

A utility class for working with strings.

Member Function Documentation

def Library.String.Utilities.String.escape (   Self,
  thisString,
  specialCharacters 
)

Escape special characters within a string.

/p specialCharacters should be a dictionary object whose keys specify the character to match and whose values specify the replacement value for that character.

def Library.String.Utilities.String.explode (   Self,
  thisString,
  resultType = list,
  itemDelimiter = sDefaultItemsDelimiter,
  keyDelimiter = sDefaultKeyDelimiter 
)

Expand the specified string into a list or dictionary object.

The string is assumed to contain one or more items separated by the specified delimiters.

def Library.String.Utilities.String.fileSize (   Self,
  value,
  binary = False 
)

Format the specified value as a human-readable file size.

This code is borrowed from jinja2 code, and includes a modification that I had to make in order to get the jinja2 code to work with my file size values.

Format the value like a 'human-readable' file size (i.e. 13 kB,
4.1 MB, 102 Bytes, etc).  Per default decimal prefixes are used (Mega,
Giga, etc.), if the second parameter is set to `True` the binary
prefixes are used (Mebi, Gibi).
def Library.String.Utilities.String.format (   Self,
  s,
  posValues,
  kwValues 
)

Format a string.

This routine is necessary to provide Python 2.7 functionality in the event that Python 2.6 is being used, as is the case with my hosting provider.

def Library.String.Utilities.String.formatPrescan (   Self,
  fmt 
)

Perform a first pass of a format string, collecting the names (or indices) of fields specified in the string.

The field specifiers are assumed to conform to the type used by str.format(), and can be either keyword specifiers or positional specifiers (or a mix of both).

Returns
This routine returns a dictonary object with two keys, fields and sequence. /p fields is a list that contains the names or positions of fields specified within the format string. sequence specifies the non-field substrings and field placeholders, in the order in which they are declared within the format string.
def Library.String.Utilities.String.formatUsing (   Self,
  callback,
  fmt,
  posValues,
  kwValues 
)

Format a string using a helper function.

This routine is necessary because str.format() removes single-quote characters from string values as it processes them, and these characters are needed when specifying field names as part of an SQL query passed to a database server.

def Library.String.Utilities.String.handleFormatField (   Self,
  field,
  posValues,
  kwValues 
)

The default behavior for formatting a string.

def Library.String.Utilities.String.hash (   Self,
  thisString 
)

Construct a hash value for the specified string.

This method simply returns the value of the hash() function as applied to the specified string.

def Library.String.Utilities.String.implode (   Self,
  theseItems,
  itemsDelimiter = sDefaultItemsDelimiter,
  keyDelimiter = sDefaultKeyDelimiter 
)

Implode the list or dictionary object using the specified delimiters.

This routine returns a string that contains each item or key/value pair separated using the specified delimiters.

def Library.String.Utilities.String.isNumeric (   Self,
  thisString 
)

Determine whether the specified string consists of only numeric characters.

def Library.String.Utilities.String.obfuscate (   thisString,
  prefix = "&#",
  postfix = ";",
  odds = 0.25 
)
static

Obfuscate the specified string.

thisString is obfuscated by constructing a string that contains the ASCII character code for each character in the string. The character code is prefixed by prefix and has postfix appended to it.

The previous actions only occur if a random number generated by the Python random.random() function is greater than or equal to odds. Setting odds to a value of 1.0 will effectively prevent obfuscation (since random.random() only returns values between 0 and 1), while setting odds to a value of 0.0 will ensure that every character is obfuscated. Otherwise, a mix of obfuscated and regular characters from thisString is returned.

In its default state, this method is designed to obfuscate e-mail addresses and other text that might appear on a Web page.

def Library.String.Utilities.String.quote (   Self,
  thisString,
  beginMark = "'",
  endMark = None 
)

Return the quoted form of the specified string, using the specified beginning and end markers.

def Library.String.Utilities.String.toFloat (   Self,
  thisString,
  defaultValue = 0.0 
)

Attempt to convert the specified string to an floating-point value.

If the attempt fails, no exception is raised, and the routine returns the default value specified.

def Library.String.Utilities.String.toInteger (   Self,
  thisString,
  defaultValue = 0 
)

Attempt to convert the specified string to an integer value.

If the attempt fails, no exception is raised, and the routine returns the default value specified.

def Library.String.Utilities.String.toLong (   Self,
  thisString,
  defaultValue = 0 
)

Attempt to convert the specified string to a long integer value.

If the attempt fails, no exception is raised, and the routine returns the default value specified.


The documentation for this class was generated from the following file: