Debian Codegraph @

source_2012/infosys.mss

raw
1 @comment{ $Source: e:\\cvsroot/ARM/Source/infosys.mss,v $ }
2 @comment{ $Revision: 1.44 $ $Date: 2012/11/28 23:53:05 $ $Author: randy $ }
3 @Part(infosys, Root="ada.mss")
4
5 @Comment{$Date: 2012/11/28 23:53:05 $}
6 @LabeledNormativeAnnex{Information Systems}
7
8 @begin{Intro}
9 @Defn{information systems}
10 @Leading@;This Annex provides a set of facilities relevant to
11 Information Systems programming. These fall into several
12 categories:
13 @begin{itemize}
14 an attribute definition clause specifying Machine_Radix for a decimal subtype;
15
16 the package Decimal, which declares a set of constants defining the
17 implementation's capacity for decimal types, and a
18 generic procedure
19 for decimal division; and
20
21 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
22 the child packages Text_IO.Editing@Chg{Version=[2],New=[,],Old=[ and]}
23 Wide_Text_IO.Editing@Chg{Version=[2],New=[, and Wide_Wide_Text_IO.Editing],Old=[]},
24 which
25 support formatted and localized output of decimal data, based on
26 @lquotes@;picture String@rquotes@; values.
27 @end{itemize}
28
29 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
30 See also: @RefSec{Fixed Point Types}; @RefSec{Operations of Fixed Point Types};
31 @RefSec{Type Conversions};
32 @RefSec{Operational and Representation Attributes};
33 @RefSec(Input-Output for Real Types);@Chg{Version=[2],
34 New=[],Old=[@RefSec{Interfacing with COBOL};]}
35 @RefSec{Interfacing with C and C++};@Chg{Version=[2],
36 New=[ @RefSec{Interfacing with COBOL};],Old=[]}
37 @RefSec{Numerics}.
38
39 The character and string handling packages in
40 @RefSec{Predefined Language Environment}
41 are also relevant for Information Systems.
42 @end{Intro}
43
44 @begin{ImplAdvice}
45 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
46 If COBOL (respectively, C) is widely supported in the target environment,
47 implementations supporting the Information Systems
48 Annex should provide the child package
49 Interfaces.COBOL (respectively, Interfaces.C) specified in
50 @RefSecNum{Interface to Other Languages}
51 and should support a @i{convention_}@nt{identifier} of
52 COBOL (respectively, C) @Chg{Version=[3],New=[for],Old=[in]} the
53 @Chg{Version=[3],New=[Convention aspect],Old=[interfacing pragmas]}
54 (see @RefSecNum{Interface to Other Languages}),
55 thus allowing Ada programs to interface with programs written in
56 that language.
57 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
58 Text=[If COBOL (respectively, C) is supported in the target environment,
59 then interfacing to COBOL (respectively, C) should be supported as
60 specified in @RefSecNum{Interface to Other Languages}.]}]}
61 @end{ImplAdvice}
62
63 @begin{Extend83}
64 @Defn{extensions to Ada 83}
65 This Annex is new to Ada 95.
66 @end{Extend83}
67
68 @begin{DiffWord95}
69 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
70 @ChgAdded{Version=[2],Text=[Added a mention of Wide_Wide_Text_IO.Editing,
71 part of the support for 32-bit characters.]}
72 @end{DiffWord95}
73
74 @LabeledClause{Machine_Radix Attribute Definition Clause}
75
76 @begin{StaticSem}
77 @PDefn2{Term=[specifiable], Sec=(of Machine_Radix for decimal first subtypes)}
78 @Defn{Machine_Radix clause}
79 Machine_Radix may be specified for a decimal first subtype
80 (see @RefSecNum{Fixed Point Types})
81 via an @nt{attribute_definition_clause};
82 the expression of such a clause shall be static,
83 and its value shall be 2 or 10.
84 A value of 2 implies a binary base range; a
85 value of 10 implies a decimal base range.@Chg{Version=[3],New=[@AspectDefn{Machine_Radix}],Old=[]}
86 @begin{Ramification}
87 In the absence of a Machine_Radix clause, the choice
88 of 2 versus 10 for S'Machine_Radix is not specified.
89 @end{Ramification}
90
91 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Machine_Radix],
92 Text=[@ChgAdded{Version=[3],Text=[Radix (2 or 10) that is used to
93 represent a decimal fixed point type.]}]}
94
95 @end{StaticSem}
96
97 @begin{ImplAdvice}
98 Packed decimal should be used as the internal representation
99 for objects of subtype S when S'Machine_Radix = 10.
100 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
101 Text=[Packed decimal should be used as the internal representation
102 for objects of subtype @i<S> when @i<S>'Machine_Radix = 10.]}]}
103 @end{ImplAdvice}
104
105 @begin{Discussion}
106
107 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
108 The intent of a decimal Machine_Radix attribute definition clause
109 is to allow the programmer to declare an Ada decimal data object
110 whose representation matches a particular COBOL implementation's
111 representation of packed decimal items.
112 The Ada object may then be passed to an interfaced COBOL program
113 that takes a packed decimal data item as a parameter,
114 assuming that convention COBOL has been specified for the Ada
115 object's type @Chg{Version=[3],New=[with an aspect],Old=[in a @nt[pragma]]}
116 Convention.
117
118 Additionally, the Ada compiler may choose to generate arithmetic
119 instructions that exploit the packed decimal representation.
120
121 @end{discussion}
122
123 @begin{Examples}
124 @Leading@Keepnext@i{Example of Machine_Radix attribute definition clause:}
125 @begin{example}
126 @key[type] Money @key[is] @key[delta] 0.01 @key[digits] 15;
127 @key[for] Money'Machine_Radix @key[use] 10;
128 @end{example}
129 @end{Examples}
130
131 @LabeledClause{The Package Decimal}
132
133 @begin{StaticSem}
134 @Leading@Keepnext@;The library package Decimal has the following declaration:
135 @begin{Example}
136 @key(package) Ada.Decimal @key(is)@ChildUnit{Parent=[Ada],Child=[Decimal]}
137 @key(pragma) Pure(Decimal);
138
139 @AdaObjDefn{Max_Scale} : @key(constant) := @RI{implementation-defined};
140 @AdaObjDefn{Min_Scale} : @key(constant) := @RI{implementation-defined};
141
142 @AdaObjDefn{Min_Delta} : @key(constant) := 10.0**(-Max_Scale);
143 @AdaObjDefn{Max_Delta} : @key(constant) := 10.0**(-Min_Scale);
144
145 @AdaObjDefn{Max_Decimal_Digits} : @key(constant) := @RI{implementation-defined};
146
147 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
148 @key(generic)
149 @key(type) Dividend_Type @key(is) @key(delta) <> @key(digits) <>;
150 @key(type) Divisor_Type @key(is) @key(delta) <> @key(digits) <>;
151 @key(type) Quotient_Type @key(is) @key(delta) <> @key(digits) <>;
152 @key(type) Remainder_Type @key(is) @key(delta) <> @key(digits) <>;
153 @key(procedure) @AdaSubDefn{Divide} (Dividend : @key(in) Dividend_Type;
154 Divisor : @key(in) Divisor_Type;
155 Quotient : @key(out) Quotient_Type;
156 Remainder : @key(out) Remainder_Type)@Chg{Version=[3],New=[
157 @key(with) Convention => Intrinsic],Old=[;
158 @key[pragma] Convention(Intrinsic, Divide)]};
159
160 @key(end) Ada.Decimal;
161 @end{Example}
162 @ImplDef{The values of named numbers in the package Decimal.}
163
164 Max_Scale is the largest N such that 10.0**(@en@;N) is allowed as a decimal
165 type's delta. Its type is @i{universal_integer}.
166
167 Min_Scale is the smallest N such that 10.0**(@en@;N) is allowed as a decimal
168 type's delta. Its type is @i{universal_integer}.
169
170 Min_Delta is the smallest value allowed for @i{delta} in a
171 @nt{decimal_fixed_point_definition}. Its type is @i{universal_real}.
172
173 Max_Delta is the largest value allowed for @i{delta} in a
174 @nt{decimal_fixed_point_definition}. Its type is @i{universal_real}.
175
176 Max_Decimal_Digits is the largest value allowed for @i{digits} in a
177 @nt{decimal_fixed_point_definition}. Its type is @i{universal_integer}.
178 @begin{reason}
179 The name is Max_Decimal_Digits versus Max_Digits, in order to avoid
180 confusion with the named number System.Max_Digits relevant to floating
181 point.
182 @end{reason}
183 @end{StaticSem}
184
185 @begin{StaticSem}
186 The effect of Divide is as follows.
187 The value of Quotient is Quotient_Type(Dividend/Divisor).
188 The value of Remainder is Remainder_Type(Intermediate),
189 where Intermediate is the difference between Dividend and the product of
190 Divisor and Quotient; this result is computed exactly.
191 @end{StaticSem}
192
193 @begin(ImplReq)
194 Decimal.Max_Decimal_Digits shall be at least 18.
195
196 Decimal.Max_Scale shall be at least 18.
197
198 Decimal.Min_Scale shall be at most 0.
199 @end{ImplReq}
200
201 @begin(Notes)
202 The effect of division yielding a quotient with control over rounding
203 versus truncation is obtained by applying either the
204 function attribute Quotient_Type'Round or the conversion Quotient_Type
205 to the expression Dividend/Divisor.
206 @end(Notes)
207
208
209 @LabeledClause{Edited Output for Decimal Types}
210 @begin{Intro}
211 @Leading@;
212 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
213 The child packages Text_IO.Editing@Chg{Version=[2],New=[,],Old=[ and]}
214 Wide_Text_IO.Editing@Chg{Version=[2],New=[, and Wide_Wide_Text_IO.Editing],Old=[]}
215 provide localizable formatted text
216 output, known as @i{edited output}@Defn{edited output},
217 for decimal types. An edited
218 output string is a function of a numeric value, program-specifiable
219 locale elements, and a format control value. The numeric value is of
220 some decimal type. The locale elements are:
221 @begin{itemize}
222 the currency string;
223
224 the digits group separator character;
225
226 the radix mark character; and
227
228 the fill character that replaces leading zeros of the numeric value.
229 @end{itemize}
230
231 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
232 For Text_IO.Editing the edited output and currency strings are of
233 type String, and the locale characters are of type Character.
234 For Wide_@!Text_IO.@!Editing their types are Wide_@!String and Wide_@!Character,
235 respectively.@Chg{Version=[2],New=[ For Wide_Wide_@!Text_IO.@!Editing
236 their types are Wide_Wide_@!String and Wide_Wide_@!Character, respectively.],Old=[]}
237
238 Each of the locale elements has a default value that can be replaced or
239 explicitly overridden.
240
241 A format-control
242 value is of the private type Picture; it determines
243 the composition of the edited output string and controls the form and
244 placement of the sign, the position of the locale elements and the
245 decimal digits, the presence or absence of a radix mark, suppression
246 of leading zeros, and insertion of particular character values.
247
248 @Leading@;A Picture object is composed from a String value, known as a
249 @i{picture String}, that serves as a template for the
250 edited output string, and a
251 Boolean value that controls whether a string of all space characters is
252 produced when the number's value is zero. A picture String comprises a
253 sequence of one- or two-Character symbols, each serving as a placeholder
254 for a character or string at a corresponding position in the edited
255 output string. The picture String symbols fall into several categories
256 based on their effect on the edited output string:
257 @TabClear()
258 @begin{Display}
259 @TabSet{3, 21, 27, 33, 39, 45, 51}
260 @\Decimal Digit: @\'9'
261 @\Radix Control: @\'.' @\'V'
262 @\Sign Control: @\'+' @\'@en@;' @\'<' @\'>' @\"CR" @\"DB"
263 @\Currency Control: @\'$' @\'#'
264 @\Zero Suppression: @\'Z' @\'*'
265 @\Simple Insertion: @\'_' @\'B' @\'0' @\'/'
266 @end{Display}
267
268 The entries are not case-sensitive. Mixed- or lower-case forms
269 for "CR" and "DB", and lower-case forms for 'V', 'Z', and 'B',
270 have the same effect as the upper-case symbols shown.
271
272 An occurrence of a '9' Character in the picture String represents a
273 decimal digit position in the edited output string.
274
275 A radix control Character in the picture String indicates the position
276 of the radix mark in the edited output string: an actual character
277 position for '.', or an assumed position for 'V'.
278
279 A sign control Character in the picture String affects the form of the
280 sign in the edited output string. The '<' and '>' Character values indicate
281 parentheses for negative values. A Character '+', '@en@;', or '<' appears
282 either singly, signifying a fixed-position sign in the edited output,
283 or repeated, signifying a floating-position sign that is preceded by
284 zero or more space characters and that replaces a leading 0.
285
286 A currency control Character in the picture String indicates an
287 occurrence of the currency string in the edited output string. The
288 '$' Character represents the complete currency string; the '#'
289 Character represents one character of the currency string. A '$'
290 Character appears either singly, indicating a fixed-position currency
291 string in the edited output, or repeated, indicating a
292 floating-position currency string that occurs in place of a leading 0.
293 A sequence of '#' Character values indicates either a fixed- or
294 floating-position currency string, depending on context.
295
296 A zero suppression Character in the picture String allows a leading
297 zero to be replaced by either the space character (for 'Z') or
298 the fill character (for '*').
299
300 A simple insertion Character in the picture String represents, in
301 general, either itself (if '/' or '0'), the space character (if 'B'),
302 or the digits group separator character (if '_'). In some contexts it
303 is treated as part of a floating sign, floating currency, or zero
304 suppression string.
305
306 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
307 An example of a picture String is "<###Z_ZZ9.99>". If the currency string
308 is "@Chg{Version=[2],New=[kr],Old=[FF]}", the separator character is ',', and
309 the radix mark is '.' then the edited output string values for the decimal
310 values 32.10 and @en@;5432.10 are
311 "bb@Chg{Version=[2],New=[kr],Old=[FF]}bbb32.10b" and
312 "(b@Chg{Version=[2],New=[kr],Old=[FF]}5,432.10)", respectively, where 'b'
313 indicates the space character.
314
315 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
316 The generic packages Text_IO.Decimal_IO@Chg{Version=[2],New=[,],Old=[ and]}
317 Wide_Text_IO.Decimal_IO@Chg{Version=[2],New=[, and Wide_Wide_Text_IO.Decimal_IO],Old=[]}
318 (see @RefSec(Input-Output for Real Types))
319 provide text input and nonedited text output for decimal types.
320 @end{Intro}
321
322 @begin{Notes}
323 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
324 A picture String is of type Standard.String, @Chg{Version=[2],New=[for all of],
325 Old=[both for]} Text_IO.Editing@Chg{Version=[2],New=[,],Old=[ and]}
326 Wide_Text_IO.Editing@Chg{Version=[2],New=[, and Wide_Wide_Text_IO.Editing],Old=[]}.
327 @end{Notes}
328
329 @begin{DiffWord95}
330 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
331 @ChgAdded{Version=[2],Text=[Added descriptions of Wide_Wide_Text_IO.Editing;
332 see @RefSecNum{The Package Wide_Wide_Text_IO.Editing}.]}
333 @end{DiffWord95}
334
335
336 @LabeledSubClause{Picture String Formation}
337 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
338 @begin{Intro}
339 @Defn2{term=[picture String],sec=[for edited output]}
340 @Defn2{term=[well-formed picture String],sec=[for edited output]}
341 A @i{well-formed picture String}, or simply @i{picture String},
342 is a String value that conforms to the
343 syntactic rules, composition constraints, and character replication
344 conventions specified in this @Chg{Version=[3],New=[subclause],Old=[clause]}.
345 @end{Intro}
346
347 @begin{RunTime}
348 @TabClear()
349 @ChgRef{Version=[1], Kind=[Deleted]}
350 @Chg[New=<>,Old=<@ @;@comment{Empty paragraph to hang junk paragraph number from original RM}>]
351 @begin{Display}
352 @ntf{picture_string} ::=
353 @ntf{fixed_$_picture_string}
354 | @ntf{fixed_#_picture_string}
355 | @ntf{floating_currency_picture_string}
356 | @ntf{non_currency_picture_string}
357 @comment{Blank Line}
358 @end{Display}
359 @begin{display}
360 @ntf{fixed_$_picture_string} ::=
361 [@ntf{fixed_LHS_sign}] @ntf{fixed_$_char} {@ntf{direct_insertion}} [@ntf{zero_suppression}]
362 @ntf{number} [@ntf{RHS_sign}]
363 @comment{Blank Line}
364 | [@ntf{fixed_LHS_sign} {@ntf{direct_insertion}}] [@ntf{zero_suppression}]
365 @ntf{number} @ntf{fixed_$_char} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
366 @comment{Blank Line}
367 | @ntf{floating_LHS_sign} @ntf{number} @ntf{fixed_$_char} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
368 @comment{Blank Line}
369 | [@ntf{fixed_LHS_sign}] @ntf{fixed_$_char} {@ntf{direct_insertion}}
370 @ntf{all_zero_suppression_number} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
371 @comment{Blank Line}
372 | [@ntf{fixed_LHS_sign} {@ntf{direct_insertion}}] @ntf{all_zero_suppression_number} {@ntf{direct_insertion}}
373 @ntf{fixed_$_char} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
374 @comment{Blank Line}
375 | @ntf{all_sign_number} {@ntf{direct_insertion}} @ntf{fixed_$_char} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
376 @comment{Blank Line}
377 @end{display}
378 @begin{display}
379 @ntf{fixed_#_picture_string} ::=
380 [@ntf{fixed_LHS_sign}] @ntf{single_#_currency} {@ntf{direct_insertion}}
381 [@ntf{zero_suppression}] @ntf{number} [@ntf{RHS_sign}]
382 @comment{Blank Line}
383 | [@ntf{fixed_LHS_sign}] @ntf{multiple_#_currency} {@ntf{direct_insertion}}
384 @ntf{zero_suppression} @ntf{number} [@ntf{RHS_sign}]
385 @comment{Blank Line}
386 | [@ntf{fixed_LHS_sign} {@ntf{direct_insertion}}] [@ntf{zero_suppression}]
387 @ntf{number} @ntf{fixed_#_currency} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
388 @comment{Blank Line}
389 | @ntf{floating_LHS_sign} @ntf{number} @ntf{fixed_#_currency} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
390 @comment{Blank Line}
391 | [@ntf{fixed_LHS_sign}] @ntf{single_#_currency} {@ntf{direct_insertion}}
392 @ntf{all_zero_suppression_number} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
393 @comment{Blank Line}
394 | [@ntf{fixed_LHS_sign}] @ntf{multiple_#_currency} {@ntf{direct_insertion}}
395 @ntf{all_zero_suppression_number} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
396 @comment{Blank Line}
397 | [@ntf{fixed_LHS_sign} {@ntf{direct_insertion}}] @ntf{all_zero_suppression_number} {@ntf{direct_insertion}}
398 @ntf{fixed_#_currency} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
399 @comment{Blank Line}
400 | @ntf{all_sign_number} {@ntf{direct_insertion}} @ntf{fixed_#_currency} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
401 @comment{Blank Line}
402 @end{display}
403 @begin{display}
404 @ntf{floating_currency_picture_string} ::=
405 [@ntf{fixed_LHS_sign}] {@ntf{direct_insertion}} @ntf{floating_$_currency} @ntf{number} [@ntf{RHS_sign}]
406 | [@ntf{fixed_LHS_sign}] {@ntf{direct_insertion}} @ntf{floating_#_currency} @ntf{number} [@ntf{RHS_sign}]
407 | [@ntf{fixed_LHS_sign}] {@ntf{direct_insertion}} @ntf{all_currency_number} {@ntf{direct_insertion}} [@ntf{RHS_sign}]
408 @comment{Blank Line}
409 @end{display}
410 @begin{display}
411 @ntf{non_currency_picture_string} ::=
412 [@ntf{fixed_LHS_sign} {@ntf{direct_insertion}}] @ntf{zero_suppression} @ntf{number} [@ntf{RHS_sign}]
413 | [@ntf{floating_LHS_sign}] @ntf{number} [@ntf{RHS_sign}]
414 | [@ntf{fixed_LHS_sign} {@ntf{direct_insertion}}] @ntf{all_zero_suppression_number} {@ntf{direct_insertion}}
415 [@ntf{RHS_sign}]
416 | @ntf{all_sign_number} {@ntf{direct_insertion}}
417 | @ntf{fixed_LHS_sign} @ntf{direct_insertion} {@ntf{direct_insertion}} @ntf{number} [@ntf{RHS_sign}]
418 @comment{Blank Line}
419 @end{display}
420 @begin{display}
421 @ntf{fixed_LHS_sign} ::= @ntf{LHS_Sign}
422 @end{display}
423 @begin{display}
424 @ntf{LHS_Sign} ::= + | @en | <
425 @comment{Blank Line}
426 @end{display}
427 @begin{display}
428 @ntf{fixed_$_char} ::= $
429 @comment{Blank Line}
430 @end{display}
431 @begin{display}
432 @ntf{direct_insertion} ::= @ntf{simple_insertion}
433 @end{display}
434 @begin{display}
435 @ntf{simple_insertion} ::= _ | B | 0 | /
436 @comment{Blank Line}
437 @end{display}
438 @begin{display}
439 @ntf{zero_suppression} ::= Z {Z | @ntf{context_sensitive_insertion}} | @ntf{fill_string}
440 @end{display}
441 @begin{display}
442 @ntf{context_sensitive_insertion} ::= @ntf{simple_insertion}
443 @comment{Blank Line}
444 @end{display}
445 @begin{display}
446 @ntf{fill_string} ::= * {* | @ntf{context_sensitive_insertion}}
447 @comment{Blank Line}
448 @end{display}
449 @begin{display}
450 @ntf{number} ::=
451 @ntf{fore_digits} [@ntf{radix} [@ntf{aft_digits}] {@ntf{direct_insertion}}]
452 | @ntf{radix} @ntf{aft_digits} {@ntf{direct_insertion}}
453 @end{display}
454 @begin{display}
455 @ntf{fore_digits} ::= 9 {9 | @ntf{direct_insertion}}
456 @end{display}
457 @begin{display}
458 @ntf{aft_digits} ::= {9 | @ntf{direct_insertion}} 9
459 @end{display}
460 @begin{display}
461 @ntf{radix} ::= . | V
462 @comment{Blank Line}
463 @end{display}
464 @begin{display}
465 @ntf{RHS_sign} ::= + | @en | > | CR | DB
466 @comment{Blank Line}
467 @end{display}
468 @begin{display}
469 @ntf{floating_LHS_sign} ::=
470 @ntf{LHS_Sign} {@ntf{context_sensitive_insertion}} @ntf{LHS_Sign} {@ntf{LHS_Sign} | @ntf{context_sensitive_insertion}}
471 @comment{Blank Line}
472 @end{display}
473 @begin{display}
474 @ntf{single_#_currency} ::= #
475 @end{display}
476 @begin{display}
477 @ntf{multiple_#_currency} ::= ## {#}
478 @comment{Blank Line}
479 @end{display}
480 @begin{display}
481 @ntf{fixed_#_currency} ::= @ntf{single_#_currency} | @ntf{multiple_#_currency}
482 @comment{Blank Line}
483 @end{display}
484 @begin{display}
485 @ntf{floating_$_currency} ::=
486 $ {@ntf{context_sensitive_insertion}} $ {$ | @ntf{context_sensitive_insertion}}
487 @comment{Blank Line}
488 @end{display}
489 @begin{display}
490 @ntf{floating_#_currency} ::=
491 # {@ntf{context_sensitive_insertion}} # {# | @ntf{context_sensitive_insertion}}
492 @comment{Blank Line}
493 @end{display}
494 @begin{display}
495 @ntf{all_sign_number} ::= @ntf{all_sign_fore} [@ntf{radix} [@ntf{all_sign_aft}]] [>]
496 @end{display}
497 @begin{display}
498 @ntf{all_sign_fore} ::=
499 @ntf{sign_char} {@ntf{context_sensitive_insertion}} @ntf{sign_char} {@ntf{sign_char} | @ntf{context_sensitive_insertion}}
500 @end{display}
501 @begin{display}
502 @ntf{all_sign_aft} ::= {@ntf{all_sign_aft_char}} @ntf{sign_char}
503 @comment{Blank Line}
504 @ntf{all_sign_aft_char} ::= @ntf{sign_char} | @ntf{context_sensitive_insertion}
505 @end{display}
506 @begin{display}
507 @ntf{sign_char} ::= + | @en | <
508 @comment{Blank Line}
509 @end{display}
510 @begin{display}
511 @ntf{all_currency_number} ::= @ntf{all_currency_fore} [@ntf{radix} [@ntf{all_currency_aft}]]
512 @end{display}
513 @begin{display}
514 @ntf{all_currency_fore} ::=
515 @ntf{currency_char} {@ntf{context_sensitive_insertion}}
516 @ntf{currency_char} {@ntf{currency_char} | @ntf{context_sensitive_insertion}}
517 @end{display}
518 @begin{display}
519 @ntf{all_currency_aft} ::= {@ntf{all_currency_aft_char}} @ntf{currency_char}
520 @comment{Blank Line}
521 @ntf{all_currency_aft_char} ::= @ntf{currency_char} | @ntf{context_sensitive_insertion}
522 @end{display}
523 @begin{display}
524 @ntf{currency_char} ::= $ | #
525 @comment{Blank Line}
526 @end{display}
527 @begin{display}
528 @ntf{all_zero_suppression_number} ::= @ntf{all_zero_suppression_fore} [ @ntf{radix} [@ntf{all_zero_suppression_aft}]]
529 @end{display}
530 @begin{display}
531 @ntf{all_zero_suppression_fore} ::=
532 @ntf{zero_suppression_char} {@ntf{zero_suppression_char} | @ntf{context_sensitive_insertion}}
533 @end{display}
534 @begin{display}
535 @ntf{all_zero_suppression_aft} ::= {@ntf{all_zero_suppression_aft_char}} @ntf{zero_suppression_char}
536 @comment{Blank Line}
537 @ntf{all_zero_suppression_aft_char} ::= @ntf{zero_suppression_char} | @ntf{context_sensitive_insertion}
538 @end{display}
539 @begin{display}
540 @trailing@ntf{zero_suppression_char} ::= Z | *
541 @end{Display}
542
543 @Leading@;The following composition constraints apply to a picture String:
544 @begin{Itemize}
545 A @ntf{floating_LHS_sign} does not have occurrences of different @ntf{LHS_Sign}
546 Character values.
547
548 If a picture String has '<' as @ntf{fixed_LHS_sign}, then it has '>' as
549 @ntf{RHS_sign}.
550
551 If a picture String has '<' in a @ntf{floating_LHS_sign} or in an
552 @ntf{all_sign_number}, then it has an occurrence of '>'.
553
554 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0088],ARef=[AI95-00153]}
555 If a picture String has '+' or '@en@;' as @ntf{fixed_LHS_sign}, in a
556 @ntf{floating_LHS_sign}, or in an @ntf{all_sign_number}, then it has no
557 @ntf{RHS_sign}@Chg{New=[ or '>' character],Old=[]}.
558
559 An instance of @ntf{all_sign_number} does not have occurrences of
560 different @ntf{sign_char} Character values.
561
562 An instance of @ntf{all_currency_number} does not have occurrences of
563 different @ntf{currency_@!char} Character values.
564
565 An instance of @ntf{all_zero_suppression_number} does not have occurrences
566 of different @ntf{zero_@!suppression_@!char} Character values, except for possible
567 case differences between 'Z' and 'z'.
568 @end{Itemize}
569
570 A @i{replicable Character} is a Character that, by the
571 above rules, can occur in two consecutive positions in a picture String.
572
573 @Leading@;A @i{Character replication} is a String
574 @begin{example}
575 @RI{char} & '(' & @RI{spaces} & @RI{count_string} & ')'
576 @end{example}
577 where @i{char} is a replicable Character,
578 @i{spaces} is a String (possibly empty) comprising only space Character values,
579 and @i{count_string} is a String of one or more decimal digit Character
580 values. A Character replication in a picture String has the same effect
581 as (and is said to be @i{equivalent to}) a String comprising @i[n]
582 consecutive occurrences of @i{char}, where
583 @i[n]=Integer'Value(@i{count_string}).
584
585 An @i{expanded picture String} is a picture String containing no
586 Character replications.
587 @begin{Discussion}
588
589 Since 'B' is not allowed after a RHS sign, there is no need
590 for a special rule to disallow "9.99DB(2)" as an abbreviation for
591 "9.99DBB"
592 @end{discussion}
593 @end{RunTime}
594
595 @begin{Notes}
596 Although a sign to the left of the number can float, a sign to the right
597 of the number is in a fixed position.
598 @end{Notes}
599
600 @begin{DiffWord95}
601 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0088],ARef=[AI95-00153-01]}
602 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> The picture string rules for
603 numbers were tightened.]}
604 @end{DiffWord95}
605
606
607 @LabeledSubClause{Edited Output Generation}
608 @begin{RunTime}
609 @Leading@;The contents of an edited output string are based on:
610 @begin{Itemize}
611 A value, Item, of some decimal type Num,
612
613 An expanded picture String Pic_String,
614
615 A Boolean value, Blank_When_Zero,
616
617 A Currency string,
618
619 A Fill character,
620
621 A Separator character, and
622
623 A Radix_Mark character.
624 @end{Itemize}
625
626 The combination of a True value for Blank_When_Zero and a '*' character
627 in Pic_String is inconsistent; no edited output string is defined.
628 @begin{Reason}
629 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]}
630 @ChgAdded{Version=[2],Text=[Such a Pic_String is invalid, and any attempt
631 to use such a string will raise Picture_Error.]}
632 @end{Reason}
633
634
635 A layout error is identified in the rules below if leading
636 nonzero digits of Item, character values of the Currency string,
637 or a negative sign would be
638 truncated; in such cases no edited output string is defined.
639
640 The edited output string has lower bound 1 and upper bound N where
641 N = Pic_String'Length + Currency_Length_Adjustment @en
642 Radix_Adjustment, and
643 @begin{Itemize}
644 Currency_Length_Adjustment =
645 Currency'Length @en@; 1 if there is some occurrence of '$' in
646 Pic_String, and
647 0 otherwise.
648
649 Radix_Adjustment =
650 1 if there is an occurrence of 'V' or 'v' in Pic_Str, and
651 0 otherwise.
652 @end{Itemize}
653
654 @Leading@defn{displayed magnitude (of a decimal value)}
655 Let the magnitude of Item be expressed as a base-10 number
656 I@-(p)@Times@Times@Times@;I@-(1).F@-(1)@Times@Times@Times@;F@-(q),
657 called the @i{displayed} @i{magnitude} of Item,
658 where:
659 @begin{Itemize}
660 q = Min(Max(Num'Scale, 0), n) where n is 0 if Pic_String
661 has no @ntf{radix} and is otherwise the number of digit
662 positions following @ntf{radix} in Pic_String,
663 where a digit position corresponds to an occurrence of
664 '9', a @ntf{zero_suppression_char} (for an
665 @ntf{all_zero_suppression_number}), a @ntf{currency_char}
666 (for an @ntf{all_currency_number}), or a @ntf{sign_char}
667 (for an @ntf{all_sign_number}).
668
669 I@-(p) /= 0 if p>0.
670 @end{Itemize}
671
672 If n < Num'Scale, then the above number is the result of rounding
673 (away from 0 if exactly midway between values).
674
675 If Blank_When_Zero = True and the displayed magnitude of Item
676 is zero,
677 then the edited output string
678 comprises all space character values. Otherwise, the picture String is
679 treated as a sequence of instances of syntactic categories based on
680 the rules in @RefSecNum[Picture String Formation],
681 and the edited output string is the concatenation of
682 string values derived from these categories according to the
683 following mapping rules.
684
685 Table F-1 shows the mapping from a sign control symbol to a
686 corresponding character or string in the edited output. In the
687 columns showing the edited output, a lower-case 'b' represents the
688 space character.
689 If there is no sign control symbol but the value of Item
690 is negative, a layout error occurs and no edited output string
691 is produced.
692
693 @Table{Columns=<3>,Alignment=<AllCenter>,FirstColWidth=[1],LastColWidth=[1],
694 NoBreak=[T],Border=[T],SmallSize=[F],
695 Caption=<@b{Table F-1: Edited Output for Sign Control Symbols}>,
696 Headers=<@b{Sign Control Symbol}@\@b{Edited Output for @*Nonnegative Number}@\@b{Edited Output for @*Negative Number}>,
697 Body=['+'@\'+'@\'@en@;'
698 '@en@;'@\'b'@\'@en@;'
699 '<'@\'b'@\'('
700 '>'@\'b'@\')'
701 "CR"@\"bb"@\"CR"@Last
702 "DB"@\"bb"@\"DB"]}
703
704 An instance of @ntf{fixed_LHS_sign} maps to a character as shown in
705 Table F-1.
706
707 An instance of @ntf{fixed_$_char} maps to Currency.
708
709 An instance of @ntf{direct_insertion} maps to
710 Separator if @ntf{direct_insertion} = '_', and to
711 the @ntf{direct_insertion} Character otherwise.
712
713
714 @Leading@;An instance of @ntf{number} maps to a string
715 @i{integer_part} & @i{radix_part} & @i{fraction_part}
716 where:
717 @begin{Itemize}
718 The string for @i{integer_part} is obtained as follows:
719 @begin{Enumerate}
720 Occurrences of '9' in @ntf{fore_digits} of @ntf{number} are replaced
721 from right to left with the decimal digit character values for
722 I@-(1), ..., I@-(p), respectively.
723
724 Each occurrence of '9' in @ntf{fore_digits}
725 to the left of the leftmost '9' replaced according
726 to rule 1 is replaced with '0'.
727
728 If p exceeds the number of occurrences of '9' in
729 @ntf{fore_digits} of @ntf{number}, then the excess leftmost
730 digits are eligible for use in the mapping of
731 an instance of @ntf{zero_suppression}, @ntf{floating_LHS_sign},
732 @ntf{floating_$_currency},
733 or @ntf{floating_#_currency} to the left of @ntf{number};
734 if there is no such instance, then a layout error
735 occurs and no edited output string is produced.
736 @end{Enumerate}
737
738 @leading@;The @i{radix_part} is:
739 @begin{InnerItemize}
740 "" if @ntf{number} does not include a @ntf{radix}, if @ntf{radix} = 'V',
741 or if @ntf{radix} = 'v'
742
743 Radix_Mark if @ntf{number} includes '.' as @ntf{radix}
744 @end{InnerItemize}
745
746 @leading@;The string for @i{fraction_part} is obtained as follows:
747 @begin{Enumerate}
748 Occurrences of '9'
749 in @ntf{aft_digits} of @ntf{number} are replaced
750 from left to right with the decimal digit character values for F@-(1),
751 ... F@-(q).
752
753 Each occurrence of '9' in @ntf{aft_digits}
754 to the right of the rightmost '9' replaced according to rule 1
755 is replaced by '0'.
756 @end{Enumerate}
757 @end{Itemize}
758
759 @leading@;An instance of @ntf{zero_suppression} maps to the string obtained as follows:
760 @begin{Enumerate}
761 The rightmost 'Z', 'z', or '*' Character values
762 are replaced
763 with the excess digits (if any)
764 from the @i{integer_part} of the mapping of the @ntf{number}
765 to the right of the @ntf{zero_suppression} instance,
766
767 A @ntf{context_sensitive_insertion} Character is replaced
768 as though it were a @ntf{direct_insertion} Character, if
769 it occurs to the right of some 'Z', 'z', or '*' in
770 @ntf{zero_suppression} that has been mapped to an excess
771 digit,
772
773 @leading@;Each Character to the left of the
774 leftmost Character replaced according to rule 1 above
775 is replaced by:
776 @begin{InnerItemize}
777 the space character if the zero suppression Character is
778 'Z' or 'z', or
779
780 the Fill character if the zero suppression Character is '*'.
781 @end{InnerItemize}
782
783 A layout error occurs if some excess digits remain
784 after all 'Z', 'z', and '*' Character values in
785 @ntf{zero_suppression} have been replaced via rule 1; no
786 edited output string is produced.
787 @end{Enumerate}
788
789 An instance of @ntf{RHS_sign} maps to a character or string
790 as shown in Table F-1.
791
792
793 An instance of @ntf{floating_LHS_sign} maps to the string obtained as follows.
794 @begin{Enumerate}
795 Up to all but one of the rightmost @ntf{LHS_Sign}
796 Character values are replaced by the excess digits (if any)
797 from the @i{integer_part} of the mapping of the @ntf{number}
798 to the right of the @ntf{floating_LHS_sign} instance.
799
800 The next Character to the left is replaced
801 with the character given by the entry in Table F-1
802 corresponding to the @ntf{LHS_Sign} Character.
803
804 A @ntf{context_sensitive_insertion} Character is replaced
805 as though it were a @ntf{direct_insertion} Character, if
806 it occurs to the right of the leftmost @ntf{LHS_Sign}
807 character replaced according to rule 1.
808
809 Any other Character is replaced by the space character..
810
811 A layout error occurs if some excess digits remain
812 after replacement via rule 1; no edited output string is
813 produced.
814 @end{Enumerate}
815
816 An instance of @ntf{fixed_#_currency} maps to the Currency string with n
817 space character values concatenated on the left (if the instance does
818 not follow a @ntf{radix}) or on the right (if the instance does follow a
819 @ntf{radix}), where n is the difference between the length of the
820 @ntf{fixed_#_currency} instance and Currency'Length. A layout error
821 occurs if Currency'Length exceeds the length of the
822 @ntf{fixed_#_currency} instance; no edited output string is produced.
823
824
825 @Leading@;An instance of @ntf{floating_$_currency} maps to the string
826 obtained as follows:
827 @begin{Enumerate}
828 Up to all but one of the rightmost '$'
829 Character values are replaced
830 with the excess digits (if any)
831 from the @i{integer_part} of the mapping of the @ntf{number}
832 to the right of the @ntf{floating_$_currency} instance.
833
834 The next Character to the left is replaced
835 by the Currency string.
836
837 A @ntf{context_sensitive_insertion} Character is replaced
838 as though it were a @ntf{direct_insertion} Character, if
839 it occurs to the right of the leftmost '$' Character
840 replaced via rule 1.
841
842 Each other Character is replaced by the space character.
843
844 A layout error occurs if some excess digits remain
845 after replacement by rule 1; no edited output string is
846 produced.
847 @end{Enumerate}
848
849 @leading@;An instance of @ntf{floating_#_currency} maps to the string obtained
850 as follows:
851 @begin{Enumerate}
852 Up to all but one of the rightmost '#'
853 Character values are replaced
854 with the excess digits (if any)
855 from the @i{integer_part} of the mapping of the @ntf{number}
856 to the right of the
857 @ntf{floating_#_currency} instance.
858
859 The substring whose last Character occurs at the position immediately
860 preceding the leftmost Character replaced via rule 1, and whose
861 length is Currency'Length, is replaced by the Currency string.
862
863 A @ntf{context_sensitive_insertion} Character is replaced
864 as though it were a @ntf{direct_insertion} Character, if
865 it occurs to the right of the leftmost '#'
866 replaced via rule 1.
867
868 Any other Character is replaced by the space character.
869
870 A layout error occurs if some excess digits remain
871 after replacement rule 1, or if there is no substring
872 with the required length for replacement rule 2; no edited
873 output string is produced.
874 @end{Enumerate}
875
876 @leading@;An instance of @ntf{all_zero_suppression_number} maps to:
877 @begin{Itemize}
878 a string of all spaces if
879 the displayed magnitude of Item is zero,
880 the @ntf{zero_suppression_char}
881 is 'Z' or 'z', and the instance of
882 @ntf{all_zero_suppression_number} does not have
883 a @ntf{radix} at its last character position;
884
885 a string containing the Fill character in each position except
886 for the character (if any) corresponding to @ntf{radix}, if
887 @ntf{zero_suppression_char} = '*' and the
888 displayed magnitude of Item is zero;
889
890 otherwise,
891 the same result as if each @ntf{zero_suppression_char} in
892 @ntf{all_zero_suppression_aft} were '9', interpreting
893 the instance of @ntf{all_zero_suppression_number} as
894 either @ntf{zero_suppression} @ntf{number} (if a @ntf{radix}
895 and @ntf{all_zero_suppression_aft} are present), or
896 as @ntf{zero_suppression} otherwise.
897 @end{Itemize}
898
899 @leading@;An instance of @ntf{all_sign_number} maps to:
900 @begin{Itemize}
901 a string of all spaces if
902 the displayed magnitude of Item is zero and the
903 instance of @ntf{all_sign_number} does not have a @ntf{radix}
904 at its last character position;
905
906 otherwise,
907 the same result as if each @ntf{sign_char} in
908 @ntf{all_sign_number_aft} were '9', interpreting
909 the instance of @ntf{all_sign_number} as
910 either @ntf{floating_LHS_sign} @ntf{number} (if a @ntf{radix}
911 and @ntf{all_sign_number_aft} are present), or
912 as @ntf{floating_LHS_sign} otherwise.
913 @end{Itemize}
914
915 @leading@;An instance of @ntf{all_currency_number} maps to:
916 @begin{Itemize}
917 a string of all spaces if
918 the displayed magnitude of Item is zero and the
919 instance of @ntf{all_currency_number} does not have a @ntf{radix}
920 at its last character position;
921
922 otherwise,
923 the same result as if each @ntf{currency_char} in
924 @ntf{all_currency_number_aft} were '9', interpreting
925 the instance of @ntf{all_currency_number} as
926 @ntf{floating_$_currency} @ntf{number} or
927 @ntf{floating_#_currency} @ntf{number}
928 (if a @ntf{radix}
929 and @ntf{all_currency_number_aft} are present), or
930 as @ntf{floating_$_currency} or @ntf{floating_#_currency}
931 otherwise.
932 @end{Itemize}
933 @end{RunTime}
934
935 @begin{Examples}
936 In the result string values shown below, 'b' represents the space character.
937 @begin{Example}
938 Item: Picture and Result Strings:
939
940 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0248-1]}
941 123456.78 Picture: "-###**_***_**9.99"
942 @Chg{New=[Result:],Old=[ ]} "bbb$***123,456.78"
943 "bbFF***123.456,78" (currency = "FF",
944 separator = '.',
945 radix mark = ',')
946
947 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0089],ARef=[AI95-00070]}
948 123456.78 Picture: "-@Chg{New=[],Old=[$$]}$**_***_**9.99"
949 Result: "@Chg{New=[],Old=[bb]}b$***123,456.78"
950 "b@Chg{New=[],Old=[bb]}FF***123.456,78" (currency = "FF",
951 @Chg{New=[],Old=[ ]} separator = '.',
952 @Chg{New=[],Old=[ ]} radix mark = ',')
953
954 0.0 Picture: "-$$$$$$.$$"
955 Result: "bbbbbbbbbb"
956
957 0.20 Picture: "-$$$$$$.$$"
958 Result: "bbbbbb$.20"
959
960 -1234.565 Picture: "<<<<_<<<.<<###>"
961 Result: "bb(1,234.57DMb)" (currency = "DM")
962
963 12345.67 Picture: "###_###_##9.99"
964 Result: "bbCHF12,345.67" (currency = "CHF")
965 @end{Example}
966 @end{Examples}
967
968 @begin{DiffWord95}
969 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0089],ARef=[AI95-00070-01]}
970 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the picture string
971 example.]}
972 @end{DiffWord95}
973
974
975 @LabeledSubClause{The Package Text_IO.Editing}
976 @begin{Intro}
977 The package Text_IO.Editing provides a private type Picture with associated
978 operations, and a generic package Decimal_Output.
979 An object of type Picture is composed from a well-formed picture String
980 (see @RefSecNum(Picture String Formation)) and a Boolean item indicating
981 whether a zero numeric value will result in an edited output string
982 of all space characters.
983 The package Decimal_Output
984 contains edited output subprograms implementing the effects defined
985 in @RefSecNum(Edited Output Generation).
986 @end{Intro}
987
988 @begin{StaticSem}
989 @leading@;The library package Text_IO.Editing has the following declaration:
990 @begin{Example}
991 @key(package) Ada.Text_IO.Editing @key(is)@ChildUnit{Parent=[Ada.Text_IO],Child=[Editing]}
992
993 @key(type) @AdaTypeDefn{Picture} @key(is) @key(private);
994
995 @key(function) @AdaSubDefn{Valid} (Pic_String : @key(in) String;
996 Blank_When_Zero : @key(in) Boolean := False) @key(return) Boolean;
997
998 @key(function) @AdaSubDefn{To_Picture} (Pic_String : @key(in) String;
999 Blank_When_Zero : @key(in) Boolean := False)
1000 @key(return) Picture;
1001
1002 @key(function) @AdaSubDefn{Pic_String} (Pic : @key(in) Picture) @key(return) String;
1003 @key(function) @AdaSubDefn{Blank_When_Zero} (Pic : @key(in) Picture) @key(return) Boolean;
1004
1005 @AdaObjDefn{Max_Picture_Length} : @key(constant) := @RI{implementation_defined};
1006
1007 @AdaExcDefn{Picture_Error} : @key(exception);
1008
1009 @AdaObjDefn{Default_Currency} : @key(constant) String := "$";
1010 @AdaObjDefn{Default_Fill} : @key(constant) Character := '*';
1011 @AdaObjDefn{Default_Separator} : @key(constant) Character := ',';
1012 @AdaObjDefn{Default_Radix_Mark} : @key(constant) Character := '.';
1013
1014 @key(generic)
1015 @key(type) Num @key(is) @key(delta) <> @key(digits) <>;
1016 Default_Currency : @key(in) String := Text_IO.Editing.Default_Currency;
1017 Default_Fill : @key(in) Character := Text_IO.Editing.Default_Fill;
1018 Default_Separator : @key(in) Character :=
1019 Text_IO.Editing.Default_Separator;
1020 Default_Radix_Mark : @key(in) Character :=
1021 Text_IO.Editing.Default_Radix_Mark;
1022 @key(package) @AdaPackDefn{Decimal_Output} @key(is)
1023 @key(function) @AdaSubDefn{Length} (Pic : @key(in) Picture;
1024 Currency : @key(in) String := Default_Currency)
1025 @key(return) Natural;
1026
1027 @key(function) @AdaSubDefn{Valid} (Item : @key(in) Num;
1028 Pic : @key(in) Picture;
1029 Currency : @key(in) String := Default_Currency)
1030 @key(return) Boolean;
1031
1032 @key(function) @AdaSubDefn{Image} (Item : @key(in) Num;
1033 Pic : @key(in) Picture;
1034 Currency : @key(in) String := Default_Currency;
1035 Fill : @key(in) Character := Default_Fill;
1036 Separator : @key(in) Character := Default_Separator;
1037 Radix_Mark : @key(in) Character := Default_Radix_Mark)
1038 @key(return) String;
1039
1040 @key(procedure) @AdaSubDefn{Put} (File : @key(in) File_Type;
1041 Item : @key(in) Num;
1042 Pic : @key(in) Picture;
1043 Currency : @key(in) String := Default_Currency;
1044 Fill : @key(in) Character := Default_Fill;
1045 Separator : @key(in) Character := Default_Separator;
1046 Radix_Mark : @key(in) Character := Default_Radix_Mark);
1047
1048 @key(procedure) @AdaSubDefn{Put} (Item : @key(in) Num;
1049 Pic : @key(in) Picture;
1050 Currency : @key(in) String := Default_Currency;
1051 Fill : @key(in) Character := Default_Fill;
1052 Separator : @key(in) Character := Default_Separator;
1053 Radix_Mark : @key(in) Character := Default_Radix_Mark);
1054
1055 @trailing@; @key(procedure) @AdaSubDefn{Put} (To : @key(out) String;
1056 Item : @key(in) Num;
1057 Pic : @key(in) Picture;
1058 Currency : @key(in) String := Default_Currency;
1059 Fill : @key(in) Character := Default_Fill;
1060 Separator : @key(in) Character := Default_Separator;
1061 Radix_Mark : @key(in) Character := Default_Radix_Mark);
1062 @key(end) Decimal_Output;
1063 @key(private)
1064 ... @RI{-- not specified by the language}
1065 @key(end) Ada.Text_IO.Editing;
1066 @end{Example}
1067 @ImplDef{The value of Max_Picture_Length in the package Text_IO.Editing}
1068
1069 @Trailing@;The exception Constraint_Error is raised
1070 if the Image function or any of the
1071 Put procedures is invoked with a null string for Currency.
1072 @begin{DescribeCode}
1073 @begin{Example}@Keepnext
1074 @key(function) Valid (Pic_String : @key(in) String;
1075 Blank_When_Zero : @key(in) Boolean := False) @key(return) Boolean;
1076 @end{Example}
1077 @Trailing@;Valid returns True if Pic_String is a well-formed picture String
1078 (see @RefSecNum(Picture String Formation)) the
1079 length of whose expansion does not exceed Max_Picture_Length, and if
1080 either Blank_When_Zero is False or Pic_String contains no '*'.
1081
1082 @begin{Example}@Keepnext
1083 @key(function) To_Picture (Pic_String : @key(in) String;
1084 Blank_When_Zero : @key(in) Boolean := False)
1085 @key(return) Picture;
1086 @end{Example}
1087 @Trailing@;To_Picture returns a result Picture such that the application of the
1088 function Pic_String to this result
1089 yields an expanded picture String equivalent to Pic_String, and such
1090 that Blank_When_Zero applied to the result Picture is the same value as the
1091 parameter Blank_When_Zero.
1092 Picture_Error is raised if not
1093 Valid(Pic_String, Blank_When_Zero).
1094
1095 @begin{Example}
1096 @key(function) Pic_String (Pic : @key(in) Picture) @key(return) String;
1097 @Comment{Blank line}
1098 @key(function) Blank_When_Zero (Pic : @key(in) Picture) @key(return) Boolean;
1099 @end{Example}
1100 @Leading@;If Pic is To_Picture(String_Item, Boolean_Item) for some String_Item and
1101 Boolean_Item, then:
1102 @begin[itemize]
1103 Pic_String(Pic) returns an expanded picture String
1104 equivalent to String_Item and with any lower-case letter
1105 replaced with its corresponding upper-case form, and
1106
1107 Blank_When_Zero(Pic) returns Boolean_Item.
1108 @end[Itemize]
1109
1110 @Leading@;If Pic_1 and Pic_2 are objects of type Picture, then "="(Pic_1, Pic_2)
1111 is True when
1112 @begin[itemize]
1113 Pic_String(Pic_1) = Pic_String(Pic_2), and
1114
1115 @Trailing@;Blank_When_Zero(Pic_1) = Blank_When_Zero(Pic_2).
1116 @end[Itemize]
1117
1118 @begin{Example}@Keepnext
1119 @key(function) Length (Pic : @key(in) Picture;
1120 Currency : @key(in) String := Default_Currency)
1121 @key(return) Natural;
1122 @end{Example}
1123 @Leading@;Length returns Pic_String(Pic)'Length + Currency_Length_Adjustment @en
1124 Radix_Adjustment where
1125 @begin[itemize]
1126 @Leading@;Currency_Length_Adjustment =
1127 @begin[Inneritemize]
1128 Currency'Length @en@; 1 if there is some occurrence of '$' in
1129 Pic_String(Pic), and
1130
1131 0 otherwise.
1132 @end[Inneritemize]
1133
1134 @Leading@;Radix_Adjustment =
1135 @begin[Inneritemize]
1136 1 if there is an occurrence of 'V' or 'v' in Pic_Str(Pic), and
1137
1138 @Trailing@;0 otherwise.
1139 @end[Inneritemize]
1140 @end[itemize]
1141
1142 @begin{Example}@Keepnext
1143 @key(function) Valid (Item : @key(in) Num;
1144 Pic : @key(in) Picture;
1145 Currency : @key(in) String := Default_Currency)
1146 @key(return) Boolean;
1147 @end{Example}
1148 @Trailing@;Valid returns True if Image(Item, Pic, Currency) does not raise
1149 Layout_Error, and returns False otherwise.
1150
1151 @begin{Example}
1152 @key(function) Image (Item : @key(in) Num;
1153 Pic : @key(in) Picture;
1154 Currency : @key(in) String := Default_Currency;
1155 Fill : @key(in) Character := Default_Fill;
1156 Separator : @key(in) Character := Default_Separator;
1157 Radix_Mark : @key(in) Character := Default_Radix_Mark)
1158 @key(return) String;
1159 @end{Example}
1160 @Trailing@;Image returns the edited output String as defined in
1161 @RefSecNum(Edited Output Generation) for Item,
1162 Pic_String(Pic), Blank_When_Zero(Pic),
1163 Currency, Fill, Separator,
1164 and Radix_Mark. If these rules identify a layout error, then Image
1165 raises the exception Layout_Error.
1166
1167 @begin{Example}
1168 @key(procedure) Put (File : @key(in) File_Type;
1169 Item : @key(in) Num;
1170 Pic : @key(in) Picture;
1171 Currency : @key(in) String := Default_Currency;
1172 Fill : @key(in) Character := Default_Fill;
1173 Separator : @key(in) Character := Default_Separator;
1174 Radix_Mark : @key(in) Character := Default_Radix_Mark);
1175 @Comment{Blank line}
1176 @key(procedure) Put (Item : @key(in) Num;
1177 Pic : @key(in) Picture;
1178 Currency : @key(in) String := Default_Currency;
1179 Fill : @key(in) Character := Default_Fill;
1180 Separator : @key(in) Character := Default_Separator;
1181 Radix_Mark : @key(in) Character := Default_Radix_Mark);
1182 @end{Example}
1183 @Trailing@;Each of these Put procedures
1184 outputs Image(Item, Pic, Currency, Fill, Separator, Radix_Mark)
1185 consistent with the conventions for Put for other real types in case
1186 of bounded line length (see @RefSec{Get and Put Procedures}).
1187
1188 @begin{Example}
1189 @key(procedure) Put (To : @key(out) String;
1190 Item : @key(in) Num;
1191 Pic : @key(in) Picture;
1192 Currency : @key(in) String := Default_Currency;
1193 Fill : @key(in) Character := Default_Fill;
1194 Separator : @key(in) Character := Default_Separator;
1195 Radix_Mark : @key(in) Character := Default_Radix_Mark);
1196 @end{Example}
1197
1198 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
1199 Put copies Image(Item, Pic, Currency, Fill, Separator, Radix_Mark)
1200 to the given string, right justified. Otherwise@Chg{Version=[3],New=[,],Old=[]}
1201 unassigned Character values
1202 in To are assigned the space character. If To'Length is less than
1203 the length of the string resulting from Image, then Layout_Error is raised.
1204 @end{DescribeCode}
1205 @end{StaticSem}
1206
1207 @begin{ImplReq}
1208 Max_Picture_Length shall be at least 30.
1209 The implementation shall support currency strings of length
1210 up to at least 10, both for Default_Currency in an instantiation of
1211 Decimal_Output, and for Currency in an invocation of Image or any
1212 of the Put procedures.
1213 @begin{Discussion}
1214 This implies that a picture string with character replications
1215 need not be supported (i.e., To_Picture will raise Picture_Error)
1216 if its expanded form exceeds 30 characters.
1217 @end{Discussion}
1218 @end{ImplReq}
1219
1220 @begin{Notes}
1221 @Leading@;The rules for edited output are based on COBOL (ANSI X3.23:1985,
1222 endorsed by ISO as ISO 1989-1985), with the
1223 following differences:
1224 @begin{Itemize}
1225 The COBOL provisions for picture string localization and for 'P' format
1226 are absent from Ada.
1227
1228 @Leading@;The following Ada facilities are not in COBOL:
1229 @begin{InnerItemize}
1230 currency symbol placement after the number,
1231
1232 localization of edited output string for multi-character
1233 currency string values, including support for both length-preserving
1234 and length-expanding currency symbols in picture strings
1235
1236 localization of the radix mark, digits separator, and
1237 fill character, and
1238
1239 parenthesization of negative values.
1240 @end{InnerItemize}
1241 @end{Itemize}
1242 @ChgNote{The following paragraph is missing a number in the original version.
1243 To give it a number in the new version, it is marked as an insertion.}
1244 @ChgRef{Version=[0],Kind=[Added]}@NoPrefix
1245 @Chg{New=[],Old=[@Noparanum@;]}The value of 30 for Max_Picture_Length is the
1246 same limit as in COBOL.
1247 @end{Notes}
1248
1249 @begin{Reason}
1250 There are several reasons we have not adopted the COBOL-style permission to
1251 provide a single-character replacement in the picture string for the `$' as
1252 currency symbol, or to interchange the roles of `.' and `,' in picture strings
1253 @begin{Itemize}
1254 It would have introduced considerable complexity into Ada, as well as
1255 confusion between run-time and compile-time character interpretation, since
1256 picture Strings are dynamically computable in Ada, in contrast with COBOL
1257
1258 Ada's rules for real literals provide a natural interpretation of `_' as
1259 digits separator and `.' for radix mark; it is not essential to allow these to
1260 be localized in picture strings, since Ada does not allow them to be localized
1261 in real literals.
1262
1263 The COBOL restriction for the currency symbol in a picture string to be
1264 replaced by
1265 a single character currency symbol is a compromise
1266 solution. For general international usage
1267 a mechanism is needed to localize the edited output to
1268 be a multi-character currency string. Allowing a single-Character
1269 localization for the picture Character, and a multiple-character localization
1270 for the currency string, would be an unnecessary complication.
1271 @end{Itemize}
1272 @end{Reason}
1273
1274 @LabeledSubClause{The Package Wide_Text_IO.Editing}
1275
1276 @begin{StaticSem}
1277 @Leading@;@Defn{Ada.Wide_@!Text_IO.Editing}
1278 @ChildUnit{Parent=[Ada.Wide_@!Text_IO],Child=[Editing]}
1279 The child package Wide_Text_IO.Editing has
1280 the same contents as Text_IO.Editing, except that:
1281 @begin{Itemize}
1282 each occurrence of Character is replaced by Wide_Character,
1283
1284 each occurrence of Text_IO is replaced by Wide_Text_IO,
1285
1286 the subtype of Default_Currency is Wide_String rather than String, and
1287
1288 each occurrence of String
1289 in the generic package Decimal_Output is replaced by
1290 Wide_String.
1291 @end{Itemize}
1292 @ImplDef{The value of Max_Picture_Length in the package Wide_Text_IO.Editing}
1293 @end{StaticSem}
1294
1295 @begin{Notes}
1296 Each of the functions Wide_Text_IO.Editing.Valid, To_Picture, and Pic_String has String (versus
1297 Wide_String) as its parameter or result subtype, since a picture String
1298 is not localizable.
1299 @end{Notes}
1300
1301 @LabeledAddedSubClause{Version=[2],Name=[The Package Wide_Wide_Text_IO.Editing]}
1302
1303
1304 @begin{StaticSem}
1305 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
1306 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{Ada.Wide_@!Wide_@!Text_IO.Editing}
1307 @ChildUnit{Parent=[Ada.Wide_@!Wide_@!Text_IO],Child=[Editing]}
1308 The child package Wide_Wide_Text_IO.Editing has
1309 the same contents as Text_IO.Editing, except that:]}
1310 @begin{Itemize}
1311 @ChgRef{Version=[2],Kind=[AddedNormal]}
1312 @ChgAdded{Version=[2],Text=[each occurrence of Character is replaced by
1313 Wide_Wide_Character,]}
1314
1315 @ChgRef{Version=[2],Kind=[AddedNormal]}
1316 @ChgAdded{Version=[2],Text=[each occurrence of Text_IO is replaced by
1317 Wide_Wide_Text_IO,]}
1318
1319 @ChgRef{Version=[2],Kind=[AddedNormal]}
1320 @ChgAdded{Version=[2],Text=[the subtype of Default_Currency is Wide_Wide_String
1321 rather than String, and]}
1322
1323 @ChgRef{Version=[2],Kind=[AddedNormal]}
1324 @ChgAdded{Version=[2],Text=[each occurrence of String
1325 in the generic package Decimal_Output is replaced by
1326 Wide_Wide_String.]}
1327 @end{Itemize}
1328 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@Chg{Version=[2],New=[The
1329 value of Max_Picture_Length in the package Wide_Wide_Text_IO.Editing],Old=[]}]}
1330
1331 @end{StaticSem}
1332
1333 @begin{Notes}
1334 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
1335 @ChgAdded{Version=[2],Text=[Each of the functions
1336 Wide_Wide_Text_IO.Editing.Valid, To_Picture, and Pic_String has String (versus
1337 Wide_Wide_String) as its parameter or result subtype, since a picture String is
1338 not localizable.]}
1339 @end{Notes}
1340
1341 @begin{Extend95}
1342 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
1343 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1344 Package Wide_Wide_Text_IO.Editing is new; it supports 32-bit character
1345 strings. (Shouldn't it have been
1346 @lquotes@;Widest_Text_IO.Editing@rquotes@;? :-)]}
1347 @end{Extend95}
1348
1349