forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fsencoding.cc
82 lines (67 loc) · 1.47 KB
/
fsencoding.cc
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
/* This file is (c) 2008-2012 Konstantin Isakov <[email protected]>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "fsencoding.hh"
#include "wstring_qt.hh"
#include <QString>
#include <QDir>
#include <vector>
namespace FsEncoding {
string encode( wstring const & str )
{
#ifdef __WIN32
return string( gd::toQString( str ).toUtf8().data() );
#else
return string( gd::toQString( str ).toLocal8Bit().data() );
#endif
}
string encode( string const & str )
{
#ifdef __WIN32
return string( str );
#else
return string( QString::fromUtf8( str.c_str() ).toLocal8Bit().data() );
#endif
}
string encode( QString const & str )
{
#ifdef __WIN32
return string( str.toUtf8().data() );
#else
return string( str.toLocal8Bit().data() );
#endif
}
wstring decode( string const & str )
{
#ifdef __WIN32
return gd::toWString( QString::fromUtf8( str.c_str() ) );
#else
return gd::toWString( QString::fromLocal8Bit( str.c_str() ) );
#endif
}
QString decode( const char *str )
{
#ifdef __WIN32
return QString::fromUtf8( str );
#else
return QString::fromLocal8Bit( str );
#endif
}
char separator()
{
return QDir::separator().toAscii();
}
string dirname( string const & str )
{
size_t x = str.rfind( separator() );
if ( x == string::npos )
return string( "." );
return string( str, 0, x );
}
string basename( string const & str )
{
size_t x = str.rfind( separator() );
if ( x == string::npos )
return str;
return string( str, x + 1 );
}
}