For Programmers: Free Programming Magazines  


Home > Archive > Smalltalk > April 2007 > (VWST) String includes: compare failure









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author (VWST) String includes: compare failure
dragoncity@impulse.net.au

2007-04-14, 10:11 pm

Hi,
I have a small email processing program that is trying to check
incoming email header addresses eg: fred@something.net
against a list I have of 'friends' on a file. ( exported from my eMail
program in plain text).

I have tested the comparision code using a workspace program and it
works as I expect.

However when I try to use the same code comparing against a email
address read from a POP3 server,the code allways fails to
compare properly ie: always fails even tho I know that the incoming
email address being checked is correct - -its my own !!

I can only assume that a 'string' from POP3 is not really a
string ???

ON inspection the 'strings' in the collection are type
ISO8859LiString, the POP3 strings are type ByteString -- is this the
problem?

So why does the includes: work in my workspace but fails within a
program ?

========================================
===================

======== example Transcript :

jimbo@impulse.net.au|20
thingo1@impulse.net.au|22
brett s hallett <dragoncity@impulse.net.au>|43
thingo11@impulse.net.au|23
thingo4@impulse.net.au|22
thingo2@impulse.net.au|22
thingo3@impulse.net.au|22

Find a entry :brett s hallett <dragoncity@impulse.net.au>|43
Found

============== end example ws ====================

The following code is an extraction from my program

The line :
( eMailAddresses includes: (item eAddress) )

searches orderedcollection eMailAddesses for the POP3 sourced
eAddress which is displayed in a Dataset List.

==============================
btnSetDeletes
" set All rows to DELETE , except those in current email adresses
file

Note: this routine removes the entries out of the eMailList Dataset
List, does the processing,
and puts the list back into eMailList - appears Datasets dont like
updating in place! "

| aList |

Trace ifTrue: [self Status: 'SetDeletes Pressed '].

connectFlag
ifFalse: [Dialog warn: 'no eMail Connection '. ^false.].

self loadEmailAddresses. "load the current mail programs email
addresses into a collection "
Trace ifTrue: [self Status: 'Loaded eMail addreses file into
Collection'].

aList := eMailList list.

aList do:
[:item |
Transcript show: '**setdeletes ** '; show: (item eAddress); show:
' |'; show: item size printString; cr.

( eMailAddresses includes: (item eAddress) )
ifTrue: [Transcript cr; show: ' Found '. item eDelTick
false.]
ifFalse: [Transcript cr; show: ' NotFound '. item eDelTick
true. ] .

].

self eMailList list: aList.
^self
========================================
=========
--
Brett S Hallett
dragoncity@impulse.net.au

Bruce Samuelson

2007-04-14, 10:11 pm

I don't think your problem is comparing instances of ISO8859L1String and
ByteString. Contrary to many comparison methods that require that the
two objects be of the same class or species, your two string classes
need not be the same. For example, try this:

ISO8859L1String new = ByteString new "returns true, at least in VW 7.3"

Perhaps the problem is with the way you mark items for deletion:

(eMailAddresses includes: item eAddress)
ifTrue: [Transcript cr; show: ' Found '. item eDelTick false]
ifFalse: [Transcript cr; show: ' NotFound '. item eDelTick true]

item eDelTick true "Calls the #true method; there's no such method
in standard Smalltalk. How did you define it?"

item eDelTick: true "Try this instead--define an #eDelTick: method
and call it with true as an argument."

Have you used the VisualWorks token explainer? In your browser window,

- Highlight true, i.e., drag the mouse over the four letters <t r u e>.
- Invoke the right click menu 'explain'.

In your code, it should say something like this: #true is a message
selector which is defined in 1 class.

If you do the same in the code I suggest, it should say this: 'true' is
a constant. It is the only instance of True and is the receiver of many
control messages.

dragoncity@impulse.net.au wrote:
> Hi,
> I have a small email processing program that is trying to check
> incoming email header addresses eg: fred@something.net
> against a list I have of 'friends' on a file. ( exported from my eMail
> program in plain text).
>
> I have tested the comparision code using a workspace program and it
> works as I expect.
>
> However when I try to use the same code comparing against a email
> address read from a POP3 server,the code allways fails to
> compare properly ie: always fails even tho I know that the incoming
> email address being checked is correct - -its my own !!
>
> I can only assume that a 'string' from POP3 is not really a
> string ???
>
> ON inspection the 'strings' in the collection are type
> ISO8859LiString, the POP3 strings are type ByteString -- is this the
> problem?
>
> So why does the includes: work in my workspace but fails within a
> program ?
>
> ========================================
===================
>
> ======== example Transcript :
>
> jimbo@impulse.net.au|20
> thingo1@impulse.net.au|22
> brett s hallett <dragoncity@impulse.net.au>|43
> thingo11@impulse.net.au|23
> thingo4@impulse.net.au|22
> thingo2@impulse.net.au|22
> thingo3@impulse.net.au|22
>
> Find a entry :brett s hallett <dragoncity@impulse.net.au>|43
> Found
>
> ============== end example ws ====================
>
> The following code is an extraction from my program
>
> The line :
> ( eMailAddresses includes: (item eAddress) )
>
> searches orderedcollection eMailAddesses for the POP3 sourced
> eAddress which is displayed in a Dataset List.
>
> ==============================
> btnSetDeletes
> " set All rows to DELETE , except those in current email adresses
> file
>
> Note: this routine removes the entries out of the eMailList Dataset
> List, does the processing,
> and puts the list back into eMailList - appears Datasets dont like
> updating in place! "
>
> | aList |
>
> Trace ifTrue: [self Status: 'SetDeletes Pressed '].
>
> connectFlag
> ifFalse: [Dialog warn: 'no eMail Connection '. ^false.].
>
> self loadEmailAddresses. "load the current mail programs email
> addresses into a collection "
> Trace ifTrue: [self Status: 'Loaded eMail addreses file into
> Collection'].
>
> aList := eMailList list.
>
> aList do:
> [:item |
> Transcript show: '**setdeletes ** '; show: (item eAddress); show:
> ' |'; show: item size printString; cr.
>
> ( eMailAddresses includes: (item eAddress) )
> ifTrue: [Transcript cr; show: ' Found '. item eDelTick
> false.]
> ifFalse: [Transcript cr; show: ' NotFound '. item eDelTick
> true. ] .
>
> ].
>
> self eMailList list: aList.
> ^self
> ========================================
=========
> --
> Brett S Hallett
> dragoncity@impulse.net.au
>

dragoncity@impulse.net.au

2007-04-16, 7:08 pm

Hi Bruce,

Thanks for your reply.

> If you do the same in the code I suggest, it should say this: 'true' is
> a constant. It is the only instance of True and is the receiver of many
> control messages.


My code says the same :-)
==========
( eMailAddresses includes: (item eAddress) )

I'm quite sure that this line of code is failing, because when I click
to execute btnSelDeletes, they are all
ticked 'true' and none of the email address in MailAddresses are
found.

I have inspected both eMailAddresses and (item eAdresss) and they both
display the correct text, but (item eAddress) is never found.
====================================

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com