-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHelpers.cpp
66 lines (56 loc) · 1.52 KB
/
Helpers.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
58
59
60
61
62
63
64
65
/******************************************************************************
* w_scan_cpp - a dtv channel scanner based on VDR (www.tvdr.de) and it's
* Plugins.
*
* See the README file for copyright information and how to reach the author.
*****************************************************************************/
#include <string>
#include <langinfo.h>
#include <locale.h>
#include "Helpers.h"
std::string VdrSource(std::string s) {
size_t p = s.find_first_of("EWew");
size_t p2 = s.find(".");
if (p == std::string::npos)
return s;
char c = s[p];
if (c == 'e') c = 'E';
if (c == 'w') c = 'W';
if (p2 != std::string::npos) {
// VDR type.
if (s[p2+1] == '0') // S13.0E -> S13E
return s.substr(0,p2) + c;
return s;
}
if ((p+1) == s.size()) // S33E
return s;
// w_scan type.
if (s[p+1] == '0')
return s.substr(0,p) + c;
s[p] = '.';
return s + c;
}
bool InitCharTables(void) {
char* CodeSet;
if (setlocale(LC_CTYPE, "") != nullptr)
CodeSet = nl_langinfo(CODESET);
else {
char* LangEnv = getenv("LANG");
if (LangEnv) {
CodeSet = strchr(LangEnv, '.');
if (CodeSet)
CodeSet++;
}
else
CodeSet = nullptr;
}
if (CodeSet) {
bool result = SI::SetSystemCharacterTable(CodeSet);
if (not result)
ErrorMessage("SetSystemCharacterTables(" + std::string(CodeSet) + ") failed");
cCharSetConv::SetSystemCharacterTable(CodeSet);
return result;
}
else
return false;
}