diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2013-09-10 00:17:28 -0700 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2013-09-10 00:17:28 -0700 |
commit | 0dfa9a6b27b868e273b2ad6e8e9c5b5c7374b3e8 (patch) | |
tree | f99c24b7b45bd1577ffce87d4dfdfa354d1e9ccd /src/objc/utils | |
parent | 0480c8997054a8b3ea5537419b8a4f3812bc44f5 (diff) |
Added conversion between NSIndexSet and MCOIndexSet (fixed #370)
Diffstat (limited to 'src/objc/utils')
-rw-r--r-- | src/objc/utils/MCOIndexSet.h | 3 | ||||
-rw-r--r-- | src/objc/utils/MCOIndexSet.mm | 10 | ||||
-rw-r--r-- | src/objc/utils/MCOUtils.h | 1 | ||||
-rw-r--r-- | src/objc/utils/NSIndexSet+MCO.h | 18 | ||||
-rw-r--r-- | src/objc/utils/NSIndexSet+MCO.m | 25 |
5 files changed, 57 insertions, 0 deletions
diff --git a/src/objc/utils/MCOIndexSet.h b/src/objc/utils/MCOIndexSet.h index d80aa322..2bb2684e 100644 --- a/src/objc/utils/MCOIndexSet.h +++ b/src/objc/utils/MCOIndexSet.h @@ -57,6 +57,9 @@ /** Enumerates all the indexes of the index set.*/ - (void) enumerateIndexes:(void (^)(uint64_t idx))block; +/** Returns an NSIndexSet from a MCOIndexSet */ +- (NSIndexSet *) nsIndexSet; + @end #endif diff --git a/src/objc/utils/MCOIndexSet.mm b/src/objc/utils/MCOIndexSet.mm index 628ae23f..156be13e 100644 --- a/src/objc/utils/MCOIndexSet.mm +++ b/src/objc/utils/MCOIndexSet.mm @@ -147,4 +147,14 @@ MCO_SYNTHESIZE_NSCODING } } +- (NSIndexSet *) nsIndexSet +{ + NSMutableIndexSet * result = [NSMutableIndexSet indexSet]; + MCORange * allRanges = [self allRanges]; + for(unsigned int i = 0 ; i < [self rangesCount] ; i ++) { + [result addIndexesInRange:NSMakeRange(allRanges[i].location, allRanges[i].length)]; + } + return result; +} + @end diff --git a/src/objc/utils/MCOUtils.h b/src/objc/utils/MCOUtils.h index 3a2c8d82..e2f2e69c 100644 --- a/src/objc/utils/MCOUtils.h +++ b/src/objc/utils/MCOUtils.h @@ -23,5 +23,6 @@ #import <MailCore/MCOConstants.h> #import <MailCore/MCOIndexSet.h> #import <MailCore/MCORange.h> +#import <MailCore/NSIndexSet+MCO.h> #endif diff --git a/src/objc/utils/NSIndexSet+MCO.h b/src/objc/utils/NSIndexSet+MCO.h new file mode 100644 index 00000000..66aa5229 --- /dev/null +++ b/src/objc/utils/NSIndexSet+MCO.h @@ -0,0 +1,18 @@ +// +// NSIndexSet+MCO.h +// mailcore2 +// +// Created by Hoa V. DINH on 9/10/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import <Foundation/Foundation.h> + +@class MCOIndexSet; + +@interface NSIndexSet (MCO) + +/** Returns a MCOIndexSet from an NSIndexSet */ +- (MCOIndexSet *) mcoIndexSet; + +@end diff --git a/src/objc/utils/NSIndexSet+MCO.m b/src/objc/utils/NSIndexSet+MCO.m new file mode 100644 index 00000000..dd2b83d0 --- /dev/null +++ b/src/objc/utils/NSIndexSet+MCO.m @@ -0,0 +1,25 @@ +// +// NSIndexSet+MCO.m +// mailcore2 +// +// Created by Hoa V. DINH on 9/10/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "NSIndexSet+MCO.h" +#import "MCOIndexSet.h" + +@implementation NSIndexSet (MCO) + +- (MCOIndexSet *) mcoIndexSet +{ + MCOIndexSet * result = [MCOIndexSet indexSet];; + + [self enumerateRangesUsingBlock:^(NSRange range, BOOL * stop) { + [result addRange:MCORangeMake(range.location, range.length)]; + }]; + + return result; +} + +@end |