NSString (EDExtensions)


Declared In:
NSString+Extensions.h


Category Description

Various common extensions to NSString.


Global Variables

Synopsis:

NSString *MIMEAsciiStringEncoding;
NSString *MIMELatin1StringEncoding;
NSString *MIMELatin2StringEncoding;
NSString *MIME2022JPStringEncoding;
NSString *MIMEUTF8StringEncoding;

Description:

String constants for common MIME string ecoding names. In Core Foundation these are referred to as IANA charset names. Unless you know a method/framework uses "shared" or "pooled" strings you must compare using isEqualToString: and not the == operator.

Synopsis:

NSString *MIMEApplicationContentType;
NSString *MIMEImageContentType;
NSString *MIMEAudioContentType;
NSString *MIMEMessageContentType;
NSString *MIMEMultipartContentType;
NSString *MIMETextContentType;
NSString *MIMEVideoContentType;
NSString *MIMEAlternativeMPSubtype;
NSString *MIMEMixedMPSubtype;
NSString *MIMEParallelMPSubtype;
NSString *MIMEDigestMPSubtype;
NSString *MIMERelatedMPSubtype;
NSString *MIMEInlineContentDisposition;
NSString *MIMEAttachmentContentDisposition;

Description:

String constants for common MIME content types. Unless you know a method/framework uses "shared" or "pooled" strings you must compare using isEqualToString: and not ==.


Method Types

Convenience factory methods
+ stringWithData:encoding:
Handling whitespace
- stringByRemovingSurroundingWhitespace
- isWhitespace
- stringByRemovingWhitespace
- stringByRemovingCharactersFromSet:
Comparisons
- hasPrefixCaseInsensitive:
- isEmpty
Conversions
- boolValue
- intValueForHex
Using MIME encoding names
+ stringWithData:MIMEEncoding:
+ stringWithBytes:length:MIMEEncoding:
- initWithData:MIMEEncoding:
- dataUsingMIMEEncoding:
+ stringEncodingForMIMEEncoding:
+ MIMEEncodingForStringEncoding:
- recommendedMIMEEncoding
Filename extensions for MIME types
+ pathExtensionForContentType:
+ contentTypeForPathExtension:
+ addContentTypePathExtensionPair:
Determining encoding of XML documents
+ MIMEEncodingOfXMLDocument:
+ encodingOfXMLDocument:
Encryptions
- encryptedString
- encryptedStringWithSalt:
- isValidEncryptionOfString:
Abbreviating paths
- stringByAbbreviatingPathToWidth:forFont:
- stringByAbbreviatingPathToWidth:forAttributes:
Sharing instances
- sharedInstance
Printing/formatting
+ printf:
+ fprintf::
- printf
- fprintf:


Class Methods

MIMEEncodingForStringEncoding:

+ (NSString *)MIMEEncodingForStringEncoding:(NSStringEncoding)encoding

Returns the MIME character set corresponding to the NSStringEncoding or nil if no such encoding exists. On Mac OS X this wraps CFStringConvertEncodingToIANACharSetName and on other platforms hardcoded tables are used.


MIMEEncodingOfXMLDocument:

+ (NSString *)MIMEEncodingOfXMLDocument:(NSData *)xmlData

Examines xmlData and searches for an XML processing directive that specifies the document's encoding. If found returns the encoding, specified as a MIME character set, otherwise returns nil.


addContentTypePathExtensionPair:

+ (void)addContentTypePathExtensionPair:(EDObjectPair *)tePair

Adds a mapping between a MIME content type/subtype and a file extension to the internal table; the MIME type/subtype being the first object and the file extension the second object in the pair. Note that one MIME type might be represented by several file extensions but a file extension must always map to exactly one MIME type; for example "image/jpeg" maps to "jpg" and "jpeg." A fairly extensive table is available by default.


contentTypeForPathExtension:

+ (NSString *)contentTypeForPathExtension:(NSString *)extension

Returns the MIME content type/subtype for extension


encodingOfXMLDocument:

+ (NSStringEncoding)encodingOfXMLDocument:(NSData *)xmlData

Examines xmlData and searches for an XML processing directive that specifies the document's encoding. If found returns the encoding, specified as an NSStringEncoding, otherwise returns 0.


fprintf::

+ (void)fprintf:(NSFileHandle *)fileHandle :(NSString *)format, ...

Writes the printf format string to fileHandle using the default C String encoding.


pathExtensionForContentType:

+ (NSString *)pathExtensionForContentType:(NSString *)contentType

Returns a file extension that is used for files of the MIME content type/subtype. Note that one MIME type might be represented by several file extensions.


printf:

+ (void)printf:(NSString *)format, ...

Writes the printf format string to stdout using the default C String encoding.


stringEncodingForMIMEEncoding:

+ (NSStringEncoding)stringEncodingForMIMEEncoding:(NSString *)charsetName

Returns the NSStringEncoding corresponding to the MIME character set charsetName or 0 if no such encoding exists. On Mac OS X this wraps CFStringConvertIANACharSetNameToEncoding and on other platforms hardcoded tables are used.


stringWithBytes:length:MIMEEncoding:

+ (NSString *)stringWithBytes:(const void *)buffer length:(unsigned int)length MIMEEncoding:(NSString *)charsetName

Creates and returns a string by copying length characters from buffer and coverting these into a string using the string encoding described by charsetName. If no NSStringEncoding corresponds to charsetName this method returns nil.


stringWithData:MIMEEncoding:

+ (NSString *)stringWithData:(NSData *)data MIMEEncoding:(NSString *)charsetName

Creates and returns a string by converting the bytes in data using the string encoding described by charsetName. If no NSStringEncoding corresponds to charsetName this method returns nil.


stringWithData:encoding:

+ (NSString *)stringWithData:(NSData *)data encoding:(NSStringEncoding)encoding

Convenience factory method.


Instance Methods

boolValue

- (BOOL)boolValue

Returns YES if the receiver is equal to string "yes", comparing case insensitive.


dataUsingMIMEEncoding:

- (NSData *)dataUsingMIMEEncoding:(NSString *)charsetName

Returns an NSData object containing a representation of the receiver in the encoding described by charsetName. If no NSStringEncoding corresponds to charsetName this method returns nil.


encryptedString

- (NSString *)encryptedString

Returns an encrypted version of the receiver using a random "salt."

This method is thread-safe.

Note: This method is not available on Windows NT platforms.


encryptedStringWithSalt:

- (NSString *)encryptedStringWithSalt:(const char *)salt

Returns an encrypted version of the receiver using salt as randomizer. Salt must be a C String containing excatly two characters.

This method is thread-safe.

Note: This method is not available on Windows NT platforms.


fprintf:

- (void)fprintf:(NSFileHandle *)fileHandle

Writes the contents of the reciever to fileHandle using the default C String encoding.


hasPrefixCaseInsensitive:

- (BOOL)hasPrefixCaseInsensitive:(NSString *)string

Returns YES if the receiver's prefix is equal to string, comparing case insensitive.


initWithData:MIMEEncoding:

- (id)initWithData:(NSData *)buffer MIMEEncoding:(NSString *)charsetName

Initialises a newly allocated string by converting the bytes in buffer using the string encoding described by charsetName. If no NSStringEncoding corresponds to charsetName this method returns nil.


intValueForHex

- (unsigned int)intValueForHex

Assumes the string contains an integer written in hexadecimal notation and returns its value. Uses scanHexInt in NSScanner.


isEmpty

- (BOOL)isEmpty

Returns yes if the string contains no text characters. Note that its length can still be non-zero.


isValidEncryptionOfString:

- (BOOL)isValidEncryptionOfString:(NSString *)aString

Returns YES if the receiver is a encryption of aString. Assume you have the encrypted password in pwd and the user's input in input. Call [pwd isValidEncryptionOfString:input] to verify the passwrd.

This method is thread-safe.

Note: This method is not available on Windows NT platforms.


isWhitespace

- (BOOL)isWhitespace

Returns YES if the receiver consists of whitespace only.


printf

- (void)printf

Writes the contents of the reciever to stdout using the default C String encoding.


recommendedMIMEEncoding

- (NSString *)recommendedMIMEEncoding

Returns the encoding, specified as a MIME character set, that the receiver should be converted to when being transferred on the Internet. This method prefers ASCII over ISO-Latin over the smallest encoding.


sharedInstance

- (NSString *)sharedInstance

Maintains a global pool of string instances. Returns the instance stored in the pool or adds the receiver if no such string was in the pool before. This can be used to allow for equality tests using == instead of isEqual: but this "leaks" all string instances that are ever shared and, hence, should be used with caution.


stringByAbbreviatingPathToWidth:forAttributes:

- (NSString *)stringByAbbreviatingPathToWidth:(float)maxWidth forAttributes:(NSDictionary *)attributes

Returns a string that is not wider than maxWidths pixels.


stringByAbbreviatingPathToWidth:forFont:

- (NSString *)stringByAbbreviatingPathToWidth:(float)maxWidth forFont:(NSFont *)font

Returns a string that is not wider than maxWidths pixels.


stringByRemovingCharactersFromSet:

- (NSString *)stringByRemovingCharactersFromSet:(NSCharacterSet *)set

Returns a copy of the receiver with all characters from set removed.


stringByRemovingSurroundingWhitespace

- (NSString *)stringByRemovingSurroundingWhitespace

Returns a copy of the receiver with all whitespace left of the first non-whitespace character and right of the last whitespace character removed.


stringByRemovingWhitespace

- (NSString *)stringByRemovingWhitespace

Returns a copy of the receiver with all whitespace removed.


Version 2.0 Copyright ©2002. All Rights Reserved.