Top Prev Next Up Down
CenterC
Center the result. Because we are working with 21-bit characters
and all indexing is based on theese 21-bit characters.
function centerC(value:CFix;length:Integer;pad:CFix:=CFix_Space)
return CFix;
function centerC(value:String;length:Integer;pad:String:=" ")
return String;
function centerC(value:CVar;length:Integer;pad:CFix:=CFix_Space)
return CVar;
Examples:
001| v10:String:="1234567890";
002|
w:String:=(3=>'3',4=>'4',5=>'5');
003| x8:String:=" ABC ";
004| y14:String:="abcdefghijklmn";
005| y15:String:="abcdefghijklmnU";
006| z:String(1 .. 0);
[1] Ada.Text_IO.Put_Line ( "centerC(y14,10).>" &
centerC(y14,10) & "<");
result: centerC(y14,10).>cdefghijkl<
[2] Ada.Text_IO.Put_Line ( "centerC(y14,11).>" &
centerC(y14,11) & "<");
result: centerC(y14,11).>cdefghijklm<
[3] Ada.Text_IO.Put_Line ( "centerC(y14,14).>" &
centerC(y14,14) & "<");
result: centerC(y14,14).>abcdefghijklmn<
[4] Ada.Text_IO.Put_Line ( "centerC(y15,15).>" &
centerC(y15,15) & "<");
result: centerC(y15,15).>abcdefghijklmnU<
[5] Ada.Text_IO.Put_Line ( "centerC("""",10,"""").>" &
centerC("",10,"") & "<");
result: centerC("",10,"").>����������<
The string is empty and no pad is
given or defaulted. But the result must have a length of ten. The
result is ten Unicode ‘replacement characters’.
[6] Ada.Text_IO.Put_Line ( "centerC(y14,15).>" &
centerC(y14,15) & "<");
result: centerC(y14,15).>abcdefghijklmn
<
[7] Ada.Text_IO.Put_Line ( "centerC(y14,16).>" &
centerC(y14,16) & "<");
result: centerC(y14,16).>
abcdefghijklmn <
[8] Ada.Text_IO.Put_Line ( "centerC(y14,16,""!"").>" &
centerC(y14,16,"!") & "<");
result: centerC(y14,16,"!").>!abcdefghijklmn!<
[9] Ada.Text_IO.Put_Line ( "centerC(y14,18,""! "").>" &
centerC(y14,18,"! ") & "<");
result: centerC(y14,18,"!
").>! abcdefghijklmn !<
[10] Ada.Text_IO.Put_Line ( "centerC(y14,20,""!."").>" &
centerC(y14,20,"!.") & "<");
result: centerC(y14,20,"!.").>!..abcdefghijklmn..!<
[11] Ada.Text_IO.Put_Line ( "centerC(y14,21,""!."").>" &
centerC(y14,21,"!.") & "<");
result: centerC(y14,21,"!.").>!..abcdefghijklmn...!<
[12] Ada.Text_IO.Put_Line ( "centerC("",21,""!="").>" &
centerC("",21,"!=") & "<");
result: centerC(",21,"!=").>!===================!<
By coding ‘Put_Line(centerC(“”,12,”!=”));
Put_Line(centerC(“Anything”,12,”! ”));
Put_Line(centerC(“”,12,”!=”));’ you get a box as output
!========!
! Anything !
!========!
The centerC function duplicate the last storage unit of
the pad is needed and reverse the pad for the right end. This
feature of centerC-function is used for construction of the box.
Store data from value in a way to keep the middle of the
storage units as much as possible in the center of the result.