Re: Objective-C BufferedReader
Re: Objective-C BufferedReader
- Subject: Re: Objective-C BufferedReader
- From: Jason Jobe <email@hidden>
- Date: Sat, 12 Feb 2005 17:56:06 -0500
What's wrong with NSFileHandle?
file:///Developer/ADC Reference Library/documentation/Cocoa/
Reference/Foundation/ObjC_classic/Classes/NSFileHandle.html
On Feb 12, 2005, at 5:39 PM, Hamish Allan wrote:
Hi,
I have as yet been unable to find anything written in Objective-C that
provides the functionality of Java's java.io.BufferedReader.
1) Does such a library object exist, and if so, where?
Assuming not, I thought I might try to implement it naively as below
(readLine hard-coded to stdin for pedagogical purposes). It works fine
for strings that are less than BUFFER_LENGTH characters long, but if
they are over, fgets() never returns. I know this is not really a
Cocoa question, but since I was asking (1) above, I thought I'd also
ask here:
2) What's wrong with the following code?
- (NSString *)readLineFromStdin
{
NSMutableString *ret = [NSMutableString
stringWithCapacity:BUFFER_LENGTH];
char buf[BUFFER_LENGTH + 1];
char *chars = fgets(buf, BUFFER_LENGTH, stdin);
if (chars != NULL)
{
char *endl = strchr(chars, '\n');
while (endl == NULL)
{
[ret appendString: [NSString stringWithCString:buf
length:BUFFER_LENGTH]];
endl = strchr(chars, '\n');
}
[ret appendString: [NSString stringWithCString:buf length:(endl -
buf)]];
}
return ret;
}
Many thanks,
Hamish
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
- jason
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden