2009-02-05 14:21:47 +00:00
|
|
|
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "fsencoding.hh"
|
|
|
|
#include <QString>
|
|
|
|
#include <QDir>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace FsEncoding {
|
|
|
|
|
|
|
|
string encode( wstring const & str )
|
|
|
|
{
|
|
|
|
return string( QString::fromStdWString( str ).toLocal8Bit().data() );
|
|
|
|
}
|
|
|
|
|
|
|
|
string encode( string const & str )
|
|
|
|
{
|
|
|
|
return string( QString::fromUtf8( str.c_str() ).toLocal8Bit().data() );
|
|
|
|
}
|
|
|
|
|
|
|
|
char separator()
|
|
|
|
{
|
|
|
|
return QDir::separator().toAscii();
|
|
|
|
}
|
|
|
|
|
|
|
|
string dirname( string const & str )
|
|
|
|
{
|
2009-02-02 15:01:48 +00:00
|
|
|
size_t x = str.rfind( separator() );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-02 15:01:48 +00:00
|
|
|
if ( x == string::npos )
|
|
|
|
return string( "." );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-02 15:01:48 +00:00
|
|
|
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 );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|