Changeset 515

Show
Ignore:
Timestamp:
03/31/08 17:49:36 (9 months ago)
Author:
pmerrill
Message:
  • Added a cropping function for directory paths.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/SapphireFrappliance/NSString-Extensions.h

    r461 r515  
    5151@end 
    5252 
     53@interface NSString (Additions) 
     54/*! 
     55 * @brief Crop a string (path) into something shorter 
     56 * 
     57 * This method creates a crops a string (path) if it is greater than the desired path component length 
     58 * 
     59 * @param directoryPath The path string 
     60 * @param toLength The number of path components to return 
     61 * @return The new string after cropping 
     62 */ 
     63+ (NSString *)stringByCroppingDirectoryPath:(NSString *)directoryPath toLength:(int)requestedLength; 
     64@end 
     65 
    5366/*! 
    5467 * @brief Mutable string extensions for Replacements 
  • trunk/SapphireFrappliance/NSString-Extensions.m

    r461 r515  
    4040@end 
    4141 
     42@implementation NSString (Additions) 
     43+ (NSString *)stringByCroppingDirectoryPath:(NSString *)directoryPath toLength:(int)requestedLength 
     44{ 
     45        int dirLength=[[directoryPath pathComponents] count]; 
     46        NSString *returnPath=directoryPath ; 
     47        if(dirLength>requestedLength) 
     48        { 
     49                NSLog(@"Directory %@ is %d - req %d",directoryPath, dirLength,requestedLength); 
     50                NSRange croppedRange; 
     51                croppedRange.location=dirLength-requestedLength; 
     52                croppedRange.length=requestedLength; 
     53                returnPath=[NSString stringWithFormat:@" ../%@/",[NSString pathWithComponents:[[directoryPath pathComponents] subarrayWithRange:croppedRange]]]; 
     54        } 
     55        return returnPath; 
     56} 
     57@end 
     58 
     59 
    4260@implementation NSMutableString (Replacements) 
    4361- (void)replaceAllOccurancesOf:(NSString *)search withString:(NSString *)replacement