Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Oberon > Re: Weak formal...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 445 of 500
Post > Topic >>

Re: Weak formal methods ?

by "Xcriber51" <ken@[EMAIL PROTECTED] > Oct 29, 2007 at 07:43 AM

Hi

Don't know what pre- and post-conditions you want to assert for this
routine (whether it contains consecutive spaces? By the time you find that
you're already halfway into the routine), but here's what I came up with
(if I didn't misunderstand what you want as output). This I coded using
BlackBox:

PROCEDURE RemoveExtraSpaces*(VAR s, result: ARRAY OF CHAR);
    VAR i, k, pos: INTEGER;
BEGIN
    s := s+' ';
    i := 0; Strings.Find(s, ' ', i, pos);
    
    k := 0;
    
    WHILE pos # -1 DO
        IF pos-i > 1 THEN 
            WHILE i <= pos DO result[k] := s[i]; INC(k); INC(i) END ;
        END ;
        i := pos+1; Strings.Find(s, ' ', i, pos);
    END ;
    
    result[k] := 0X;

END RemoveExtraSpaces;

It only checks the difference between two constantly updated indeces, one
hunting for the next space while the other trailing it, and if their
difference is more than one, copies what is between them.

Hope it does the job.


-- Ken

--
Message posted using
http://www.talkaboutprogramming.com/group/comp.lang.oberon/
More information at http://www.talkaboutprogramming.com/faq.html
 




 4 Posts in Topic:
Weak formal methods ?
problems@[EMAIL PROTECTED  2007-10-28 20:35:38 
Re: Weak formal methods ?
CBFalconer <cbfalconer  2007-10-29 00:08:11 
Re: Weak formal methods ?
"Xcriber51" <  2007-10-29 07:43:00 
Re: Weak formal methods ?
"Xcriber51" <  2007-10-29 12:51:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 11:05:08 CDT 2008.