Debian Codegraph @

source_2005/infosys.mss

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