Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ AllowShortIfStatementsOnASingleLine: Always
AllowShortLoopsOnASingleLine: true
IndentRequires: true
IncludeCategories:
# Headers in <> with .h extension.
- Regex: '<([A-Za-z0-9\/-_])+\.h>'
# Headers in "" with a file extension.
- Regex: '"([A-Za-z0-9\/-_])+\..*"'
Priority: 10
# Headers in <> with .hpp extension.
- Regex: '<([A-Za-z0-9\/-_])+\.hpp>'
# Headers in <> with a file extension.
- Regex: '<([A-Za-z0-9\/-_])+\..*>'
Priority: 20
# Headers in <> without extension.
# Headers in <> without a file extension.
- Regex: '<([A-Za-z0-9\/-_])+>'
Priority: 30
PointerAlignment: Left
Expand Down
5 changes: 3 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
Checks: 'clang-analyzer-*,
concurrency-*,
cppcoreguidelines-*,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-non-private-member-variables-in-classes,
misc-*,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
modernize-*,
-modernize-use-trailing-return-type,
performance-*,
portability-*,
readability-*,
Expand Down
18 changes: 5 additions & 13 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
[*]
insert_final_newline = true
charset = utf-8
indent_size = 4
indent_style = tab
# Optional: git will commit as lf, this will only affect local files
end_of_line = lf

[*.{py,md,yml,sh,cmake,json}]
indent_style = space
indent_size = 2

[*.{py,md,yml,sh,cmake,json}.in]
indent_style = space
indent_size = 2
# Optional: git will commit as lf, this will only affect local files
end_of_line = lf

[CMakeLists.txt]
indent_style = space
indent_size = 2
[*.{hpp,cpp}]
indent_style = tab
indent_size = 4
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
uname -m
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 10
- name: configure
run: cmake -S . --preset=ninja-gcc -B build -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14
run: cmake -S . --preset=ninja-gcc -B build
- name: build debug
run: cmake --build build --config=Debug -- -v
- name: build release
Expand Down
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_DEBUG_POSTFIX "-d")

include(version.cmake)
set(package_name djson)

project(djson VERSION ${djson_version})
project(${package_name} VERSION ${djson_version})

option(DJ_INSTALL "Setup djson install" ${PROJECT_IS_TOP_LEVEL})
option(DJ_BUILD_TESTS "Build djson tests" ${PROJECT_IS_TOP_LEVEL})
Expand All @@ -16,6 +17,26 @@ configure_file(Doxyfile.in Doxyfile @ONLY)

add_subdirectory(lib)

if(DJ_INSTALL)
message(STATUS "[${package_name}] setting up install")
include(GNUInstallDirs)

set(install_dst "${CMAKE_INSTALL_LIBDIR}/cmake/${package_name}")

install(
TARGETS ${package_name}
EXPORT ${package_name}-targets
FILE_SET HEADERS
)

install(
EXPORT ${package_name}-targets
DESTINATION "${install_dst}"
NAMESPACE ${package_name}::
FILE ${package_name}-config.cmake
)
endif()

if(DJ_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
Expand Down
3 changes: 0 additions & 3 deletions config.cmake.in

This file was deleted.

2 changes: 1 addition & 1 deletion install_test/exe/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <djson/build_version.hpp>
#include "djson/build_version.hpp"
#include <print>

auto main() -> int { std::println("djson version: {}", dj::build_version_v); }
18 changes: 0 additions & 18 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,3 @@ target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
target_link_libraries(${PROJECT_NAME} PRIVATE
$<$<BOOL:${MINGW}>:stdc++exp>
)

if(DJ_INSTALL)
message(STATUS "[djson] setting up install")
include(GNUInstallDirs)

install(
TARGETS djson
EXPORT djson-targets
FILE_SET HEADERS
)

install(
EXPORT djson-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/djson"
NAMESPACE djson::
FILE djson-config.cmake
)
endif()
2 changes: 1 addition & 1 deletion lib/include/djson/error.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <djson/src_loc.hpp>
#include "djson/src_loc.hpp"
#include <string>

namespace dj {
Expand Down
4 changes: 2 additions & 2 deletions lib/include/djson/json.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <djson/error.hpp>
#include <djson/string_table.hpp>
#include "djson/error.hpp"
#include "djson/string_table.hpp"
#include <expected>
#include <format>
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/detail/parser.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "djson/json.hpp"
#include <detail/scanner.hpp>
#include <detail/value.hpp>
#include <djson/json.hpp>

namespace dj::detail {
class Parser {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/detail/token.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <djson/src_loc.hpp>
#include "djson/src_loc.hpp"
#include <array>
#include <cassert>
#include <string_view>
Expand Down
4 changes: 2 additions & 2 deletions lib/src/detail/value.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <djson/json.hpp>
#include <djson/string_table.hpp>
#include "djson/json.hpp"
#include "djson/string_table.hpp"
#include <cstdint>
#include <string>
#include <variant>
Expand Down
21 changes: 18 additions & 3 deletions lib/src/djson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,29 @@ template <typename T>
return std::visit(visitor, in.payload);
}

[[nodiscard]] auto resolve_symlink(fs::path path) -> fs::path {
static constexpr auto max_iters_v{100};
auto err = std::error_code{};
for (auto iter = 0; iter < max_iters_v; ++iter) {
if (fs::is_symlink(path, err)) {
path = fs::read_symlink(path, err);
if (err != std::errc{}) { return {}; }
continue;
}

return path;
}
return {};
}

[[nodiscard]] auto file_to_string(std::string_view const path, std::string& out) {
if (path.empty()) { return false; }

auto const fs_path = fs::path{path};
auto const real_path = resolve_symlink(path);
auto err = std::error_code{};
if (fs::is_directory(fs_path, err) || fs::is_symlink(fs_path, err)) { return false; }
if (real_path.empty() || fs::is_directory(real_path, err) || fs::is_symlink(real_path)) { return false; }

auto file = std::ifstream{fs_path, std::ios::binary | std::ios::ate};
auto file = std::ifstream{real_path, std::ios::binary | std::ios::ate};
if (!file.is_open()) { return false; }

auto const size = file.tellg();
Expand Down
8 changes: 7 additions & 1 deletion scripts/build_docs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ include(version.cmake)

configure_file(Doxyfile.in "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile" @ONLY)

set(flags "")

if(QUIET)
set(flags "-q")
endif()

execute_process(COMMAND
doxygen Doxyfile
doxygen ${flags} Doxyfile
COMMAND_ERROR_IS_FATAL ANY
)
2 changes: 1 addition & 1 deletion tests/harness/unit_test_main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <djson/build_version.hpp>
#include "djson/build_version.hpp"
#include <unit_test.hpp>
#include <print>

Expand Down
2 changes: 1 addition & 1 deletion tests/test_files.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <djson/json.hpp>
#include "djson/json.hpp"
#include <unit_test.hpp>
#include <filesystem>
#include <print>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_json.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <djson/json.hpp>
#include "djson/json.hpp"
#include <unit_test.hpp>
#include <print>
#include <ranges>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_serialize.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <djson/json.hpp>
#include "djson/json.hpp"
#include <unit_test.hpp>
#include <print>

Expand Down
2 changes: 1 addition & 1 deletion version.cmake
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set(djson_version "3.1.3")
set(djson_version "3.1.4")