diff --git a/CMakeLists.txt b/CMakeLists.txt index 28a8297..7657313 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ -cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) +# For target_compile_features +cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) project(platform_folders VERSION 3.2.0 LANGUAGES CXX) # Since it's off, the library will be static by default @@ -20,6 +21,12 @@ set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "sago/platform_folders.h" ) +# Minimum C++11 for "nullptr" and other stuff +target_compile_features(${PROJECT_NAME} PRIVATE + cxx_std_11 + cxx_nullptr +) + # Apple requires linking to CoreServices # Check sys name instead of "APPLE" for cross-compilation if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") diff --git a/sago/platform_folders.cpp b/sago/platform_folders.cpp index 34e6bae..2dfaa4c 100644 --- a/sago/platform_folders.cpp +++ b/sago/platform_folders.cpp @@ -29,7 +29,6 @@ SOFTWARE. #include "platform_folders.h" #include #include -#include #include #include @@ -37,14 +36,15 @@ SOFTWARE. #include #include -static std::string win32_utf16_to_utf8(const wchar_t* wstr) { +static std::string win32_utf16_to_utf8(const wchar_t* wstr) +{ std::string res; // If the 6th parameter is 0 then WideCharToMultiByte returns the number of bytes needed to store the result. - int actualSize = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); + int actualSize = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr); if (actualSize > 0) { //If the converted UTF-8 string could not be in the initial buffer. Allocate one that can hold it. std::vector buffer(actualSize); - actualSize = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &buffer[0], buffer.size(), NULL, NULL); + actualSize = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &buffer[0], buffer.size(), nullptr, nullptr); res = buffer.data(); } if (actualSize == 0) { @@ -58,7 +58,8 @@ static std::string win32_utf16_to_utf8(const wchar_t* wstr) { static std::string GetWindowsFolder(int folderId, const char* errorMsg) { wchar_t szPath[MAX_PATH]; szPath[0] = 0; - if ( !SUCCEEDED( SHGetFolderPathW( NULL, folderId, NULL, 0, szPath ) ) ) { + if ( !SUCCEEDED( SHGetFolderPathW( nullptr, folderId, nullptr, 0, szPath ) ) ) + { throw std::runtime_error(errorMsg); } return win32_utf16_to_utf8(szPath); @@ -151,7 +152,7 @@ static std::string getLinuxFolderDefault(const char* envName, const char* defaul static void appendExtraFoldersTokenizer(const char* envName, const char* envValue, std::vector& folders) { std::vector buffer(envValue, envValue + std::strlen(envValue) + 1); char* p = std::strtok ( &buffer[0], ":"); - while (p != NULL) { + while (p != nullptr) { if (p[0] == '/') { folders.push_back(p); } @@ -160,7 +161,7 @@ static void appendExtraFoldersTokenizer(const char* envName, const char* envValu //The XDG documentation indicates that the folder should be ignored but that the program should continue. std::cerr << "Skipping path \"" << p << "\" in \"" << envName << "\" because it does not start with a \"/\"\n"; } - p = std::strtok (NULL, ":"); + p = std::strtok (nullptr, ":"); } }