Re: Debugging problems
Re: Debugging problems
- Subject: Re: Debugging problems
- From: Michael Mulligan <email@hidden>
- Date: Mon, 28 Mar 2005 17:15:22 -0500
On Mar 28, 2005, at 5:01 PM, Ondra Cada wrote:
Hmmm... quite strange. Happen you perhaps use -O3 or something similar? That would render the line numbers somewhat unreliable :)
I was just running with the standard "Development" build setting.
Presumed you've found a block of code which, if present, definitely causes an error, and, if commented out, the error (so far) never ever occurred, it might be reasonable to post the block here: who knows, perhaps there's a bug there after all, and somebody would notice. Or, perhaps, there's a bug in Cocoa caused by the very code, and somebody might be forewarned/forearmed :)
Here it is, sorry if it's a little messy...I kept adding/removing things to see if it ever made a difference (this was a method in a category on NSString):
=================
//removes leading and trailing whitespace from inString as well as squeezes runs of spaces (multiples spaces->one space) within inString
-(NSString *)removeExcessiveWhitespace
{
nil || [self length]==0)
return @"";
//------the easy way out{
return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//------}.......below this is the mysterious crasher, extraneous NSLogs removed....
NSFileHandle *handle;
NSString *result;
//the task to be run is: /bin/bash -c echo "quoteEscaped(tempString)" | tr -s '[:space:]'
NSTask *shell=[[NSTask alloc] init];
NSPipe *sopipe=[[NSPipe alloc] init];
[shell setLaunchPath:@"/bin/bash"];
NSMutableString *tempString=[self mutableCopy];
[tempString replaceOccurrencesOfString:@"\"" withString:@"\\\"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [tempString length])]; //escape quotes
nil)
return @"";
[shell setArguments:
[NSArray arrayWithObjects:
@"-c",
[NSString stringWithFormat:@"echo \"%@\" | tr -s '[:space:]'",tempString],
nil
]
];
[shell setStandardOutput:sopipe];
handle=[sopipe fileHandleForReading];
[shell launch];
result=[[NSString alloc] initWithData:[handle readDataToEndOfFile] encoding:NSASCIIStringEncoding]; // convert NSData -> NSString
[tempString release];
[sopipe release];
[shell release];
[result autorelease];
return [result stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
=================
Not *exactly* what you want, but seeing you use the heavy artillery of an NSTask for this... well, you know there's a method stringByTrimmingCharactersInSet:, don't you? :)
I do, but I simply wanted to turn runs of spaces into one rather than eliminating them entirely (and tr -s makes this an easy task and required no extra coding on my part).
-Mike
__________
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
__________
_______________________________________________
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