mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
FsEncoding has got a basename() function. The Lsa module now uses it instead
of the system/local one. The implementation of FsEncoding::dirname() was also changed to stop relying on the system version.
This commit is contained in:
parent
4c29464c09
commit
e9799ba248
|
@ -5,7 +5,6 @@
|
|||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <vector>
|
||||
#include <libgen.h>
|
||||
|
||||
namespace FsEncoding {
|
||||
|
||||
|
@ -26,11 +25,22 @@ char separator()
|
|||
|
||||
string dirname( string const & str )
|
||||
{
|
||||
std::vector< char > tmp( str.size() + 1 );
|
||||
size_t x = str.rfind( separator() );
|
||||
|
||||
memcpy( &tmp.front(), str.c_str(), tmp.size() );
|
||||
if ( x == string::npos )
|
||||
return string( "." );
|
||||
|
||||
return ::dirname( &tmp.front() );
|
||||
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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@ char separator();
|
|||
/// Returns the directory part of the given filename.
|
||||
string dirname( string const & );
|
||||
|
||||
/// Returns the name part of the given filename.
|
||||
string basename( string const & );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
22
src/lsa.cc
22
src/lsa.cc
|
@ -7,6 +7,7 @@
|
|||
#include "folding.hh"
|
||||
#include "utf8.hh"
|
||||
#include "btreeidx.hh"
|
||||
#include "fsencoding.hh"
|
||||
#include <set>
|
||||
#include <vorbis/vorbisfile.h>
|
||||
#include <string.h>
|
||||
|
@ -131,23 +132,6 @@ Entry::Entry( File::Class & f )
|
|||
read * sizeof( uint16_t ) );
|
||||
}
|
||||
|
||||
#ifdef __WIN32
|
||||
|
||||
// Win32 features the usual Posix basename() which may modify its input. We
|
||||
// provide our local implementation here instead.
|
||||
|
||||
char const * basename( char const * n )
|
||||
{
|
||||
char const * lastSep = strrchr( n, '\\' );
|
||||
|
||||
if ( !lastSep )
|
||||
return n;
|
||||
|
||||
return lastSep + 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
class LsaDictionary: public BtreeIndexing::BtreeDictionary
|
||||
{
|
||||
File::Class idx;
|
||||
|
@ -159,7 +143,7 @@ public:
|
|||
vector< string > const & dictionaryFiles );
|
||||
|
||||
virtual string getName() throw()
|
||||
{ return basename( string( getDictionaryFilenames()[ 0 ] ).c_str() ); }
|
||||
{ return FsEncoding::basename( getDictionaryFilenames()[ 0 ] ); }
|
||||
|
||||
virtual map< Dictionary::Property, string > getProperties() throw()
|
||||
{ return map< Dictionary::Property, string >(); }
|
||||
|
@ -479,7 +463,7 @@ vector< sptr< Dictionary::Class > > Format::makeDictionaries(
|
|||
{
|
||||
// Building the index
|
||||
|
||||
initializing.indexingDictionary( basename( i->c_str() ) );
|
||||
initializing.indexingDictionary( FsEncoding::basename( *i ) );
|
||||
|
||||
File::Class idx( indexFile, "wb" );
|
||||
|
||||
|
|
Loading…
Reference in a new issue