forked from overtake/telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYapDatabaseLogging.m
executable file
·73 lines (61 loc) · 1.5 KB
/
YapDatabaseLogging.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#import "YapDatabaseLogging.h"
#if YapDatabaseLoggingTechnique != YapDatabaseLoggingTechnique_Lumberjack
/**
* This method is based on CocoaLumberjack's DDExtractFileNameWithoutExtension function.
* The copy option has been removed, as we only use __FILE__ as the filePath parameter.
**/
NSString *YDBExtractFileNameWithoutExtension(const char *filePath)
{
if (filePath == NULL) return nil;
char *lastSlash = NULL;
char *lastDot = NULL;
char *p = (char *)filePath;
while (*p != '\0')
{
if (*p == '/')
lastSlash = p;
else if (*p == '.')
lastDot = p;
p++;
}
char *subStr;
NSUInteger subLen;
if (lastSlash)
{
if (lastDot)
{
// lastSlash -> lastDot
subStr = lastSlash + 1;
subLen = lastDot - subStr;
}
else
{
// lastSlash -> endOfString
subStr = lastSlash + 1;
subLen = p - subStr;
}
}
else
{
if (lastDot)
{
// startOfString -> lastDot
subStr = (char *)filePath;
subLen = lastDot - subStr;
}
else
{
// startOfString -> endOfString
subStr = (char *)filePath;
subLen = p - subStr;
}
}
// We can take advantage of the fact that __FILE__ is a string literal.
// Specifically, we don't need to waste time copying the string.
// We can just tell NSString to point to a range within the string literal.
return [[NSString alloc] initWithBytesNoCopy:subStr
length:subLen
encoding:NSUTF8StringEncoding
freeWhenDone:NO];
}
#endif