Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

63 lines (48 sloc) 1.307 kb
//
// NSString+Paragraphs.m
// DTRichTextEditor
//
// Created by Oliver Drobnik on 11/11/11.
// Copyright (c) 2011 Cocoanetics. All rights reserved.
//
#import "NSString+Paragraphs.h"
@implementation NSString (Paragraphs)
- (NSRange)rangeOfParagraphsContainingRange:(NSRange)range parBegIndex:(NSUInteger *)parBegIndex parEndIndex:(NSUInteger *)parEndIndex
{
// get beginning and end of paragraph containing the replaced range
CFIndex beginIndex;
CFIndex endIndex;
CFStringGetParagraphBounds((__bridge CFStringRef)self, CFRangeMake(range.location, range.length), &beginIndex, &endIndex, NULL);
if (parBegIndex)
{
*parBegIndex = beginIndex;
}
if (parEndIndex)
{
*parEndIndex = endIndex;
}
return NSMakeRange(beginIndex, endIndex - beginIndex);
}
- (BOOL)indexIsAtBeginningOfParagraph:(NSUInteger)index
{
// index zero is beginning of first paragraph
if (!index)
{
return YES;
}
// beginning of any other paragraph is after NL
if ([self characterAtIndex:index-1] == '\n')
{
return YES;
}
// no beginning
return NO;
}
- (NSRange)rangeOfParagraphAtIndex:(NSUInteger)index
{
NSUInteger start;
NSUInteger end;
[self rangeOfParagraphsContainingRange:NSMakeRange(index, 1) parBegIndex:&start parEndIndex:&end];
return NSMakeRange(start, end-start);
}
@end
Jump to Line
Something went wrong with that request. Please try again.