Skip to content

Commit

Permalink
Version bump; Require and use C++17
Browse files Browse the repository at this point in the history
  • Loading branch information
TinoDidriksen committed Oct 5, 2023
1 parent ab7246a commit ef432b0
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 73 deletions.
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
project(transfuse
VERSION 0.6.1
VERSION 0.6.2
LANGUAGES CXX C
)

Expand Down Expand Up @@ -52,7 +52,7 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_FLAGS_COMMON} -fvisibility-inlines-hidden")

# Require latest possible C++ standard
foreach(flag "-std=c++20" "-std=c++2a" "-std=c++17" "-std=c++1z" "-std=c++14" "-std=c++1y")
foreach(flag "-std=c++20" "-std=c++2a" "-std=c++17")
string(REGEX REPLACE "[^a-z0-9]" "" _flag ${flag})
CHECK_CXX_COMPILER_FLAG(${flag} COMPILER_SUPPORTS_${_flag})
if(COMPILER_SUPPORTS_${_flag})
Expand All @@ -62,7 +62,7 @@ else()
endif()
endforeach()
if(NOT _ENABLED_CXX)
message(FATAL_ERROR "Could not enable at least C++14 (C++1y) - upgrade your compiler")
message(FATAL_ERROR "Could not enable at least C++17 - upgrade your compiler")
endif()
endif()

Expand Down Expand Up @@ -94,13 +94,9 @@ find_library(LIBZIP_LIBRARIES zip REQUIRED)

include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(filesystem HAS_FS)
CHECK_INCLUDE_FILE_CXX(string_view HAS_SV)
if(HAS_FS)
add_definitions(-DHAS_FS)
endif()
if(HAS_SV)
add_definitions(-DHAS_SV)
endif()

# std::filesystem is in a separate library until g++ 9
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ add_executable(transfuse
shared.hpp
state.hpp
stream.hpp
string_view.hpp
xml.hpp

base64.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/base64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#ifndef e5bd51be_BASE64_HPP_
#define e5bd51be_BASE64_HPP_

#include "string_view.hpp"
#include "shared.hpp"
#include <string>
#include <string_view>
#include <cstdint>

namespace Transfuse {
Expand Down
2 changes: 1 addition & 1 deletion src/dom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#define e5bd51be_DOM_HPP_

#include "state.hpp"
#include "string_view.hpp"
#include "xml.hpp"
#include "stream.hpp"
#include <unicode/utext.h>
#include <unicode/regex.h>
#include <libxml/tree.h>
#include <string_view>
#include <array>
#include <deque>

Expand Down
2 changes: 1 addition & 1 deletion src/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

#include "state.hpp"
#include "filesystem.hpp"
#include "string_view.hpp"
#include "shared.hpp"
#include "base64.hpp"
#include "dom.hpp"
#include "formats.hpp"
#include <libxml/tree.h>
#include <libxml/xmlsave.h>
#include <zip.h>
#include <string_view>
#include <fstream>
#include <iostream>
#include <random>
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef e5bd51be_FILESYSTEM_HPP_
#define e5bd51be_FILESYSTEM_HPP_

#include "string_view.hpp"
#include <string_view>

#ifdef HAS_FS
#include <filesystem>
Expand Down
2 changes: 1 addition & 1 deletion src/format-html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ std::string inject_html(DOM& dom) {
if (b != std::string::npos) {
content.replace(b, 3, "UTF-8");
// libxml2's serializer adds this <meta> tag to be helpful, but we already had one
std::string meta{ R"X(<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">)X" }; // ToDo: C++17 string_view
std::string_view meta{ R"X(<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">)X" };
auto m = content.find(meta);
if (m != std::string::npos) {
content.erase(m, meta.size());
Expand Down
2 changes: 1 addition & 1 deletion src/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef e5bd51be_OPTIONS_HPP_
#define e5bd51be_OPTIONS_HPP_

#include "string_view.hpp"
#include <string_view>
#include <utility>
#include <array>
#include <algorithm>
Expand Down
11 changes: 5 additions & 6 deletions src/shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ using namespace icu;

namespace Transfuse {

// ToDo: C++17 constexpr these
const std::string_view UTF8_BOM("\xef\xbb\xbf");
const std::string_view UTF32LE_BOM("\xff\xfe\x00\x00", 4);
const std::string_view UTF32BE_BOM("\x00\x00\xfe\xff", 4);
const std::string_view UTF16LE_BOM("\xff\xfe");
const std::string_view UTF16BE_BOM("\xfe\xff");
constexpr std::string_view UTF8_BOM("\xef\xbb\xbf");
constexpr std::string_view UTF32LE_BOM("\xff\xfe\x00\x00", 4);
constexpr std::string_view UTF32BE_BOM("\x00\x00\xfe\xff", 4);
constexpr std::string_view UTF16LE_BOM("\xff\xfe");
constexpr std::string_view UTF16BE_BOM("\xfe\xff");

inline bool is_utf8(std::string_view data) {
UChar32 c = 0;
Expand Down
9 changes: 1 addition & 8 deletions src/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#ifndef e5bd51be_SHARED_HPP_
#define e5bd51be_SHARED_HPP_

#include "string_view.hpp"
#include "filesystem.hpp"
#include <unicode/unistr.h>
#include <string>
#include <string_view>
#include <fstream>
#include <algorithm>
#include <cctype>
Expand Down Expand Up @@ -112,13 +112,6 @@ namespace details {
inline void _concat(std::string&) {
}

// ToDo: C++17 renders this function obsolete
template<typename... Args>
inline void _concat(std::string& msg, std::string_view t, Args... args) {
msg += t;
_concat(msg, args...);
}

template<typename T, typename... Args>
inline void _concat(std::string& msg, const T& t, Args... args) {
msg.append(t);
Expand Down
6 changes: 3 additions & 3 deletions src/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void State::commit() {

void State::name(std::string_view val) {
info("name", val);
s->name.assign(val.begin(), val.end()); // ToDo: C++17 change to =
s->name = val;
}

std::string_view State::name() {
Expand All @@ -165,7 +165,7 @@ std::string_view State::name() {

void State::format(std::string_view val) {
info("format", val);
s->format.assign(val.begin(), val.end()); // ToDo: C++17 change to =
s->format = val;
}

std::string_view State::format() {
Expand All @@ -177,7 +177,7 @@ std::string_view State::format() {

void State::stream(std::string_view val) {
info("stream", val);
s->stream.assign(val.begin(), val.end()); // ToDo: C++17 change to =
s->stream = val;
}

std::string_view State::stream() {
Expand Down
2 changes: 1 addition & 1 deletion src/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#ifndef e5bd51be_STATE_HPP_
#define e5bd51be_STATE_HPP_

#include "string_view.hpp"
#include "filesystem.hpp"
#include "xml.hpp"
#include <string>
#include <string_view>
#include <memory>

namespace Transfuse {
Expand Down
2 changes: 1 addition & 1 deletion src/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#define e5bd51be_STREAM_HPP_

#include "filesystem.hpp"
#include "string_view.hpp"
#include "xml.hpp"
#include "shared.hpp"
#include "state.hpp"
#include <unicode/utext.h>
#include <vector>
#include <string>
#include <string_view>
#include <fstream>

namespace Transfuse {
Expand Down
39 changes: 0 additions & 39 deletions src/string_view.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/xml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#ifndef e5bd51be_XML_HPP_
#define e5bd51be_XML_HPP_

#include "string_view.hpp"
#include <libxml/tree.h>
#include <libxml/xmlstring.h>
#include <string>
#include <string_view>
#include <set>
#include <algorithm>
#include <cctype>
Expand Down

0 comments on commit ef432b0

Please sign in to comment.