Hauptseite | Liste aller Namensbereiche | Klassenhierarchie | Übersicht | Auflistung der Dateien | Elemente eines Namensbereiches | Datenstruktur-Elemente | Datei-Elemente

Helper.cpp

gehe zur Dokumentation dieser Datei
00001 // Copyright (C) 2004 Bernhard Assmann <bernie@tuxomania.net>
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //  
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //  
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 //  
00017 
00018 #include <iomanip>
00019 #include <sstream>
00020 #include <cstdio>
00021 #include <qdir.h>
00022 #include <qstringlist.h>
00023 #include <qfileinfo.h>
00024 
00025 extern "C" {
00026 #include <xcrypt.h>
00027 }
00028 
00029 #include "psfa/Helper.hpp"
00030 
00031 
00032 
00033 bool
00034 psfahelper::onlyWhiteSpace( const std::string theString ) 
00035 {
00036   using std::string;
00037    
00038   string whiteSpaces = " \n\t";
00039   string::size_type wSPos = theString.find_first_not_of( whiteSpaces );
00040   if( wSPos == string::npos ) {
00041     return true;
00042   }
00043   return false;
00044 }
00045 
00046 
00047 
00048 unsigned int
00049 psfahelper::getXMLChLength ( const XMLCh* const field ) 
00050 {
00051   if( field ) {
00052     std::string::size_type i = 0;
00053     while( field[i] != 0 ) {
00054       ++i;
00055     }
00056     return i;
00057   }
00058   return 0;
00059 }
00060 
00061 
00062 
00063 const std::string
00064 psfahelper::stripWhiteSpace( std::string theString ) 
00065 {
00066   using std::string;
00067   using psfahelper::onlyWhiteSpace;
00068   
00069   if( onlyWhiteSpace( theString ) ) {
00070     return "";
00071   }
00072     
00073   string::size_type whiteSpacePos;
00074   
00075   whiteSpacePos = theString.find( "  " );
00076   while( whiteSpacePos < string::npos ) {
00077     theString.replace( whiteSpacePos, 2, "" );
00078     whiteSpacePos = theString.find( "  ", whiteSpacePos );
00079   }
00080 
00081   whiteSpacePos = theString.find( "\n" );
00082   while( whiteSpacePos < string::npos ) {
00083     theString.replace( whiteSpacePos, 1, " " );
00084     whiteSpacePos = theString.find( "\n", whiteSpacePos + 1 );
00085   }
00086   
00087   whiteSpacePos = theString.find( "\t" );
00088   while( whiteSpacePos < string::npos ) {
00089     theString.replace( whiteSpacePos, 1, "" );
00090     whiteSpacePos = theString.find( "\t", whiteSpacePos + 1 );
00091   }
00092   
00093   return theString;
00094 }
00095 
00096 
00097 
00098 const std::string
00099 psfahelper::getMd5Sum( const std::string path, const std::string fileName ) 
00100 {
00101   std::string filePath = path + "/" + fileName;
00102 
00103   std::FILE* file = std::fopen( filePath.c_str(), "r" );
00104   unsigned char buff[16];
00105   md5_stream( file, buff );
00106 
00107   std::ostringstream sum;
00108   for (int cnt = 0; cnt < 16; ++cnt) {
00109     sum << std::setfill('0')
00110    << std::setw(2)
00111    << std::hex
00112    << static_cast<int>(buff[cnt]);
00113   }
00114   std::fclose( file );
00115 
00116   return sum.str();
00117 }
00118 
00119   
00120 
00121 void
00122 psfahelper::splitString( const std::string theString,
00123           std::vector< std::string >& theVector,
00124           const std::string delim ) 
00125 {
00126   using std::string;
00127   
00128   if( theString.empty() ) {
00129     return;
00130   }
00131   string::size_type startToken = 0;
00132   string::size_type nextToken  = theString.find( delim );
00133   while( nextToken < string::npos ) {
00134     string token( theString, startToken, nextToken - startToken );
00135     if( token != "" ) {
00136       theVector.push_back( token );
00137     }
00138     ++nextToken;
00139     startToken = nextToken;
00140     nextToken = theString.find( delim, startToken );
00141   }
00142   string token( theString, startToken );
00143   if( token != "" ) {
00144     theVector.push_back( token );
00145   }
00146   return;
00147 }
00148 
00149 
00150 
00151 void
00152 psfahelper::getFilePaths( const std::string path, 
00153            const std::string pattern, 
00154            std::vector< std::string >& fileList ) 
00155 {
00156   QDir dir( path.c_str() );
00157   dir.setFilter( QDir::Files | QDir::NoSymLinks | QDir::Readable );
00158   bool success = dir.exists();
00159   if( !success ) {
00160     return;
00161   }
00162   dir.setNameFilter( pattern.c_str() );
00163   QStringList dirList = dir.entryList();
00164   for( QStringList::Iterator i = dirList.begin(); i != dirList.end(); ++i ) {
00165     fileList.push_back( (*i).ascii() );
00166   }
00167   return;
00168 }
00169 
00170 
00171 
00172 bool
00173 psfahelper::pathIsDir( const std::string path ) 
00174 {
00175   QDir dir( path.c_str() );
00176   return dir.exists();
00177 }
00178 
00179 
00180 
00181 bool
00182 psfahelper::pathIsReadable( const std::string path ) 
00183 {
00184   QFileInfo file( path.c_str() );
00185   return file.isReadable();
00186 }
00187 
00188 
00189 
00190 int
00191 psfahelper::getFileSize( const std::string path ) 
00192 {
00193   QFileInfo file( path.c_str() );
00194   return file.size();
00195 }

Erzeugt am Mon Jul 12 11:45:04 2004 für PSFA von doxygen 1.3.4