comp.lang.ada
 help / color / mirror / Atom feed
From: Frode Tenneboe <ft@alne.edh.ericsson.se>
Subject: Re: Optimising string handling in application
Date: Wed, 2 Apr 2003 07:15:52 +0000 (UTC)
Date: 2003-04-02T07:15:52+00:00	[thread overview]
Message-ID: <1049267738.39983@edh3> (raw)
In-Reply-To: mptia.297625$3D1.163591@sccrnsc01

tmoran@acm.org wrote:
> Does this (with its questions answered) do what you want?

Yes. Thank you. However, since I'm calling this all over the place
and need the fixed length types I have reintroduced them to put
the gritty stuff in one place:

   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

      Stop_First_String : constant Positive := Ada.Strings.Fixed.Index
        (Source => Msg(1 .. Msg_Length),
         Pattern => "ME001=") + 5;
      Start_Next_String : Positive;

   begin

      if Stop_First_String = 5 then -- "ME001=" not present
         raise Constraint_Error;
      end if;

      Start_Next_String := Ada.Strings.Fixed.Index
        (Source => Msg(Stop_First_String .. Msg_Length),
         Pattern => ";");
      if Start_Next_String = 0 then -- ";" not present
         raise Constraint_Error;
      end if;

      declare
         Dummy : constant String :=
           Msg (1 .. Stop_First_String) &
           Callsign(1 .. Callsign_Length) &
           Msg (Start_Next_String .. Msg_Length);
      begin
         Msg_Length := Dummy'Length;
         Msg (1 .. Msg_Length) := Dummy;
      end;

   end Replace_Callsign_In_Msg;


Better. Could probably be tuned more, but it's also more readable
now. Thanks all.

Follow-up question: Is it safe to asume that strings _allways_
start with 'First = 1 (provided the (sub)type starts with 1) except when 
passing slices where 'First = start_of_slice?


 -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;                 |



  reply	other threads:[~2003-04-02  7:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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