-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathColorLog.m
More file actions
54 lines (47 loc) · 1.18 KB
/
ColorLog.m
File metadata and controls
54 lines (47 loc) · 1.18 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// COMMON FILE: Common
//
// ColorLog.m
// ColorLog
//
// Created by Uncle MiF on 9/15/10.
// Copyright 2010 Deep IT. All rights reserved.
//
#import "ColorLog.h"
#ifdef NSLog
#undef NSLog
#endif
void (*__ColorLog_NSLog)(NSString * fmt,...) = NSLog;// to prevent false warning about format string
BOOL IsXcodeColorsEnabled()
{
char* xcEnv = getenv("XcodeColors");
return (xcEnv && !strcmp(xcEnv, "YES"));
}
NSString* StripXcodeColors(NSString* str,...)
{
if (!str)
return nil;
NSRange range;
range = [str rangeOfString:LC_ESC @"[0"];
if (range.location == NSNotFound)
return str;
NSMutableString * res = [NSMutableString stringWithString:str];
do
{
NSRange end = range;
end.location += range.length;
end.length = [res length] - end.location;
if (end.length > 4)
end.length = 4;
end = [res rangeOfString:@"m" options:NSLiteralSearch range:end];
if (end.location == NSNotFound)
break;
[res replaceCharactersInRange:NSMakeRange(range.location, end.location - range.location + end.length) withString:@""];
range = [res rangeOfString:LC_ESC @"[0"];
}
while(range.location != NSNotFound);
return res;
}
NSString* AllowXcodeColors(NSString* str,...)
{
return str;
}