diff options
Diffstat (limited to 'src/core/basetypes/MCIndexSet.cpp')
-rw-r--r-- | src/core/basetypes/MCIndexSet.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/core/basetypes/MCIndexSet.cpp b/src/core/basetypes/MCIndexSet.cpp index 7f7e1db3..191a1588 100644 --- a/src/core/basetypes/MCIndexSet.cpp +++ b/src/core/basetypes/MCIndexSet.cpp @@ -398,6 +398,21 @@ void IndexSet::importSerializable(HashMap * serializable) } } +bool IndexSet::isEqual(Object * otherObject) +{ + IndexSet * otherIndexSet = (IndexSet *) otherObject; + if (mCount != otherIndexSet->mCount) { + return false; + } + for(unsigned int i = 0 ; i < mCount ; i ++) { + if ((mRanges[i].location != otherIndexSet->mRanges[i].location) || + (mRanges[i].length != otherIndexSet->mRanges[i].length)) { + return false; + } + } + return true; +} + void IndexSet::addIndexSet(IndexSet * indexSet) { for(unsigned int i = 0 ; i < indexSet->rangesCount() ; i ++) { @@ -435,3 +450,52 @@ INITIALIZE(IndexSet) { Object::registerObjectConstructor("mailcore::IndexSet", &createObject); } + +/* + +Unit test: + +String * uidsStr = MCSTR("129597-129662,129664,129667-129671,129673-129674,129678-129694,129696-129804"); +String * cachedUidsStr = MCSTR("129755-129804"); +IndexSet * uids = NULL; +IndexSet * cachedUids = NULL; + +{ + IndexSet * result = new IndexSet(); + Array * array = uidsStr->componentsSeparatedByString(MCSTR(",")); + mc_foreacharray(String, rangeStr, array) { + Array * rangeArray = rangeStr->componentsSeparatedByString(MCSTR("-")); + if (rangeArray->count() == 2) { + int left = ((String *) rangeArray->objectAtIndex(0))->intValue(); + int right = ((String *) rangeArray->objectAtIndex(1))->intValue(); + int length = right - left; + result->addRange(RangeMake(left, length)); + } + else { + result->addIndex(rangeStr->intValue()); + } + } + //fprintf(stderr, "%s\n", MCUTF8DESC(result)); + uids = result; +} +{ + IndexSet * result = new IndexSet(); + Array * array = cachedUidsStr->componentsSeparatedByString(MCSTR(",")); + mc_foreacharray(String, rangeStr, array) { + Array * rangeArray = rangeStr->componentsSeparatedByString(MCSTR("-")); + if (rangeArray->count() == 2) { + int left = ((String *) rangeArray->objectAtIndex(0))->intValue(); + int right = ((String *) rangeArray->objectAtIndex(1))->intValue(); + int length = right - left; + result->addRange(RangeMake(left, length)); + } + else { + result->addIndex(rangeStr->intValue()); + } + } + cachedUids = result; +} +fprintf(stderr, "|%s|\n", MCUTF8DESC(uids)); +uids->removeIndexSet(cachedUids); +fprintf(stderr, "|%s|\n", MCUTF8DESC(uids)); +*/ |