Top Prev Next Up Down

SubC

SubC works an looks like substring (Java) or substr (PL/I) but we use the name ‘subC’ because we are working with 21-bit characters and all indexing is based on theese 21-bit characters.

function subC(value:Cfix;first:Integer:=Integer'First; length:Integer:=Integer'First;last:Integer:=Integer'First) return CFix;

function subC(value:String;first:Integer:=Integer'First; length:Integer:=Integer'First;last:Integer:=Integer'First) return String;

function subC(value:Cvar;first:Integer:=Integer'First; length:Integer:=Integer'First;last:Integer:=Integer'First) 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 ("subC(v10) .........>" & subC(v10));
  result: subC(v10) .........>1234567890
  Parameters first, length and last are all defaulted and the result is the same as the value of the ‘value’ parameter.
[2] Ada.Text_IO.Put_Line ("subC(v10,2) .......>" & subC(v10,2));
  result: subC(v10,2) .......>234567890
  Parameters length and last is defaulted and the result is from the ‘2’ to the end of the string.
[3] Ada.Text_IO.Put_Line ("subC(v10,2,3) .....>" & subC(v10,2,3));
  result: subC(v10,2,3) .....>234
  Parameter ‘last’ is defaulted and ignored.
[4] Ada.Text_IO.Put_Line ("subC(v10,2,last=>5)>" & subC(v10,2,last=>5));
  result: subC(v10,2,last=>5)>2345
  Parameter ‘length’ is defaulted and ignored.
[5] Ada.Text_IO.Put_Line ("subC(v10,2,8,6) ...>" & subC(v10,2,8,6));
  result: subC(v10,2,8,6) ...>23456
  Parameter ‘length’ and ‘last’ is both given. The result is the shortest version.
[6] Ada.Text_IO.Put_Line ("subC(v10,length=>5)>" & subC(v10,length=>5));
  result: subC(v10,length=>5)>12345
  Parametersfirst’ and ‘last’ are defulted.
[7] Ada.Text_IO.Put_Line ("subC(v10,2,0) .....>" & subC(v10,2,0) & "< zero length");
  result: subC(v10,2,0) .....>< zero length
  Parameter length has a value of zero.
[8] Ada.Text_IO.Put_Line ("subC(v10,2,last=>1)>" & subC(v10,2,last=>1) & "< zero length");
  result: subC(v10,2,last=>1)>< zero length
  Parameter last has a value one smaller than first.
[9] Ada.Text_IO.Put_Line ("subC(v10,2,0,8) ...>" & subC(v10,2,0,8) & "< zero length");
  result: subC(v10,2,0,8) ...>< zero length
  Parameter length has a value of zero and a zero length result is the shortest solution.
[10] Ada.Text_IO.Put_Line ("subC(w,3,6,2) ...>" & subC(w,3,6,2) & "< zero length");
  result: subC(w,3,6,2) ...>< zero length
  Parameter ‘last has a value smaller than first and a zero length result is the shortest solution.
[11] Ada.Text_IO.Put_Line ("subC(w,length=>0)>" & subC(w,length=>0) & "< zero length");
  result: subC(w,length=>0)>< zero length
[12] Ada.Text_IO.Put_Line ("subC(z) .........>" & subC(z) & "< zero length");
  result: subC(z) .........>< zero length
[13] Ada.Text_IO.Put_Line ("subC(z,length=>0)>" & subC(z,length=>0) & "< zero length");
  result: subC(z,length=>0)>< zero length