Skip to content
This repository
file 38 lines (28 sloc) 0.786 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
//
// NSMutableString+HTML.m
// DTCoreText
//
// Created by Oliver Drobnik on 01.02.12.
// Copyright (c) 2012 Drobnik.com. All rights reserved.
//

#import "NSMutableString+HTML.h"


#define IS_WHITESPACE(_c) (_c == ' ' || _c == '\t' || _c == 0xA || _c == 0xB || _c == 0xC || _c == 0xD || _c == 0x85)

@implementation NSMutableString (HTML)

- (void)removeTrailingWhitespace
{
NSUInteger length = self.length;

NSInteger lastIndex = length-1;
NSInteger index = lastIndex;
NSInteger whitespaceLength = 0;

while (index>=0 && IS_WHITESPACE([self characterAtIndex:index]))
{
index--;
whitespaceLength++;
}

// do the removal once for all whitespace characters
if (whitespaceLength)
{
[self deleteCharactersInRange:NSMakeRange(index+1, whitespaceLength)];
}
}

@end
Something went wrong with that request. Please try again.