-
Notifications
You must be signed in to change notification settings - Fork 2
/
NSData+FastHex.h
51 lines (39 loc) · 1.71 KB
/
NSData+FastHex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// NSData+FastHex.h
// Pods
//
// Created by Jonathon Mah on 2015-05-13.
//
//
#import <Foundation/Foundation.h>
#if !__has_feature(nullability)
#define NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_END
#define nullable
#define nonnull
#endif
NS_ASSUME_NONNULL_BEGIN
@interface NSData (FastHex)
/** Returns an NSData instance constructed from the hex characters of the passed string.
* A convenience method for \p -initWithHexString:ignoreOtherCharacters: with the value
* YES for \p ignoreOtherCharacters . */
+ (instancetype)dataWithHexString:(NSString *)hexString;
/** Initializes the NSData instance with data from the hex characters of the passed string.
*
* \param hexString A string containing ASCII hexadecimal characters (uppercase and lowercase accepted).
* \param ignoreOtherCharacters If YES, skips non-hexadecimal characters, and trailing characters.
* If NO, non-hexadecimal or trailing characters will abort parsing and this method will return nil.
*
* \return the initialized data instance, or nil if \p ignoreOtherCharacters is NO and \p hexString
* contains a non-hex or trailing character. If \p hexString is the empty string, returns an empty
* (non-nil) NSData instance. */
- (nullable instancetype)initWithHexString:(NSString *)hexString ignoreOtherCharacters:(BOOL)ignoreOtherCharacters;
/** Returns a string of the receiver's data bytes as uppercase hexadecimal characters. */
- (NSString *)hexStringRepresentation;
/** Returns a string of the receiver's data bytes as uppercase or lowercase hexadecimal characters.
*
* \param uppercase YES to use uppercase letters A-F; NO for lowercase a-f
*/
- (NSString *)hexStringRepresentationUppercase:(BOOL)uppercase;
@end
NS_ASSUME_NONNULL_END