- Declared In:
- NSString+Extensions.h
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==
.
Convenience factory methodsHandling whitespace
- + stringWithData:encoding:
Comparisons
- - stringByRemovingSurroundingWhitespace
- - isWhitespace
- - stringByRemovingWhitespace
- - stringByRemovingCharactersFromSet:
Conversions
- - hasPrefixCaseInsensitive:
- - isEmpty
Using MIME encoding names
- - boolValue
- - intValueForHex
Filename extensions for MIME types
- + stringWithData:MIMEEncoding:
- + stringWithBytes:length:MIMEEncoding:
- - initWithData:MIMEEncoding:
- - dataUsingMIMEEncoding:
- + stringEncodingForMIMEEncoding:
- + MIMEEncodingForStringEncoding:
- - recommendedMIMEEncoding
Determining encoding of XML documents
- + pathExtensionForContentType:
- + contentTypeForPathExtension:
- + addContentTypePathExtensionPair:
Encryptions
- + MIMEEncodingOfXMLDocument:
- + encodingOfXMLDocument:
Abbreviating paths
- - encryptedString
- - encryptedStringWithSalt:
- - isValidEncryptionOfString:
Sharing instances
- - stringByAbbreviatingPathToWidth:forFont:
- - stringByAbbreviatingPathToWidth:forAttributes:
Printing/formatting
- - sharedInstance
- + printf:
- + fprintf::
- - printf
- - fprintf:
+ (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.
+ (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
.
+ (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.
+ (NSString *)contentTypeForPathExtension:(NSString *)extension
Returns the MIME content type/subtype for extension
+ (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.
+ (void)fprintf:(NSFileHandle *)fileHandle :(NSString *)format, ...
Writes the printf format string to fileHandle using the default C String encoding.
+ (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.
+ (void)printf:(NSString *)format, ...
Writes the printf format string to stdout using the default C String encoding.
+ (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.
+ (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
.
+ (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
.
+ (NSString *)stringWithData:(NSData *)data encoding:(NSStringEncoding)encoding
Convenience factory method.
- (BOOL)boolValue
Returns YES if the receiver is equal to string "yes", comparing case insensitive.
- (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
.
- (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.
- (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.
- (void)fprintf:(NSFileHandle *)fileHandle
Writes the contents of the reciever to fileHandle using the default C String encoding.
- (BOOL)hasPrefixCaseInsensitive:(NSString *)string
Returns YES if the receiver's prefix is equal to string, comparing case insensitive.
- (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
.
- (unsigned int)intValueForHex
Assumes the string contains an integer written in hexadecimal notation and returns its value. Uses scanHexInt in NSScanner.
- (BOOL)isEmpty
Returns yes if the string contains no text characters. Note that its length can still be non-zero.
- (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.
- (BOOL)isWhitespace
Returns YES if the receiver consists of whitespace only.
- (void)printf
Writes the contents of the reciever to stdout using the default C String encoding.
- (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.
- (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.
- (NSString *)stringByAbbreviatingPathToWidth:(float)maxWidth forAttributes:(NSDictionary *)attributes
Returns a string that is not wider than maxWidths pixels.
- (NSString *)stringByAbbreviatingPathToWidth:(float)maxWidth forFont:(NSFont *)font
Returns a string that is not wider than maxWidths pixels.
- (NSString *)stringByRemovingCharactersFromSet:(NSCharacterSet *)set
Returns a copy of the receiver with all characters from set removed.
- (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.
- (NSString *)stringByRemovingWhitespace
Returns a copy of the receiver with all whitespace removed.