File: Helpers.cpp

package info (click to toggle)
w-scan-cpp 0~20230121-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,008 kB
  • sloc: ansic: 69,193; cpp: 9,599; makefile: 1,149; perl: 862; python: 74; sh: 70
file content (66 lines) | stat: -rw-r--r-- 1,553 bytes parent folder | download | duplicates (2)
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
/******************************************************************************
 * 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;
}