Re: Debugging problems
Re: Debugging problems
- Subject: Re: Debugging problems
- From: Shaun Wexler <email@hidden>
- Date: Mon, 28 Mar 2005 18:15:29 -0800
On Mar 28, 2005, at 2:43 PM, Ondra Cada wrote:
... well to be frank I would not call those 25-odd lines "no extra coding". If you want a pretty ugly inefficient but easy solution, what about, say
-(NSString *)removeExcessiveWhitespace {
NSString *s=[self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSArray *a;
while ([a=[s componentsSeparatedByString:@" "] count]>1) s=[a componentsJoinedByString:@" "];
return s;
}
Without rewriting it for you, Michael, maybe you can glean your solution from this method:
- (NSData *)dataWithParsedString:(NSString *)commandString
{
UInt32 length = [commandString length];
const char *inUTF8 = [commandString UTF8String];
NSMutableData *data = [[NSMutableData alloc] initWithLength:(length + 1)];
char *parsed = [data mutableBytes];
UInt32 u = 0, p = 0;
char c, lastc = 0x20; // trim leading whitespace
if (inUTF8 && length && parsed)
{
while (u < length && (c = inUTF8[u++])) {
if (c >= 'a' && c <= 'z') {
c -= 32; // convert lowercase to uppercase
} else if (c == 0x0a) {
c = 0x0d; // replace all LF with CR
} else if (c & 0x80 || c & 0x60 == 0) {
c = 0x20; // convert control char's and high ASCII to whitespace
}
if (lastc == 0x20 && c == 0x20) {
continue; // remove extra whitespace
}
parsed[p++] = lastc = c;
}
while (c == 0x20 && p--) {
c = parsed[p - 1]; // trim trailing whitespace
}
if (c != 0x0d) {
parsed[p++] = 0x0d; // terminate with CR
}
}
if (p != length + 1) {
[data setLength:p];
}
return [data autorelease];
}
--
Shaun Wexler
MacFOH
http://www.macfoh.com
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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