aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-09-10 00:17:28 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-09-10 00:17:28 -0700
commit0dfa9a6b27b868e273b2ad6e8e9c5b5c7374b3e8 (patch)
treef99c24b7b45bd1577ffce87d4dfdfa354d1e9ccd /src
parent0480c8997054a8b3ea5537419b8a4f3812bc44f5 (diff)
Added conversion between NSIndexSet and MCOIndexSet (fixed #370)
Diffstat (limited to 'src')
-rw-r--r--src/cmake/objc.cmake1
-rw-r--r--src/cmake/public-headers.cmake1
-rw-r--r--src/objc/utils/MCOIndexSet.h3
-rw-r--r--src/objc/utils/MCOIndexSet.mm10
-rw-r--r--src/objc/utils/MCOUtils.h1
-rw-r--r--src/objc/utils/NSIndexSet+MCO.h18
-rw-r--r--src/objc/utils/NSIndexSet+MCO.m25
7 files changed, 59 insertions, 0 deletions
diff --git a/src/cmake/objc.cmake b/src/cmake/objc.cmake
index e3e461c9..35dfb221 100644
--- a/src/cmake/objc.cmake
+++ b/src/cmake/objc.cmake
@@ -82,6 +82,7 @@ set(objc_utils_files
objc/utils/NSObject+MCO.mm
objc/utils/NSString+MCO.mm
objc/utils/NSValue+MCO.mm
+ objc/utils/NSIndexSet+MCO.m
)
IF(APPLE)
diff --git a/src/cmake/public-headers.cmake b/src/cmake/public-headers.cmake
index 8395072a..0aad67f6 100644
--- a/src/cmake/public-headers.cmake
+++ b/src/cmake/public-headers.cmake
@@ -113,6 +113,7 @@ objc/utils/MCOOperation.h
objc/abstract/MCOConstants.h
objc/utils/MCOIndexSet.h
objc/utils/MCORange.h
+objc/utils/NSIndexSet+MCO.h
objc/abstract/MCOAbstract.h
objc/abstract/MCOAbstractMessage.h
objc/abstract/MCOAbstractMessagePart.h
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