note
	description: "Formatter for integral numbers"
	library: "Free implementation of ELKS library"
	status: "See notice at end of class."
	legal: "See notice at end of class."
	names: format_integer
	date: "$Date: 2013-03-20 23:43:02 +0000 (Wed, 20 Mar 2013) $"
	revision: "$Revision: 92323 $"

class interface
	FORMAT_INTEGER

create 
	make

feature -- Initialization

	make (w: INTEGER_32)
		require
			reasonable_field: w >= 1
		ensure
			blank_fill: fill_character = ' '
			show_sign_negative: show_sign_negative
			no_separator: no_separator
			width_set: width = w
			right_justified: right_justified
			leading_sign: leading_sign
	
feature -- Access

	fill_character: CHARACTER_8
			-- Padding character.

	width: INTEGER_32
			-- Width of the field.

	separator: CHARACTER_8
			-- Separator between 1000's of numbers.

	justification: INTEGER_32
			-- Where in the field the format goes.

	trailing_sign: BOOLEAN
			-- Is the sign at the end?

	sign_format: INTEGER_32
			-- How the sign is formatted.

	sign_string: STRING_8
			-- Formatting details for the sign.

	bracketted_negative: BOOLEAN
			-- Enclose negative numbers in brackets?
	
feature -- Status report

	centered: BOOLEAN
			-- Are numbers to be formatted centered?
		ensure
				Result = (justification = Center_justification)

	left_justified: BOOLEAN
			-- Are numbers to be formatted with spaces on the right?
		ensure
				Result = (justification = Left_justification)

	right_justified: BOOLEAN
			-- Are numbers to be formatted with spaces on the left?
		ensure
				Result = (justification = Right_justification)

	not_justified: BOOLEAN
			-- Are numbers to be formatted in smallest string possible
		ensure
				Result = (justification = No_justification)

	show_sign_negative: BOOLEAN
			-- Are numbers to show sign only when negative?
		ensure
				Result = (sign_format = Sign_negative_value)

	show_sign_positive: BOOLEAN
			-- Are numbers to show sign only when positive?
		ensure
				Result = (sign_format = Sign_positive_value)

	show_sign: BOOLEAN
			-- Are numbers to show sign whether positive or negative?
		ensure
				Result = (sign_format = Show_sign_value)

	ignore_sign: BOOLEAN
			-- Ignore the sign of a number?
		ensure
				Result = (sign_format = Ignore_sign_value)

	no_separator: BOOLEAN
			-- Is there a separator?
		ensure
				Result = (separator = '%U')

	leading_sign: BOOLEAN
			-- Is the sign leading?
		ensure
				Result = not trailing_sign
	
feature -- Status setting

	blank_fill
			-- Fill numbers with blanks.
		ensure
				fill_character = ' '

	zero_fill
			-- Fill numbers with zeros.
		ensure
				fill_character = '0'

	dollar_fill
			-- Fill numbers with dollars.
		ensure
				fill_character = '$'

	asterisk_fill
			-- Fill numbers with asterisks.
		ensure
				fill_character = '*'

	set_fill (c: CHARACTER_8)
			-- Fill numbers with c
		ensure
				fill_character = c

	set_width (w: INTEGER_32)
			-- Set width to w
		require
			wide_enough: w >= 1
		ensure
				width = w

	underscore_separate
			-- Set separator to underscore.
		ensure
				separator = '_'

	comma_separate
			-- Set separator to comma.
		ensure
				separator = ','

	dot_separate
			-- Set separator to period.
		ensure
				separator = '.'

	remove_separator
			-- Remove the separator.
		ensure
				separator = '%U'

	set_separator (c: CHARACTER_8)
			-- Set the separator to c
		ensure
				separator = c

	left_justify
			--Put padding on right
		ensure
				left_justified

	center_justify
			-- Put padding on right and left
		ensure
				centered

	right_justify
			-- Put padding on left
		ensure
				right_justified

	no_justify
			-- Always return the smallest string possible
		ensure
				not_justified

	sign_leading
			-- Set the sign to lead
		ensure
				leading_sign

	sign_trailing
			-- Set the sign to trail
		ensure
				trailing_sign

	sign_positive_only
			-- Show sign for positive numbers only.
		ensure
				show_sign_positive

	sign_negative_only
			-- Show sign for negative numbers only.
		ensure
				show_sign_negative

	sign_show
			-- Show sign for all numbers.
		ensure
				show_sign

	sign_ignore
			-- Do not show sign.
		ensure
				ignore_sign

	sign_normal
			-- Set sign for - and +.
		ensure
				sign_string ~ "- +"

	sign_cr_dr
			-- Set sign for CR/DR
		ensure
				sign_string ~ "CR  DR"

	sign_dr_cr
			-- Set sign for DR/CR
		ensure
				sign_string ~ "DR  CR"

	sign_floating_dollar
			-- Set sign for floating dollar.
		ensure
				sign_string ~ "$$$"

	sign_floating_dollar_signed
			-- Set sign for floating dollar include sign.
		ensure
				sign_string ~ "-$ $+$"

	set_sign (s: STRING_8)
			-- Set sign values for positive, zero, negative
			-- All values must be the same length.
			-- Stored as negative, zero, positive.
		require
				s /= Void
				s.count >= 3
				s.count \\ 3 = 0
		ensure
			sign_set: sign_string ~ s

	bracket_negative
			-- Bracket negative numbers.
		ensure
				bracketted_negative

	unbracket_negative
			-- Do not bracket negative numbers.
		ensure
				not bracketted_negative
	
feature -- Conversion

	formatted (i: INTEGER_32): STRING_8
			-- Format the integer.
		ensure
			exists: Result /= Void
			correct_length: not_justified or Result.count >= width
	
invariant
	sign_string_attached: sign_string /= Void
	sign_string_count: sign_string.count >= 3
	sign_string_equal_parts: sign_string.count \\ 3 = 0
	wide_enough: width >= 1
		No_justification <= justification and justification <= Right_justification

note
	copyright: "Copyright (c) 1984-2012, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class FORMAT_INTEGER

Generated by ISE EiffelStudio