A set of very small categories for NSString
, NSMutableString
, NSArray
, and
NSDictionary
that add a few sorely lacking features (isEmpty
and containsKey:
methods, for instance).
Most of the methods are relatively self-explanatory, but this should clear things up for those of slightly greater ambiguity.
You can include MPTidbits
in your project by simply copying all five source files into your project, and then importing the global header file in any file in which you want to use an MPTidbits
method:
#import "MPTidbits.h"
These functions can be found in MPFunctions.h
.
-
NSString *MPHexStringFromBytes(void *bytes, NSUInteger len)
Returns a hexadecimal
NSString
representation of the data referenced bybytes
.len
should be the length of the data (the number of bytes).
These methods can be found in NSString+MPTidbits.h
.
-
- (BOOL)isEmpty
Returns
YES
only if the receiver is either empty (no characters), or contains only whitespace characters. -
- (BOOL)isEmptyIgnoringWhitespace:(BOOL)ignoreWhitespace
If
ignoreWhitespace
isYES
, returnsYES
only if the receiver is either empty (no characters), or contains only whitespace characters. IfignoreWhitespace
isNO
, returnsYES
only if the receiver is empty (no characters) -- it does not ignore whitespace characters. -
- (NSString *)stringByTrimmingWhitespace
Returns an
NSString
object identical to the receiver except that any leading or trailing whitespace characters (the characters in the set returned byNSCharacterSet
's+whitespaceCharacterSet
) will be stripped. -
- (NSString *)MD5Hash
Returns an
NSString
object that contains a 32-character hexadecimal representation of the receiver's MD5 hash. This method uses the functions of Foundation'sCommonCrypto
library, which means that your project does not have to link against an outside library (eg, OpenSSL). -
- (NSString *)SHA1Hash
Returns an
NSString
object that contains a 40-character hexadecimal representation of the receiver's SHA-1 hash. This method uses the functions of Foundation'sCommonCrypto
library, which means that your project does not have to link against an outside library (eg, OpenSSL).
These methods can be found in NSString+MPTidbits.h
.
-
- (void)trimCharactersInSet:(NSCharacterSet *)aCharacterSet
Strips leading and trailing characters from the receiver that belong to
aCharacterSet
. In contrast toNSString
's-stringByTrimmingCharactersInSet:
, this method operates on the receiver in place. -
- (void)trimWhitespace
Strips leading and trailing whitespace characters (the characters in the set returned by
NSCharacterSet
's+whitespaceCharacterSet
) from the receiver. In contrast to the above-stringByTrimmingWhitespace
, this method operates on the receiver in place.
These methods can be found in NSCollections+MPTidbits.h
.
-
- (BOOL)isEmpty
Returns
YES
only if the receiver contains no objects: the equivalent of([receiver count] == 0)
.
These methods can be found in NSCollections+MPTidbits.h
.
-
- (BOOL)isEmpty
Returns
YES
only if the receiver contains no objects: the equivalent of([receiver count] == 0)
. -
- (BOOL)containsKey:(NSString *)aKey
Returns
YES
only if the keyaKey
has an associated object in the receiver. -
- (BOOL)containsKey:(NSString *)aKey allowEmptyValue:(BOOL)allowEmpty
If
allowEmpty
isYES
, returnsYES
only if the keyaKey
has an associated object in the receiver. IfallowEmpty
isNO
, returnsYES
only if the keyaKey
has an associated object in the receiver, and that object is neither theNSNull
object, nor does it returnYES
to anisEmpty
message (if the object responds to it). This method is useful if you want to quickly check if a key both exists, and is not an empty string, for example.
MPTidbits
is licensed under the MIT license, excerpted below.
Copyright (C) 2008 - 09 Matt Patenaude.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.