forked from vdr-projects/vdr-plugin-live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.h
130 lines (96 loc) · 3.39 KB
/
tools.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef VDR_LIVE_TOOLS_H
#define VDR_LIVE_TOOLS_H
#include <ctime>
#include <istream>
#include <locale>
#include <ostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
#include <vdr/channels.h>
#include <vdr/thread.h>
#include <vdr/videodir.h>
#include <vdr/tools.h>
std::istream& operator>>( std::istream& is, tChannelID& ret );
inline
std::ostream& operator<<( std::ostream& os, tChannelID const& id )
{
return os << *id.ToString();
}
namespace vdrlive {
std::string FormatDuration( char const* format, int hours, int minutes );
std::string FormatDateTime( char const* format, time_t time );
std::string StringReplace( std::string const& text, std::string const& substring, std::string const& replacement );
std::vector< std::string > StringSplit( std::string const& text, char delimiter );
int StringToInt( std::string const& string, int base = 10 );
std::string StringRepeat(int times, const std::string& input);
std::string StringWordTruncate(const std::string& input, size_t maxLen, bool& truncated);
inline std::string StringWordTruncate(const std::string& input, size_t maxLen) { bool dummy; return StringWordTruncate(input, maxLen, dummy); }
std::string StringEscapeAndBreak( std::string const& input );
std::string StringFormatBreak(std::string const& input);
std::string StringTrim(const std::string& str);
std::string ZeroPad(int number);
std::string MD5Hash(std::string const& str);
time_t GetTimeT(std::string timestring);
std::string ExpandTimeString(std::string timestring);
std::string StringUrlEncode( std::string const& input );
std::string GetXMLValue( std::string const& xml, std::string const& element );
time_t GetDateFromDatePicker(std::string const& datestring, std::string const& format);
std::string DatePickerToC(time_t date, std::string const& format);
std::string EncodeDomId(std::string const & toEncode, char const * from = ".-:", char const * to = "pmc");
std::string DecodeDomId(std::string const & toDecode, char const * from = "pmc", char const * to = ".-:");
std::string FileSystemExchangeChars(std::string const & s, bool ToFileSystem);
bool MoveDirectory(std::string const & sourceDir, std::string const & targetDir, bool copy = false);
struct bad_lexical_cast: std::runtime_error
{
bad_lexical_cast(): std::runtime_error( "bad lexical cast" ) {}
};
template< typename To, typename From >
To lexical_cast( From const& from )
{
std::stringstream parser;
parser << from;
To result;
parser >> result;
if ( !parser )
throw bad_lexical_cast();
return result;
}
template< typename From >
std::string ConvertToString( From const& from, std::locale const& loc = std::locale() )
{
std::ostringstream parser;
parser.imbue( loc );
parser << from;
return parser.str();
}
class ReadLock
{
private:
typedef void (ReadLock::*safe_bool)() const;
public:
ReadLock(cRwLock& lock, int timeout = 100)
: m_lock(lock)
, m_locked(false)
{
if (m_lock.Lock( false, timeout ))
m_locked = true;
}
~ReadLock()
{
if (m_locked)
m_lock.Unlock();
}
operator safe_bool() const
{
return m_locked ? &ReadLock::safe_bool_idiom : 0;
}
private:
ReadLock(ReadLock const&);
cRwLock& m_lock;
bool m_locked;
void safe_bool_idiom() const {}
};
} // namespace vdrlive
#endif // VDR_LIVE_TOOLS_H