From: Borja TORON ANTONS <toron@ccucvx.unican.es>
Subject: Oh, no! Ada-strings...
Date: Fri, 24 Apr 1992 21:24:08 UTC+0100 [thread overview]
Message-ID: <182*/S=toron/OU=ccucvx/O=unican/PRMD=iris/ADMD=mensatex/C=es/@MHS> (raw)
Brian,
the problem with ADA-strings is that range is too static. Your "empty string"
is 0-length, but your variable 'str' is a 100-length string...
they're different types for the compiler.
The solution is to use 'variable strings' as follows:
==================
Package Var_string is
type vstring(len: natural:=200) is record
str : STRING (1..len);
end record;
function "&" (s1,s2: in vstring) return vstring;
function "&" (s1: in vstring; car : in CHARACTER) return vstring;
function find (todo,sub_str: in vstring) return NATURAL;
function copy (cadena: in vstring; index, count: in natural) return vstring;
procedure delete(cadena: in out vstring; index, count: natural);
function convert(s:string) return vstring;
function "<" (iz,de: in vstring) return BOOLEAN;
function ">" (iz,de: in vstring) return BOOLEAN;
end Var_string;
==================
--------------------------------------
==================
package body Var_string is
function "&" (s1,s2: in vstring) return vstring is
begin
return (s1.len+s2.len,s1.str&s2.str);
end "&";
function "&" (s1: in vstring; car : in CHARACTER) return vstring is
begin
return (s1.len+1,s1.str&car);
end "&";
function find (todo,sub_str : in vstring) return NATURAL is
begin
for i in 1..todo.len-sub_str.len+1 loop
if todo.str(i..i+sub_str.len-1)=sub_str.str then
return i;
end if;
end loop;
return 0;
end;
function copy(cadena: in vstring; index, count: in natural) return vstring i
s
s:vstring;
indice:natural:=index;
begin
s:=(0,"");
while (indice<=cadena.len)and(indice<=(index+count-1)) loop
s:=s&cadena.str(indice);
indice:=indice+1;
end loop;
return s;
end;
procedure delete(cadena: in out vstring; index, count: natural) is
final: natural :=index+count;
sub1, sub2: vstring;
begin
sub1:=(index-1, cadena.str(1..index-1));
if final<cadena.len then
sub2:=(cadena.len-count, cadena.str(final..cadena.len));
cadena:=sub1&sub2;
else
cadena:= sub1;
end if;
end;
function "<" (iz,de: in vstring) return BOOLEAN is
begin
return iz.str<de.str;
end "<";
function ">" (iz,de: in vstring) return BOOLEAN is
begin
return iz.str>de.str;
end ">";
function convert(s:string) return vstring is
begin
return(s'last+1-s'first,s);
end;
end Var_string;
=======================
with this package, if you have:
str: vstring;
you could do:
str:=(0,"");
or
str:=convert("");
It's a bit longer, but it helps!
Borja TORON
Just an ADA user...
next reply other threads:[~1992-04-24 20:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-04-24 20:24 Borja TORON ANTONS [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-04-29 13:55 Oh, no! Ada-strings psinntp!vitro.com!v7.vitro.com!vaxs09
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox