Question about STRINGs...

Phil Malin <[email protected]> Tue, 31 May 2005 16:46:04 +1000
Newsgroups gmane.comp.lang.eiffel.smalleiffel
Message-ID <[email protected]>
Hi there.

I've been writing some network code (using my own network library I 
wrote ages ago) and have come across a bit of an annoyance (more than 
likely brought about by my own lack of knowledge).  In my code I 
currently use an array of characters as a read buffer rather than a 
STRING because when I originally wrote it I wasn't sure how STRINGs 
would handle arbitrary CHARACTERs (like nulls, etc.).  From looking at 
the STRING code it seems as though it'd be ok because it uses a 
separately defined 'count' to state the size rather than a trailing '\0' 
as in C.  Is this correct?

If this is the case, what would be the best way of copying arbitrary 
data in a C array into a STRING (since a lot of the time the user will 
be wanting the result as a STRING).  The only routines in STRING are 
'from_external' and 'from_external_copy', which seem to copy until a 
'\0' is hit (which won't be of help to me here).

The easy approach is to simply create a STRING with a certain capacity 
and then loop through the buffer of read data appending each character 
at a time (which is pretty inefficient).

Is there any possibility to add a creation routine to STRING such as

    copy_external_sequence(ptr : POINTER;size : INTEGER)


or something so one can copy some arbitrary data pointed to by 'ptr' in 
an efficient way (by having it use bcopy/memcpy/etc.)?

Thanks in advance for any pointers (pardon the pun ;-) ).

Cheers.

Phil.
phil.malin.vcf (text/x-vcard, 288 B)
begin:vcard
fn:Phil Malin
n:Malin;Phil
org:iP3 Systems;R&D
adr:South Melbourne;;Level 5, 150 Albert Road,;Melbourne;Victoria;3205;Australia
email;internet:[email protected]
title:Development Team Leader
tel;work:+613-9682-7551
url:http://www.ip3systems.com
version:2.1
end:vcard