1/* 2 This file is part of HelpViewer (http://www.roard.com/helpviewer) 3 Copyright (C) 2003 Nicolas Roard (nicolas@roard.com) 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18*/ 19 20#include "ModNSString.h" 21 22@implementation NSDecimalNumber (String) 23 - (NSString*) stringValue { 24 //NSLog (@"NSDecimalNumber stringValue"); 25 //NSLog (@"==>%@", [NSString stringWithFormat: @"%d", (int) [self doubleValue]]); 26 return [NSString stringWithFormat: @"%d", (int)[self doubleValue]]; 27 } 28@end 29 30@implementation NSString (Trim) 31+ (NSString*) trimString: (NSString*) str { 32 NSMutableString* ret = [[NSMutableString alloc] initWithString: @""]; 33 NSString* spaceChar = [NSString stringWithString: @" "]; 34 NSString* EOLChar = [NSString stringWithString: @"\n"]; 35 NSString* TabChar = [NSString stringWithString: @"\t"]; 36 37 BOOL space = YES; 38 int i; 39 40 for (i = 0; i < [str length]; i++) 41 { 42 NSString* current = [str substringWithRange: NSMakeRange (i,1)]; 43 if ([current isEqualToString: spaceChar]) 44 { 45 if (!space) 46 { 47 [ret appendString: current]; 48 space = YES; 49 } 50 } 51 else if ([current isEqualToString: EOLChar]) {} 52 else if ([current isEqualToString: TabChar]) 53 { 54 if (!space) 55 { 56 [ret appendString: @" "]; 57 space = YES; 58 } 59 } 60 else 61 { 62 [ret appendString: current]; 63 space = NO; 64 } 65 } 66 67 //NSLog (@"trimmed string : <%@> ", ret); 68 return AUTORELEASE(ret); 69 70 /* 71 NSArray* Items; 72 int i; 73 74 Items = [str componentsSeparatedByString: @"\n"]; 75 for (i = 0; i < [Items count]; i++) 76 { 77 if ([[Items objectAtIndex: i] length] > 0) 78 { 79 [ret1 appendString: [Items objectAtIndex: i]]; 80 if (i < [Items count] - 1) [ret1 appendString: @" "]; 81 } 82 } 83 Items = [ret1 componentsSeparatedByString: @" "]; 84 for (i = 0; i < [Items count]; i++) 85 { 86 if ([[Items objectAtIndex: i] length] > 0) 87 { 88 [ret2 appendString: [Items objectAtIndex: i]]; 89 if (i < [Items count] - 1) [ret2 appendString: @" "]; 90 } 91 } 92 93 return ret2; 94 //return str; 95 */ 96} 97@end 98