src: replaced some usages of string by wstring in filepath

This commit is contained in:
mlangkabel
2018-02-26 15:03:28 +01:00
parent 6d82e9265a
commit bae6bd73d6
15 changed files with 66 additions and 76 deletions
+1 -2
View File
@@ -20,7 +20,6 @@
#include "utility/commandline/CommandLineParser.h" #include "utility/commandline/CommandLineParser.h"
#include "utility/logging/ConsoleLogger.h" #include "utility/logging/ConsoleLogger.h"
#include "utility/logging/FileLogger.h" #include "utility/logging/FileLogger.h"
#include "utility/logging/LoggerUtility.h"
#include "utility/logging/logging.h" #include "utility/logging/logging.h"
#include "utility/logging/LogManager.h" #include "utility/logging/LogManager.h"
#include "utility/messaging/type/MessageInterruptTasks.h" #include "utility/messaging/type/MessageInterruptTasks.h"
@@ -52,7 +51,7 @@ void setupLogging()
std::shared_ptr<FileLogger> fileLogger = std::make_shared<FileLogger>(); std::shared_ptr<FileLogger> fileLogger = std::make_shared<FileLogger>();
fileLogger->setLogDirectory(UserPaths::getLogPath()); fileLogger->setLogDirectory(UserPaths::getLogPath());
fileLogger->setFileName(LoggerUtility::generateDatedFileName("log")); fileLogger->setFileName(FileLogger::generateDatedFileName(L"log"));
fileLogger->setLogLevel(Logger::LOG_ALL); fileLogger->setLogLevel(Logger::LOG_ALL);
logManager->addLogger(fileLogger); logManager->addLogger(fileLogger);
} }
-2
View File
@@ -370,8 +370,6 @@ add_files(
utility/logging/FileLogger.h utility/logging/FileLogger.h
utility/logging/Logger.cpp utility/logging/Logger.cpp
utility/logging/Logger.h utility/logging/Logger.h
utility/logging/LoggerUtility.cpp
utility/logging/LoggerUtility.h
utility/logging/logging.h utility/logging/logging.h
utility/logging/LogManager.cpp utility/logging/LogManager.cpp
utility/logging/LogManager.h utility/logging/LogManager.h
+5 -3
View File
@@ -1,5 +1,7 @@
#include "data/indexer/IndexerCommand.h" #include "data/indexer/IndexerCommand.h"
#include "utility/utilityString.h"
IndexerCommand::IndexerCommand( IndexerCommand::IndexerCommand(
const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths
) )
@@ -15,16 +17,16 @@ IndexerCommand::~IndexerCommand()
size_t IndexerCommand::getByteSize(size_t stringSize) const size_t IndexerCommand::getByteSize(size_t stringSize) const
{ {
size_t size = m_sourceFilePath.str().size(); size_t size = utility::encodeToUtf8(m_sourceFilePath.wstr()).size();
for (const FilePath& path: m_indexedPaths) for (const FilePath& path: m_indexedPaths)
{ {
size += stringSize + path.str().size(); size += stringSize + utility::encodeToUtf8(path.wstr()).size();
} }
for (const FilePath& path : m_excludedPaths) for (const FilePath& path : m_excludedPaths)
{ {
size += stringSize + path.str().size(); size += stringSize + utility::encodeToUtf8(path.wstr()).size();
} }
return size; return size;
+2 -2
View File
@@ -1885,7 +1885,7 @@ TooltipInfo PersistentStorage::getTooltipInfoForSourceLocationIdsAndLocalSymbolI
const NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName); const NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
snippet.code = codec.encode(nameHierarchy.getQualifiedName()); snippet.code = codec.encode(nameHierarchy.getQualifiedName());
snippet.locationFile = std::make_shared<SourceLocationFile>( snippet.locationFile = std::make_shared<SourceLocationFile>(
FilePath(nameHierarchy.getDelimiter() == NAME_DELIMITER_JAVA ? "main.java" : "main.cpp"), true, true); FilePath(nameHierarchy.getDelimiter() == NAME_DELIMITER_JAVA ? L"main.java" : L"main.cpp"), true, true);
snippet.locationFile->addSourceLocation( snippet.locationFile->addSourceLocation(
LOCATION_TOKEN, 0, std::vector<Id>(1, node.id), 1, 1, 1, snippet.code.size()); LOCATION_TOKEN, 0, std::vector<Id>(1, node.id), 1, 1, 1, snippet.code.size());
@@ -2645,7 +2645,7 @@ void PersistentStorage::buildMemberEdgeIdOrderMap()
intToLocationType(location.type), intToLocationType(location.type),
location.id, location.id,
std::vector<Id>(), std::vector<Id>(),
FilePath(std::to_string(location.fileNodeId)), FilePath(std::to_wstring(location.fileNodeId)),
location.startLine, location.startLine,
location.startCol, location.startCol,
location.endLine, location.endLine,
+37 -8
View File
@@ -2,14 +2,43 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <ctime>
#include <cstdio> #include <cstdio>
#include "utility/file/FileSystem.h" #include "utility/file/FileSystem.h"
#include "utility/utilityString.h" #include "utility/utilityString.h"
std::wstring FileLogger::generateDatedFileName(const std::wstring& prefix, const std::wstring& suffix)
{
time_t time;
std::time(&time);
tm t = *std::localtime(&time);
std::wstringstream filename;
if (!prefix.empty())
{
filename << prefix;
filename << L"_";
}
filename << t.tm_year + 1900 << L"-";
filename << (t.tm_mon < 9 ? L"0" : L"") << t.tm_mon + 1 << L"-";
filename << (t.tm_mday < 10 ? L"0" : L"") << t.tm_mday << L"_";
filename << (t.tm_hour < 10 ? L"0" : L"") << t.tm_hour << L"-";
filename << (t.tm_min < 10 ? L"0" : L"") << t.tm_min << L"-";
filename << (t.tm_sec < 10 ? L"0" : L"") << t.tm_sec;
if (!suffix.empty())
{
filename << L"_";
filename << suffix;
}
return filename.str();
}
FileLogger::FileLogger() FileLogger::FileLogger()
: Logger("FileLogger") : Logger("FileLogger")
, m_logFileName("log") , m_logFileName(L"log")
, m_logDirectory(L"user/log/") , m_logDirectory(L"user/log/")
, m_maxLogLineCount(0) , m_maxLogLineCount(0)
, m_maxLogFileCount(0) , m_maxLogFileCount(0)
@@ -31,7 +60,7 @@ FilePath FileLogger::getLogFilePath() const
void FileLogger::setLogFilePath(const FilePath& filePath) void FileLogger::setLogFilePath(const FilePath& filePath)
{ {
m_currentLogFilePath = filePath; m_currentLogFilePath = filePath;
m_logFileName = ""; m_logFileName = L"";
} }
void FileLogger::setLogDirectory(const FilePath& filePath) void FileLogger::setLogDirectory(const FilePath& filePath)
@@ -40,7 +69,7 @@ void FileLogger::setLogDirectory(const FilePath& filePath)
FileSystem::createDirectory(m_logDirectory); FileSystem::createDirectory(m_logDirectory);
} }
void FileLogger::setFileName(const std::string& fileName) void FileLogger::setFileName(const std::wstring& fileName)
{ {
if (fileName != m_logFileName) if (fileName != m_logFileName)
{ {
@@ -78,17 +107,17 @@ void FileLogger::setMaxLogFileCount(unsigned int fileCount)
void FileLogger::updateLogFileName() void FileLogger::updateLogFileName()
{ {
if (!m_logFileName.size()) if (m_logFileName.empty())
{ {
return; return;
} }
bool fileChanged = false; bool fileChanged = false;
std::string currentLogFilePath = m_logDirectory.str() + m_logFileName; std::wstring currentLogFilePath = m_logDirectory.wstr() + m_logFileName;
if (m_maxLogFileCount > 0) if (m_maxLogFileCount > 0)
{ {
currentLogFilePath += "_"; currentLogFilePath += L"_";
if (m_currentLogLineCount >= m_maxLogLineCount) if (m_currentLogLineCount >= m_maxLogLineCount)
{ {
m_currentLogLineCount = 0; m_currentLogLineCount = 0;
@@ -100,10 +129,10 @@ void FileLogger::updateLogFileName()
} }
fileChanged = true; fileChanged = true;
} }
currentLogFilePath += std::to_string(m_currentLogFileCount); currentLogFilePath += std::to_wstring(m_currentLogFileCount);
} }
currentLogFilePath += ".txt"; currentLogFilePath += L".txt";
m_currentLogFilePath = FilePath(currentLogFilePath); m_currentLogFilePath = FilePath(currentLogFilePath);
+4 -2
View File
@@ -10,6 +10,8 @@
class FileLogger: public Logger class FileLogger: public Logger
{ {
public: public:
static std::wstring generateDatedFileName(const std::wstring& prefix = L"", const std::wstring& suffix = L"");
FileLogger(); FileLogger();
virtual ~FileLogger(); virtual ~FileLogger();
@@ -17,7 +19,7 @@ public:
void setLogFilePath(const FilePath& filePath); void setLogFilePath(const FilePath& filePath);
void setLogDirectory(const FilePath& filePath); void setLogDirectory(const FilePath& filePath);
void setFileName(const std::string& fileName); void setFileName(const std::wstring& fileName);
void setMaxLogLineCount(unsigned int logCount); void setMaxLogLineCount(unsigned int logCount);
// setting the max log file count to 0 will disable ringlogging // setting the max log file count to 0 will disable ringlogging
@@ -31,7 +33,7 @@ private:
void logMessage(const std::string& type, const LogMessage& message); void logMessage(const std::string& type, const LogMessage& message);
void updateLogFileName(); void updateLogFileName();
std::string m_logFileName; std::wstring m_logFileName;
FilePath m_logDirectory; FilePath m_logDirectory;
FilePath m_currentLogFilePath; FilePath m_currentLogFilePath;
-32
View File
@@ -1,32 +0,0 @@
#include "LoggerUtility.h"
#include <sstream>
#include <ctime>
std::string LoggerUtility::generateDatedFileName(const std::string& prefix, const std::string& suffix)
{
time_t time;
std::time(&time);
tm t = *std::localtime(&time);
std::stringstream filename;
if (prefix.length() > 0)
{
filename << prefix;
filename << "_";
}
filename << t.tm_year + 1900 << "-";
filename << (t.tm_mon < 9 ? "0" : "") << t.tm_mon + 1 << "-";
filename << (t.tm_mday < 10 ? "0" : "") << t.tm_mday << "_";
filename << (t.tm_hour < 10 ? "0" : "") << t.tm_hour << "-";
filename << (t.tm_min < 10 ? "0" : "") << t.tm_min << "-";
filename << (t.tm_sec < 10 ? "0" : "") << t.tm_sec;
if (suffix.length() > 0)
{
filename << "_";
filename << suffix;
}
return filename.str();
}
-12
View File
@@ -1,12 +0,0 @@
#ifndef LOGGER_UTILITY_H
#define LOGGER_UTILITY_H
#include <string>
class LoggerUtility
{
public:
static std::string generateDatedFileName(const std::string& prefix = "", const std::string& suffix = "");
};
#endif // LOGGER_UTILITY_H
@@ -1,5 +1,7 @@
#include "data/indexer/IndexerCommandCxx.h" #include "data/indexer/IndexerCommandCxx.h"
#include "utility/utilityString.h"
IndexerCommandCxx::IndexerCommandCxx( IndexerCommandCxx::IndexerCommandCxx(
const FilePath& sourceFilePath, const FilePath& sourceFilePath,
const std::set<FilePath>& indexedPaths, const std::set<FilePath>& indexedPaths,
@@ -23,12 +25,12 @@ size_t IndexerCommandCxx::getByteSize(size_t stringSize) const
for (auto& i : m_systemHeaderSearchPaths) for (auto& i : m_systemHeaderSearchPaths)
{ {
size += stringSize + i.str().size(); size += stringSize + utility::encodeToUtf8(i.wstr()).size();
} }
for (auto& i : m_frameworkSearchPaths) for (auto& i : m_frameworkSearchPaths)
{ {
size += stringSize + i.str().size(); size += stringSize + utility::encodeToUtf8(i.wstr()).size();
} }
for (auto& i : m_compilerFlags) for (auto& i : m_compilerFlags)
+2 -2
View File
@@ -120,9 +120,9 @@ void QtLocationPicker::handleButtonPress()
{ {
if (!m_relativeRootDirectory.empty()) if (!m_relativeRootDirectory.empty())
{ {
const FilePath path(fileName.toStdString()); const FilePath path(fileName.toStdWString());
const FilePath relPath = path.getRelativeTo(m_relativeRootDirectory); const FilePath relPath = path.getRelativeTo(m_relativeRootDirectory);
if (relPath.str().size() < path.str().size()) if (relPath.wstr().size() < path.wstr().size())
{ {
fileName = QString::fromStdWString(relPath.wstr()); fileName = QString::fromStdWString(relPath.wstr());
} }
+1 -1
View File
@@ -13,7 +13,7 @@ QtStatusBar::QtStatusBar()
{ {
addWidget(new QWidget()); // add some space addWidget(new QWidget()); // add some space
m_movie = std::make_shared<QMovie>((ResourcePaths::getGuiPath().str() + "statusbar_view/loader.gif").c_str()); m_movie = std::make_shared<QMovie>(QString::fromStdWString(ResourcePaths::getGuiPath().concatenate(L"statusbar_view/loader.gif").wstr()));
// if movie doesn't loop forever, force it to. // if movie doesn't loop forever, force it to.
if (m_movie->loopCount() != -1) if (m_movie->loopCount() != -1)
{ {
@@ -697,7 +697,7 @@ void QtProjectWizzardContentPathsHeaderSearch::showDetectedIncludesResult(const
if (!relativeRoot.empty()) if (!relativeRoot.empty())
{ {
const FilePath relPath = path.getRelativeTo(relativeRoot); const FilePath relPath = path.getRelativeTo(relativeRoot);
if (relPath.str().size() < path.str().size()) if (relPath.wstr().size() < path.wstr().size())
{ {
detailedText += relPath.wstr() + L"\n"; detailedText += relPath.wstr() + L"\n";
} }
@@ -1,5 +1,7 @@
#include "data/indexer/IndexerCommandJava.h" #include "data/indexer/IndexerCommandJava.h"
#include "utility/utilityString.h"
IndexerCommandType IndexerCommandJava::getStaticIndexerCommandType() IndexerCommandType IndexerCommandJava::getStaticIndexerCommandType()
{ {
return INDEXER_COMMAND_JAVA; return INDEXER_COMMAND_JAVA;
@@ -33,7 +35,7 @@ size_t IndexerCommandJava::getByteSize(size_t stringSize) const
for (auto& i : m_classPath) for (auto& i : m_classPath)
{ {
size += stringSize + i.str().size(); size += stringSize + utility::encodeToUtf8(i.wstr()).size();
} }
return size; return size;
+5 -5
View File
@@ -84,7 +84,7 @@ public:
std::cout.rdbuf( oldBuf ); std::cout.rdbuf( oldBuf );
FilePath path = ApplicationSettings::getInstance()->getMavenPath(); FilePath path = ApplicationSettings::getInstance()->getMavenPath();
TS_ASSERT_EQUALS( path.str(), "/opt/testpath/mvn") TS_ASSERT_EQUALS( path.wstr(), L"/opt/testpath/mvn")
} }
@@ -102,10 +102,10 @@ public:
parser.parse(); parser.parse();
std::vector<FilePath> paths = ApplicationSettings::getInstance()->getHeaderSearchPaths(); std::vector<FilePath> paths = ApplicationSettings::getInstance()->getHeaderSearchPaths();
TS_ASSERT_EQUALS( paths[0].str(), "/usr") TS_ASSERT_EQUALS( paths[0].wstr(), L"/usr")
TS_ASSERT_EQUALS( paths[1].str(), "/usr/include") TS_ASSERT_EQUALS( paths[1].wstr(), L"/usr/include")
TS_ASSERT_EQUALS( paths[2].str(), "/include") TS_ASSERT_EQUALS( paths[2].wstr(), L"/include")
TS_ASSERT_EQUALS( paths[3].str(), "/opt/include") TS_ASSERT_EQUALS( paths[3].wstr(), L"/opt/include")
} }
+1 -1
View File
@@ -28,7 +28,7 @@ public:
void test_find_h_files() void test_find_h_files()
{ {
std::vector<std::wstring> headerFiles = utility::convert<FilePath, std::wstring>( std::vector<std::wstring> headerFiles = utility::convert<FilePath, std::wstring>(
FileSystem::getFilePathsFromDirectory(FilePath("data/FileSystemTestSuite"), { L".h" }), FileSystem::getFilePathsFromDirectory(FilePath(L"data/FileSystemTestSuite"), { L".h" }),
[](const FilePath& filePath){ return filePath.wstr(); } [](const FilePath& filePath){ return filePath.wstr(); }
); );