• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Re: NetSocket and parse line by line
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: NetSocket and parse line by line


  • Subject: Re: Re: NetSocket and parse line by line
  • From: "Hell's KItchen Hell's KItchen" <email@hidden>
  • Date: Sun, 26 Nov 2006 02:10:14 +0100

Well thank you very much Phil,
with your help I've wrote the function again.
This is the result for archive and future uses:

- (void)netsocket:(NetSocket*)inNetSocket dataAvailable:(unsigned)inAmount {

	NSString *str = [[[NSString alloc] initWithData: [inNetSocket
readData] encoding: NSASCIIStringEncoding]
autorelease];//NSISOLatin1StringEncoding] autorelease];


NSRange range; if(!_string) _string = [[NSMutableString alloc] init];

[_string appendString:str];
do {
range = [_string rangeOfString:@"\r\n"]; // or whatever
if (range.location != NSNotFound) {
  NSString *line = [_string substringWithRange: NSMakeRange(0,range.location)];
//  if ([_string length] == 1) {
//	[_string release];
//	_string = [[NSMutableString alloc] init];
// } else {
   [_string deleteCharactersInRange:NSMakeRange(0,range.location+range.length)];
	//}

//	NSLog(@"[%d,%d]",[_string length],range.length);
  [self _preFetchRawData:line];
}
} while( range.location != NSNotFound);

}

2006/11/23, Philip Q <email@hidden>:
On 23/11/06, Hell's KItchen Hell's KItchen <email@hidden> wrote:
>         [_string appendString:str];
>         start = stop = cont = 0;
>         do {
>             range.location = stop;
>             range.length = 0;
>             [_string getLineStart:&start end:&stop contentsEnd:&cont
> forRange:range];
>
>                         int len = cont-start;
>             if(stop != cont && cont-start >= 0) {
>                 range.location = start;
>                 range.length = cont - start;
>                                 [self _fetchRawData: [_string substringWithRange:range]];
>             } else {
>
>                         }
>         }
>         while(stop != cont);


You seem to be using an awfully complicated way to get a single line, and send it to your _fetchRawData: method (at least, I think that's what you're doing).

Might I suggest that if you know that _string is only going to contain
data since the last newline (check the appropriate spec to find out
what that is), you only need to see if the newly appended string
contains that sequence, and if so, extact that range.

For example:
[_string appendString:str];
range = [_string rangeOfString:@"\r\n"] // or whatever
if (range.location != NSNotFound) {
    line = [_string substringWithRange:range];
    [_string deleteCharactersInRange:range];
    [_self fetchRawData:line];
}

You'll want to check to see if rangeOfString: includes the sequence
you're looking for in it's NSRange and modify it appropriately.
I don't have any experience with the IRC protocol, so this might be
totally useless if you were doing all that for a reason.

-Phil

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NetSocket and parse line by line (From: "Hell's KItchen Hell's KItchen" <email@hidden>)
 >Re: NetSocket and parse line by line (From: "Philip Q" <email@hidden>)

  • Prev by Date: Re: Repositioning an NSTextFieldCell?
  • Next by Date: App crashes at startup for Standard user accounts
  • Previous by thread: Re: NetSocket and parse line by line
  • Next by thread: NSWorkspace translation versus finder
  • Index(es):
    • Date
    • Thread