From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,789b3fa522bdcc2a,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-01 03:59:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!luth.se!erix.ericsson.se!erinews.ericsson.se!news.ericsson.se!not-for-mail From: Frode Tenneboe Newsgroups: comp.lang.ada Subject: Optimising string handling in application Date: Tue, 1 Apr 2003 11:54:41 +0000 (UTC) Organization: Ericsson AS Message-ID: <1049198066.356477@edh3> NNTP-Posting-Host: edh3.edh.ericsson.se Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: newstree.wise.edt.ericsson.se 1049198081 20423 193.180.212.12 (1 Apr 2003 11:54:41 GMT) X-Complaints-To: abuse@ericsson.se NNTP-Posting-Date: Tue, 1 Apr 2003 11:54:41 +0000 (UTC) User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (SunOS/5.8 (sun4u)) Cache-Post-Path: edh3!unknown@alne X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/) Xref: archiver1.google.com comp.lang.ada:35855 Date: 2003-04-01T11:54:41+00:00 List-Id: 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; |