1. Tsunami wrappers

Hello all,

'Basic language coders may be interested too!'

If you use Tsunami for Euphoria wrappers I have good news, thanks to
Tommy Carlier for taking his time to tweak (for speed) most of the
following routines that are located near the bottom of trm_eu.ew.

These routines are really fast and allow you to use padded or delimited 
record data.

Please make sure your version of the wrapper is current before update

-- Current Version: 3.5.6.9
-- January 11, 2004

Simply copy over the old routines. There are two new routines here,
they are trm_left and trm_right. 'code to follow below'

btw, complete documentation for the wrappers use of tsunami will be free
and finished this week. Registration of tsunami's trmpro version will allow
you access to the tsunami technical support, there I or Ron Austin can help
answer any questions regarding the record manager.

register tsunami at www.trm-ug.com


code:

global function trm_ltrim(sequence s)
    -- left trim 'white space'
    integer i,len
    len=length(s)
    i=1
    while i<=len and s[i]=32 do 
       i+=1 
    end while
    return s[i..len]
end function

global function trm_rtrim(sequence s)
  -- right trim 'white space'
  integer i
  i=length(s)
  while i and s[i]=32 do 
     i-= 1 
  end while
  return s[1..i]
end function

global function trm_trim(sequence s)
  -- trim 'white space' from both ends of string s
  integer i,j,len
  len=length(s)
  i=1
  while i<=len and s[i]=32 do 
     i+=1 
  end while
  j=len
  while j>=i and s[j]=32 do 
     j-= 1 
  end while
    return s[i..j]
end function         

global function trm_mid(sequence s, integer start, integer len)
   return s[start..start+len]
end function

global function trm_left(sequence s, integer len)
    return s[1..len]
end function

global function trm_right(sequence s, integer len)
 integer slen
    slen = length(s)
    return s[slen-len..slen]
end function

global function trm_abs(atom a)
   if a < 0 then
       return -a
   else
       return a
   end if
end function

-- rpad returns string s with a spaces appended to right
global function trm_rPad(object s, integer a)
  integer len
  len=length(s)
  if len >= a then
     return s
  end if
  return s & repeat(32, a - len)
end function

-- lpad returns string s with a spaces prepended on the left
global function trm_lPad(object s, integer a)
  integer len
  len=length(s)
  if len >= a then
     return s
  end if
  return repeat(32, a - len) & s
end function

global function trm_Pack(sequence s, integer x)
  integer len, index
  sequence str, substr
  len = length(s[1]) + 1 
  for i = 2 to length(s) do
      len += length(s[i]) + 1
  end for
  str = repeat(x, len) 
  index = 1
  for i = 1 to length(s) do
      substr = s[i]
      len = length(substr)
      str[index..index + len - 1] = substr
      index += len + 1
  end for
  return str
end function

global function trm_unPack(sequence s, integer x)
integer start
sequence dseq
   dseq={}
   start = 1
   for i = 1 to length(s) do
       if s[i] = x then
          dseq = append(dseq, s[start..i-1])
          start = i+1
       end if
   end for
return dseq
end function

:end code

Euman

new topic     » topic index » view message » categorize

2. Re: Tsunami wrappers

Euman,

for a number of years I have been pushing the following alternatives, only
slightly faster, but much more elegant:


global function ltrim(sequence s)
    integer n

    n = length(s)
    for i = 1 to n do
        if s[i] != 32 then return s[i..n] end if
    end for
    return {}
end function

global function rtrim(sequence s)
    for i = length(s) to 1 by -1 do
        if s[i] != 32 then return s[1..i] end if
    end for
    return {}
end function

global function trim(sequence s)
    integer m,n

    m = 0
    n = length(s)
    for i = 1 to n do
        if s[i] != 32 then
            m = i
            exit
        end if
    end for
    if m then
        for i = n to m by -1 do
            if s[i] != 32 then return s[m..i] end if
        end for
    end if
    return {}
end function


----- Original Message ----- 
From: "Euman" <euman at bellsouth.net>
To: <EUforum at topica.com>
Sent: 20 January 2004 6:56 AM
Subject: Tsunami wrappers


>
>
> Hello all,
>
> 'Basic language coders may be interested too!'
>
> If you use Tsunami for Euphoria wrappers I have good news, thanks to
> Tommy Carlier for taking his time to tweak (for speed) most of the
> following routines that are located near the bottom of trm_eu.ew.
>
> These routines are really fast and allow you to use padded or delimited
> record data.
>
> Please make sure your version of the wrapper is current before update
>
> -- Current Version: 3.5.6.9
> -- January 11, 2004
>
> Simply copy over the old routines. There are two new routines here,
> they are trm_left and trm_right. 'code to follow below'
>
> btw, complete documentation for the wrappers use of tsunami will be free
> and finished this week. Registration of tsunami's trmpro version will
allow
> you access to the tsunami technical support, there I or Ron Austin can
help
> answer any questions regarding the record manager.
>
> register tsunami at www.trm-ug.com
>
>
> code:
>
> global function trm_ltrim(sequence s)
>     -- left trim 'white space'
>     integer i,len
>     len=length(s)
>     i=1
>     while i<=len and s[i]=32 do
>        i+=1
>     end while
>     return s[i..len]
> end function
>
> global function trm_rtrim(sequence s)
>   -- right trim 'white space'
>   integer i
>   i=length(s)
>   while i and s[i]=32 do
>      i-= 1
>   end while
>   return s[1..i]
> end function
>
> global function trm_trim(sequence s)
>   -- trim 'white space' from both ends of string s
>   integer i,j,len
>   len=length(s)
>   i=1
>   while i<=len and s[i]=32 do
>      i+=1
>   end while
>   j=len
>   while j>=i and s[j]=32 do
>      j-= 1
>   end while
>     return s[i..j]
> end function
>
> global function trm_mid(sequence s, integer start, integer len)
>    return s[start..start+len]
> end function
>
> global function trm_left(sequence s, integer len)
>     return s[1..len]
> end function
>
> global function trm_right(sequence s, integer len)
>  integer slen
>     slen = length(s)
>     return s[slen-len..slen]
> end function
>
> global function trm_abs(atom a)
>    if a < 0 then
>        return -a
>    else
>        return a
>    end if
> end function
>
> -- rpad returns string s with a spaces appended to right
> global function trm_rPad(object s, integer a)
>   integer len
>   len=length(s)
>   if len >= a then
>      return s
>   end if
>   return s & repeat(32, a - len)
> end function
>
> -- lpad returns string s with a spaces prepended on the left
> global function trm_lPad(object s, integer a)
>   integer len
>   len=length(s)
>   if len >= a then
>      return s
>   end if
>   return repeat(32, a - len) & s
> end function
>
> global function trm_Pack(sequence s, integer x)
>   integer len, index
>   sequence str, substr
>   len = length(s[1]) + 1
>   for i = 2 to length(s) do
>       len += length(s[i]) + 1
>   end for
>   str = repeat(x, len)
>   index = 1
>   for i = 1 to length(s) do
>       substr = s[i]
>       len = length(substr)
>       str[index..index + len - 1] = substr
>       index += len + 1
>   end for
<snip>

>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu