comp.lang.ada
 help / color / mirror / Atom feed
* Optimising string handling in application
@ 2003-04-01 11:54 Frode Tenneboe
  2003-04-01 18:52 ` Jeffrey Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Frode Tenneboe @ 2003-04-01 11:54 UTC (permalink / raw)



I have a small-ish procedure which only purpose is to take a
formatted string (see example) and replace the callsign(s)
inside with another.

The strings look like:

"ME000=F012;ME001=AAA,BBB,CCC;ME002=FOO...."

I would like to replace "ME001=AAA,BBB,CCC" with "ME001=AAA". The
procedure below does just that. However, looking at the code, I don't
like the lumpyness (in lack of a better word). There must be a
more elegant way of doing this? Any ideas?


   C_Max_Msg_Size : constant Integer := 1450;
   C_Max_Msg_Callsign_Length : constant Integer := 20;

   subtype T_Msg_Data_Str is String(1..C_Max_Msg_Size);
   subtype T_Msg_Callsign is String(1..C_Max_Msg_Callsign_Length);

   procedure Replace_Callsign_In_Msg
     (Msg             : in out Dpu_Loc_Messages.T_Msg_Data_Str;
      Msg_Length      : in out T_Integer_32;
      Callsign        : in     Dpu_Loc_Messages.T_Msg_Callsign;
      Callsign_Length : in     Positive) is

      Data           : Dpu_Loc_Messages.T_Msg_Data_Str;
      Data_Length    : Positive;
      Delete_Start   : Positive;
      Delete_Stop    : Natural;

   begin

      -- Prepare data string for new ME001
      Delete_Start := Ada.Strings.Fixed.Index
        (Source => Msg(1..Msg_Length),
         Pattern => "ME001=") + 6;
      for I in Delete_Start .. Msg_Length loop
         if Msg(I) = ';' then
            Delete_Stop := I - 1;
            exit;
         end if;
      end loop;

      -- delete all callsigns
      declare
         Dummy : String := Ada.Strings.Fixed.Delete
           (Source  => Msg(1..Msg_Length),
            From    => Delete_Start,
            Through => Delete_Stop);
      begin
         Data_Length := Dummy'Length;
         Data(Data'First .. Data'First + Dummy'Length - 1) := Dummy;
      end;

      -- insert new callsign
      declare
         Dummy : String := Ada.Strings.Fixed.Insert
           (Source   => Data(Data'First .. Data_Length),
            Before   => Delete_Start,
            New_Item => Callsign(Callsign'First..Callsign'First + Callsign_Length -1));
      begin
         Data_Length := Dummy'Length;
         Msg(Msg'First .. Msg'First + Data_Length - 1) := Dummy;
      end;

   end Replace_Callsign_In_Msg;



 -Frode

-- 
^ Frode Tenneb�               | email: Frode.Tennebo@eto.ericsson.se ^
| Ericsson AS., N-1788 Halden | Phone: +47 67 25 09 39               |
| with Standard.Disclaimer; use Standard.Disclaimer;                 |



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2003-04-05  7:24 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-01 11:54 Optimising string handling in application Frode Tenneboe
2003-04-01 18:52 ` Jeffrey Carter
2003-04-02  3:17 ` Steve
2003-04-02  4:10 ` tmoran
2003-04-02  7:15   ` Frode Tenneboe
2003-04-02 18:23     ` tmoran
2003-04-04 10:13       ` Frode Tenneboe
2003-04-04 13:26         ` Preben Randhol
2003-04-04 14:42           ` Frode Tenneboe
2003-04-04 21:48             ` Warren W. Gay VE3WWG
2003-04-05  7:24               ` Pascal Obry
2003-04-04 14:08         ` Frank J. Lhota
2003-04-04 15:26           ` Robert Spooner
2003-04-04 21:49             ` Warren W. Gay VE3WWG
2003-04-04 17:43         ` tmoran
2003-04-04 21:42           ` Frode Tennebø
2003-04-02 19:03     ` tmoran
2003-04-04 10:44       ` Frode Tenneboe
2003-04-05  3:28         ` tmoran
2003-04-05  0:08     ` Jeffrey Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox