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

* Re: Optimising string handling in application
  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
  2 siblings, 0 replies; 20+ messages in thread
From: Jeffrey Carter @ 2003-04-01 18:52 UTC (permalink / raw)


Frode Tenneboe wrote:
> 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?

Several.

1. Lose the Hungarian notation.

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

2. Pass slices and lose the _Length parameters. Then you can use 
attributes in here. Make this a function returning String.

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

3. Use another call to Index to find the ';'.

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

4. Replace all this with

return Msg (1 .. Delete_Start - 1) & Callsign &
        Msg (Delete_Stop + 1 .. Msg'Last);

> 
>    end Replace_Callsign_In_Msg;

If you really need the fixed-length subtype, you can grab the length of 
this return value and store it in your length value, then store the 
String into your variable:

declare
    Var_Size : constant String :=
       Replace_Callsign_In_Msg (Msg, Callsign);
begin
    Length := Var_Size'Length;
    Msg (1 .. Var_Size'Length) := Var_Size;
end;

-- 
Jeff Carter
"You couldn't catch clap in a brothel, silly English K...niggets."
Monty Python & the Holy Grail




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

* Re: Optimising string handling in application
  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
  2 siblings, 0 replies; 20+ messages in thread
From: Steve @ 2003-04-02  3:17 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1947 bytes --]

A few suggestions:
  Instead of looping to find the end of the string, use the "Index" function
from Ada.Strings.Fixed on a slice of the original string instead of your own
loop.  Something like:

  Delete_Stop := Ada.Strings.Fixed.Index( Source => Msg( Delete_Start ..
Msg_Length ) ...
  If Delete_Stop = 0 Then
    Delete_Stop := Msg_Length;
  Else
    Delete_stop := Delete_Stop - 1;
  End If;

  Then use Ada.Strings.Fixed.Replace_Slice to replace the string between
Delete_Start and Delete_Stop.

  If I were writing the code I would probably use Ada.Strings.Bounded
instead of passing around fixed sized strings separate from the length, then
use the corresponding Index and Replace_Slice functions from
Ada.Strings.Bounded.  Using bounded strings has the advantage that the
library does the work of maintaining string lengths for you.

  That is:
  Package Callsign_String_Package is
    new Ada.Strings.Bounded.Generic_Bounded_Length( C_Max_Msg_Size );

  subtype T_Msg_Data_Str is Callsign_String_Package.Bounded_String;

  etc

Steve
(The Duck)

BTW: I find your naming conventions awkward... personal preferance.


"Frode Tenneboe" <ft@alne.edh.ericsson.se> wrote in message
news:1049198066.356477@edh3...
>
> 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?
>
[snip]
>
>  -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

* Re: Optimising string handling in application
  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
  2 siblings, 1 reply; 20+ messages in thread
From: tmoran @ 2003-04-02  4:10 UTC (permalink / raw)


Does this (with its questions answered) do what you want?

  function Replace_Callsign_In_Msg(Msg          : in String;
                                   New_Callsign : in String) return String is
    Eq : constant Positive := Ada.Strings.Fixed.Index(Msg, "ME001=") + 5;
    Semi : Natural;
  begin
    if Eq = 5 then
      -- "ME001=" not present, what to do?
    end if;
    Semi := Ada.Strings.Fixed(Msg(Eq, ";");
    if Semi = 0 then
      -- following ';' missing, what to do?
    end if;
    return Msg(Msg'first .. Eq) & New_Callsign & Msg(Semi .. Msg'last);
  end Replace_Callsign_In_Msg;



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

* Re: Optimising string handling in application
  2003-04-02  4:10 ` tmoran
@ 2003-04-02  7:15   ` Frode Tenneboe
  2003-04-02 18:23     ` tmoran
                       ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Frode Tenneboe @ 2003-04-02  7:15 UTC (permalink / raw)


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



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

* Re: Optimising string handling in application
  2003-04-02  7:15   ` Frode Tenneboe
@ 2003-04-02 18:23     ` tmoran
  2003-04-04 10:13       ` Frode Tenneboe
  2003-04-02 19:03     ` tmoran
  2003-04-05  0:08     ` Jeffrey Carter
  2 siblings, 1 reply; 20+ messages in thread
From: tmoran @ 2003-04-02 18:23 UTC (permalink / raw)


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

  You don't need the temporary (Dummy) string.  Just calculate the
length first,
      Msg_Length := Msg_Length
                    - (Start_Next_String-Stop_First_String-1)
                    + Callsign_Length;
then set Msg(1 .. Msg_Length) to the concatenation.

> since I'm calling this all over the place and need the fixed length types
>...
>     (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
  Ah, so your abstract type is not "String", but rather a home-grown
version of Bounded_String that passes the current length as a separate
variable.  Let me guess where this code originated...



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

* Re: Optimising string handling in application
  2003-04-02  7:15   ` Frode Tenneboe
  2003-04-02 18:23     ` tmoran
@ 2003-04-02 19:03     ` tmoran
  2003-04-04 10:44       ` Frode Tenneboe
  2003-04-05  0:08     ` Jeffrey Carter
  2 siblings, 1 reply; 20+ messages in thread
From: tmoran @ 2003-04-02 19:03 UTC (permalink / raw)


> 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?
  Luckily, you needn't assume anything.  There are specific rules about
the value of 'first.  If those rules, in some particular case, don't
*guarantee* that 'first=1, then you can't "assume" that 'first=1.



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

* Re: Optimising string handling in application
  2003-04-02 18:23     ` tmoran
@ 2003-04-04 10:13       ` Frode Tenneboe
  2003-04-04 13:26         ` Preben Randhol
                           ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Frode Tenneboe @ 2003-04-04 10:13 UTC (permalink / raw)


tmoran@acm.org wrote:

>   You don't need the temporary (Dummy) string.  Just calculate the
> length first,
>       Msg_Length := Msg_Length
>                     - (Start_Next_String-Stop_First_String-1)
>                     + Callsign_Length;
> then set Msg(1 .. Msg_Length) to the concatenation.

Well, yes. Except that you now have overwritten the length of the orignal
string, but that's easily fixed. Thanks.

However, sometimes I miss the expressionness of perl:

s/([^;]*;ME001=)([^;]*)(;[^;]*)/$1$callsign$3/;

;-)

>   Ah, so your abstract type is not "String", but rather a home-grown
> version of Bounded_String that passes the current length as a separate
> variable.  Let me guess where this code originated...

:)

 -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

* Re: Optimising string handling in application
  2003-04-02 19:03     ` tmoran
@ 2003-04-04 10:44       ` Frode Tenneboe
  2003-04-05  3:28         ` tmoran
  0 siblings, 1 reply; 20+ messages in thread
From: Frode Tenneboe @ 2003-04-04 10:44 UTC (permalink / raw)


tmoran@acm.org wrote:
>> 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?
>   Luckily, you needn't assume anything.  There are specific rules about
> the value of 'first.  If those rules, in some particular case, don't
> *guarantee* that 'first=1, then you can't "assume" that 'first=1.

Bad phrasing of the question. I looked in RM 4.3.3 (Array aggregates)
for an answer, but I'm still not absolutely certain that my perception
of strings (or other array-types for that matter) is correct.

For subprograms which can accept unconstrained arrys (eg. String)
it is necessary to use 'First and friends. Is this the only case where
it is not guaranteed that 'First = 1?

Example:

   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

If I were to call this with:

   Replace_Callsign_In_Msg
     (Msg             => Loc_Insert_Msg.Data(2..Loc_Insert_Msg.Data'Last),
      Msg_Length      => Loc_Insert_Msg.Data_Length-1,
      Callsign        => Individual_Callsigns.Callsigns(I).Callsign,
      Callsign_Length => Individual_Callsigns.Callsigns(I).Length);

Can I assume that 'First of Msg inside Replace_Callsign_In_Msg =1?

Where in RM is this dealt with?

Regards,
 -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

* Re: Optimising string handling in application
  2003-04-04 10:13       ` Frode Tenneboe
@ 2003-04-04 13:26         ` Preben Randhol
  2003-04-04 14:42           ` Frode Tenneboe
  2003-04-04 14:08         ` Frank J. Lhota
  2003-04-04 17:43         ` tmoran
  2 siblings, 1 reply; 20+ messages in thread
From: Preben Randhol @ 2003-04-04 13:26 UTC (permalink / raw)


Frode Tenneboe wrote:
> However, sometimes I miss the expressionness of perl:
> 
> s/([^;]*;ME001=)([^;]*)(;[^;]*)/$1$callsign$3/;
> 
> ;-)

Have you checked GNAT's regexp etc... capabilities?

Preben



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

* Re: Optimising string handling in application
  2003-04-04 10:13       ` Frode Tenneboe
  2003-04-04 13:26         ` Preben Randhol
@ 2003-04-04 14:08         ` Frank J. Lhota
  2003-04-04 15:26           ` Robert Spooner
  2003-04-04 17:43         ` tmoran
  2 siblings, 1 reply; 20+ messages in thread
From: Frank J. Lhota @ 2003-04-04 14:08 UTC (permalink / raw)


"Frode Tenneboe" <ft@alne.edh.ericsson.se> wrote in message
news:1049451208.932382@edh3...
> However, sometimes I miss the expressionness of perl:
>
> s/([^;]*;ME001=)([^;]*)(;[^;]*)/$1$callsign$3/;
>
> ;-)

Why does this remind me of APL?





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

* Re: Optimising string handling in application
  2003-04-04 13:26         ` Preben Randhol
@ 2003-04-04 14:42           ` Frode Tenneboe
  2003-04-04 21:48             ` Warren W. Gay VE3WWG
  0 siblings, 1 reply; 20+ messages in thread
From: Frode Tenneboe @ 2003-04-04 14:42 UTC (permalink / raw)


Preben Randhol <randhol+news@pvv.org> wrote:

> Have you checked GNAT's regexp etc... capabilities?

AFAIK: It does not have any support for substitution.

 -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

* Re: Optimising string handling in application
  2003-04-04 14:08         ` Frank J. Lhota
@ 2003-04-04 15:26           ` Robert Spooner
  2003-04-04 21:49             ` Warren W. Gay VE3WWG
  0 siblings, 1 reply; 20+ messages in thread
From: Robert Spooner @ 2003-04-04 15:26 UTC (permalink / raw)
  To: Frank J. Lhota

Frank J. Lhota wrote:
> "Frode Tenneboe" <ft@alne.edh.ericsson.se> wrote in message
> news:1049451208.932382@edh3...
> 
>>However, sometimes I miss the expressionness of perl:
>>
>>s/([^;]*;ME001=)([^;]*)(;[^;]*)/$1$callsign$3/;
>>
>>;-)
> 
> 
> Why does this remind me of APL?
> 
> 
Because it looks like a write only language?

Bob
-- 
                             Robert L. Spooner
                      Registered Professional Engineer
                        Associate Research Engineer
                   Intelligent Control Systems Department

          Applied Research Laboratory        Phone: (814) 863-4120
          The Pennsylvania State University  FAX:   (814) 863-7841
          P. O. Box 30
          State College, PA 16804-0030       rls19@psu.edu




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

* Re: Optimising string handling in application
  2003-04-04 10:13       ` Frode Tenneboe
  2003-04-04 13:26         ` Preben Randhol
  2003-04-04 14:08         ` Frank J. Lhota
@ 2003-04-04 17:43         ` tmoran
  2003-04-04 21:42           ` Frode Tennebø
  2 siblings, 1 reply; 20+ messages in thread
From: tmoran @ 2003-04-04 17:43 UTC (permalink / raw)


> However, sometimes I miss the expressionness of perl:
>
> s/([^;]*;ME001=)([^;]*)(;[^;]*)/$1$callsign$3/;

What does that do if "ME001=" or the ';' aren't present?

What does "expressionness" mean?  Does:

function Replace_Callsign_In_Message(M, C : String) return String is
  use Ada.Strings.Fixed;
  Eq : constant Positive := Index(M, "ME001=")+5;
begin
  return M(M'first .. Eq) & C & M(Index(M(Eq .. M'last),";') .. M'last);
end Replace_Callsign_In_Message;

have more or less of it than:

function Replace_Callsign_In_Message(Msg, New_Callsign : String) return String is
  use Ada.Strings.Fixed;
  Eq : constant Positive := Index(Msg, "ME001=")+5;
  Semi : Natural;
begin
  if Eq = 5 then raise Constraint_Error;end if; -- missing "ME001="
  Semi := Index(Msg, ";");
  if Semi = 0 then raise Constraint_Error;end if; -- missing ";"
  return Msg(Msg'first .. Eq)
         & New_Callsign
         & Msg(Semi .. Msg'last);
end Replace_Callsign_In_Message;



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

* Re: Optimising string handling in application
  2003-04-04 17:43         ` tmoran
@ 2003-04-04 21:42           ` Frode Tennebø
  0 siblings, 0 replies; 20+ messages in thread
From: Frode Tennebø @ 2003-04-04 21:42 UTC (permalink / raw)


On Friday 04 April 2003 19:43 tmoran@acm.org wrote:

>> However, sometimes I miss the expressionness of perl:
>>
>> s/([^;]*;ME001=)([^;]*)(;[^;]*)/$1$callsign$3/;
> 
> What does that do if "ME001=" or the ';' aren't present?
> 
> What does "expressionness" mean?  Does:

You missed to quote the ";-)". Apart from some trouble spelling, I was
being ironic. :)

 -Frode

PS: Very nice implementations BTW.

-- 
^ Frode Tenneb� | email: frode@tennebo.com | Frode@IRC ^
|  with Standard.Disclaimer; use Standard.Disclaimer;  |



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

* Re: Optimising string handling in application
  2003-04-04 14:42           ` Frode Tenneboe
@ 2003-04-04 21:48             ` Warren W. Gay VE3WWG
  2003-04-05  7:24               ` Pascal Obry
  0 siblings, 1 reply; 20+ messages in thread
From: Warren W. Gay VE3WWG @ 2003-04-04 21:48 UTC (permalink / raw)


Frode Tenneboe wrote:
> Preben Randhol <randhol+news@pvv.org> wrote:
>>Have you checked GNAT's regexp etc... capabilities?
> AFAIK: It does not have any support for substitution.
> 
>  -Frode

I believe the match arrays give you enough position
information that it would be trivial to code the
substitution part.

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




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

* Re: Optimising string handling in application
  2003-04-04 15:26           ` Robert Spooner
@ 2003-04-04 21:49             ` Warren W. Gay VE3WWG
  0 siblings, 0 replies; 20+ messages in thread
From: Warren W. Gay VE3WWG @ 2003-04-04 21:49 UTC (permalink / raw)


Robert Spooner wrote:
> Frank J. Lhota wrote:
> 
>> "Frode Tenneboe" <ft@alne.edh.ericsson.se> wrote in message
>> news:1049451208.932382@edh3...
>>
>>> However, sometimes I miss the expressionness of perl:
>>>
>>> s/([^;]*;ME001=)([^;]*)(;[^;]*)/$1$callsign$3/;
>>>
>>> ;-)
>>
>> Why does this remind me of APL?
>>
> Because it looks like a write only language?
> 
> Bob

Naw, it is APL, but he forgot to change to the APL
"type ball" (font). ;-)

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




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

* Re: Optimising string handling in application
  2003-04-02  7:15   ` Frode Tenneboe
  2003-04-02 18:23     ` tmoran
  2003-04-02 19:03     ` tmoran
@ 2003-04-05  0:08     ` Jeffrey Carter
  2 siblings, 0 replies; 20+ messages in thread
From: Jeffrey Carter @ 2003-04-05  0:08 UTC (permalink / raw)


Frode Tenneboe wrote:
> 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?

Objects of your subtype always have 'First = 1. Parameters of type 
String may have 'First = any value in Positive.

-- 
Jeff Carter
"English bed-wetting types."
Monty Python & the Holy Grail




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

* Re: Optimising string handling in application
  2003-04-04 10:44       ` Frode Tenneboe
@ 2003-04-05  3:28         ` tmoran
  0 siblings, 0 replies; 20+ messages in thread
From: tmoran @ 2003-04-05  3:28 UTC (permalink / raw)


>   Replace_Callsign_In_Msg
>     (Msg             => Loc_Insert_Msg.Data(2..Loc_Insert_Msg.Data'Last),
>Can I assume that 'First of Msg inside Replace_Callsign_In_Msg =1?

  It depends on whether the formal parameter is constrained or
unconstrained.  This program prints " 13 3"

with ada.text_io;
procedure testp is
  subtype teens is integer range 13 .. 19;
  subtype constrained is string(teens);
  x : string(3 .. 9);
  procedure p(c : constrained; u : string) is
  begin
    ada.text_io.put_line(integer'image(c'first) & integer'image(u'first));
  end p;
begin
  p(x,x);
end testp;



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

* Re: Optimising string handling in application
  2003-04-04 21:48             ` Warren W. Gay VE3WWG
@ 2003-04-05  7:24               ` Pascal Obry
  0 siblings, 0 replies; 20+ messages in thread
From: Pascal Obry @ 2003-04-05  7:24 UTC (permalink / raw)



"Warren W. Gay VE3WWG" <ve3wwg@cogeco.ca> writes:

> Frode Tenneboe wrote:
> > Preben Randhol <randhol+news@pvv.org> wrote:
> >>Have you checked GNAT's regexp etc... capabilities?
> > AFAIK: It does not have any support for substitution.
> >  -Frode
> 
> I believe the match arrays give you enough position
> information that it would be trivial to code the
> substitution part.

Exactly, using GNAT.Regpat it will not be difficult to implement
the expression posted.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ 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