-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.cpp
57 lines (48 loc) · 1.13 KB
/
global.cpp
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
#include "global.hpp"
chromid nAutosomes = 22;
chromid nChromosomes = 24;
namespace mapping {
ChromosomesMap chromosome;
ExtensionMap extension;
}
namespace name
{
string common(const string& a, const string& b) {
static const char specialChar = '.';
size_t i, size = min(a.length(), b.length());
for (i = 0; i < size; ++i) {
if (a[i] != b[i]) break;
}
string s = "";
if (i > 0) {
// ignore special character
if (i > 1 && a[i-1] == specialChar) --i;
s = a.substr(0, i);
}
return s;
}
string fileext(const string& s) {
size_t start = s.find_last_of('.');
return s.substr(
(start == string::npos || start == s.size()-1) ? 0 : start + 1
);
}
string filestem(const string& s) {
size_t start = s.find_last_of('/');
start = (start == string::npos) ? 0 : (start + 1);
size_t end = s.find_last_of('.');
return s.substr(
start,
(end == string::npos) ? (s.length() - start + 1) : (end - start)
);
}
string filepath(const string& s) {
size_t start = 0;
size_t end = s.find_last_of('/');
if (end == string::npos) {
return "./";
} else {
return s.substr(start, end+1);
}
}
}