forked from mmower/spike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSString+SpikeAdditions.m
32 lines (25 loc) · 981 Bytes
/
NSString+SpikeAdditions.m
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
//
// NSString+SpikeAdditions.m
// Spike
//
// Created by Matt Mower on 22/02/2009.
// Copyright 2009 LucidMac Software. All rights reserved.
//
#import "NSString+SpikeAdditions.h"
@implementation NSString (NSString_SpikeAdditions)
- (NSString *)stringByRemovingANSIEscapeSequences {
NSMutableString *filteredString = [NSMutableString stringWithCapacity:[self length]];
NSScanner *scanner = [NSScanner scannerWithString:self];
NSString *buffer;
while( ![scanner isAtEnd] ) {
if( [scanner scanUpToCharactersFromSet:[NSCharacterSet controlCharacterSet] intoString:&buffer] ) {
[filteredString appendString:buffer];
}
if( ![scanner isAtEnd] && [scanner scanCharactersFromSet:[NSCharacterSet controlCharacterSet] intoString:nil] ) {
[scanner scanUpToCharactersFromSet:[NSCharacterSet letterCharacterSet] intoString:nil];
[scanner setScanLocation:[scanner scanLocation]+1];
}
}
return filteredString;
}
@end