mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-09-29 09:00:31 +00:00
Monotone-Parent: 3049bbd9ddfe5886523c3f742888bf850719f4bc
Monotone-Revision: d9a86eb13b216d79e4554381c163dbca408f0d39 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-07-19T20:01:13 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -597,4 +597,33 @@ static NSMutableCharacterSet *safeLDIFStartChars = nil;
|
||||
stringByReplacingString: @"'" withString: @"\\'"];
|
||||
}
|
||||
|
||||
- (NSUInteger) countOccurrencesOfString: (NSString *) substring
|
||||
{
|
||||
NSRange matchRange, substrRange;
|
||||
BOOL done = NO;
|
||||
NSUInteger selfLen, substrLen, count = 0;
|
||||
|
||||
selfLen = [self length];
|
||||
substrLen = [substring length];
|
||||
|
||||
matchRange = NSMakeRange (0, selfLen);
|
||||
while (!done)
|
||||
{
|
||||
substrRange = [self rangeOfString: substring options: 0 range: matchRange];
|
||||
if (substrRange.location == NSNotFound)
|
||||
done = YES;
|
||||
else
|
||||
{
|
||||
count++;
|
||||
matchRange.location = substrRange.location + 1;
|
||||
if (matchRange.location + substrLen > selfLen)
|
||||
done = YES;
|
||||
else
|
||||
matchRange.length = selfLen - matchRange.location;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user