Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced string<octet_t> with vector<octet_t> to adhere to C++ standard #52

Merged
merged 3 commits into from
Jun 3, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test-deb.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Ribose Inc. (https://www.ribose.com)
# Copyright 2021-2024 Ribose Inc. (https://www.ribose.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
# i386 supports actions/checkout@v1 only (no Node.js 32-bit binary)
# and and actions/checkout@v1 has some issues with nested repositories
if: startsWith(matrix.image, 'amd64')
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: kward/shunit2
path: ${{github.workspace}}/tests/shunit2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-and-test-msys.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Ribose Inc. (https://www.ribose.com)
# Copyright 2021-2024 Ribose Inc. (https://www.ribose.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
shared: [on, off]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
run: ctest --test-dir build --output-on-failure

- name: Checkout shell test framework
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: kward/shunit2
path: ${{ github.workspace }}/tests/shunit2
Expand Down
21 changes: 19 additions & 2 deletions .github/workflows/build-and-test-rh.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Ribose Inc. (https://www.ribose.com)
# Copyright 2021-2024 Ribose Inc. (https://www.ribose.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
image: [ 'centos:7', 'tgagor/centos:stream8', 'quay.io/centos/centos:stream9', 'fedora:35', 'fedora:36' ]
image: [ 'centos:7', 'tgagor/centos:stream8', 'quay.io/centos/centos:stream9', 'fedora:35', 'fedora:36', 'fedora:38' ]
env: [ {CC: gcc, CXX: g++}, {CC: clang, CXX: clang++} ]
shared: [ on, off ]
container: ${{ matrix.image }}
Expand All @@ -61,6 +61,14 @@ jobs:
run: yum -y install sudo git gcc gcc-c++ make cmake clang

- name: Checkout
if: matrix.image != 'centos:7'
uses: actions/checkout@v4
with:
fetch-depth: 1

# CentOS 7 doesn't support node.js:20. To be removed once it is EOLed at June, 2024.
- name: Checkout centos:7
if: matrix.image == 'centos:7'
uses: actions/checkout@v3
with:
fetch-depth: 1
Expand All @@ -87,6 +95,15 @@ jobs:
run: sudo yum -y install findutils

- name: Checkout shell test framework
if: matrix.image != 'centos:7'
uses: actions/checkout@v4
with:
repository: kward/shunit2
path: ${{github.workspace}}/tests/shunit2
fetch-depth: 1

- name: Checkout shell test framework centos7
if: matrix.image == 'centos:7'
uses: actions/checkout@v3
with:
repository: kward/shunit2
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Ribose Inc. (https://www.ribose.com)
# Copyright 2021-2024 Ribose Inc. (https://www.ribose.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
env: ${{ matrix.env }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

Expand All @@ -77,7 +77,7 @@ jobs:
run: ctest --test-dir build --output-on-failure

- name: Checkout shell test framework
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: kward/shunit2
path: ${{github.workspace}}/tests/shunit2
Expand All @@ -94,7 +94,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
CXX: clang++
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Ribose Inc. (https://www.ribose.com)
# Copyright 2021-2024 Ribose Inc. (https://www.ribose.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Ribose Inc. (https://www.ribose.com)
# Copyright 2021-2024 Ribose Inc. (https://www.ribose.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
MAKEFLAGS: j4
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Ribose Inc. (https://www.ribose.com)
# Copyright 2021-2024 Ribose Inc. (https://www.ribose.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
COVERITY_TOKEN: qjcM1CWLcq9PJB3yL0ZXIw
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

Expand All @@ -60,4 +60,4 @@ jobs:
with:
email: maxirmx@sw.consulting
token: ${{ env.COVERITY_TOKEN }}
command: cmake --build build
command: cmake --build build
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Ribose Inc. (https://www.ribose.com)
# Copyright 2021-2024 Ribose Inc. (https://www.ribose.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: DoozyX/clang-format-lint-action@v0.11
with:
source: '.'
Expand All @@ -52,5 +52,5 @@ jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ludeeus/action-shellcheck@master
6 changes: 3 additions & 3 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Ribose Inc. (https://www.ribose.com)
# Copyright 2021-2024 Ribose Inc. (https://www.ribose.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

Expand All @@ -54,7 +54,7 @@ jobs:
run: nix build

- name: Checkout shell test framework
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: kward/shunit2
path: ${{github.workspace}}/tests/shunit2
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ if (BUILD_SHARED_LIBS AND MSVC)
message(FATAL_ERROR "Building sexp shared library with MSVC is not supported")
endif(BUILD_SHARED_LIBS AND MSVC)


message(STATUS "Building ${TYPE} library")

if (WITH_SANITIZERS)
Expand Down Expand Up @@ -107,7 +106,6 @@ if(NOT MSVC)
-Wno-unused-parameter
-Wno-missing-field-initializers
)

endif(NOT MSVC)

add_library(sexpp ${TYPE}
Expand All @@ -132,7 +130,10 @@ target_include_directories(sexpp PUBLIC

if (BUILD_SHARED_LIBS)
target_compile_definitions(sexpp PUBLIC BUILD_SHARED_LIBS)
set_target_properties(sexpp PROPERTIES CXX_VISIBILITY_PRESET "hidden")
set_target_properties(sexpp PROPERTIES
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN true
)
endif (BUILD_SHARED_LIBS)

set_target_properties(sexpp PROPERTIES
Expand Down
39 changes: 22 additions & 17 deletions include/sexpp/sexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ class sexp_input_stream_t;

typedef uint8_t octet_t;

class SEXP_PUBLIC_SYMBOL sexp_simple_string_t : public std::basic_string<octet_t>,
class SEXP_PUBLIC_SYMBOL sexp_simple_string_t : public std::vector<octet_t>,
private sexp_char_defs_t {
public:
sexp_simple_string_t(void) = default;
sexp_simple_string_t(const octet_t *dt) : std::basic_string<octet_t>{dt} {}
sexp_simple_string_t(const octet_t *bt, size_t ln) : std::basic_string<octet_t>{bt, ln} {}
sexp_simple_string_t(const octet_t *dt);
sexp_simple_string_t(const octet_t *bt, size_t ln);
sexp_simple_string_t &append(int c)
{
(*this) += (octet_t)(c & 0xFF);
push_back((octet_t)(c & 0xFF));
return *this;
}
// Returns length for printing simple string as a token
size_t advanced_length_token(void) const { return length(); }
size_t advanced_length_token(void) const { return size(); }
// Returns length for printing simple string as a base64 string
size_t advanced_length_base64(void) const { return (2 + 4 * ((length() + 2) / 3)); }
size_t advanced_length_base64(void) const { return (2 + 4 * ((size() + 2) / 3)); }
// Returns length for printing simple string ss in quoted-string mode
size_t advanced_length_quoted(void) const { return (1 + length() + 1); }
size_t advanced_length_quoted(void) const { return (1 + size() + 1); }
// Returns length for printing simple string ss in hexadecimal mode
size_t advanced_length_hexadecimal(void) const { return (1 + 2 * length() + 1); }
size_t advanced_length_hexadecimal(void) const { return (1 + 2 * size() + 1); }
size_t advanced_length(sexp_output_stream_t *os) const;

sexp_output_stream_t *print_canonical_verbatim(sexp_output_stream_t *os) const;
Expand All @@ -134,19 +134,22 @@ class SEXP_PUBLIC_SYMBOL sexp_simple_string_t : public std::basic_string<octet_t

bool operator==(const char *right) const noexcept
{
return length() == std::strlen(right) && std::memcmp(data(), right, length()) == 0;
return size() == std::strlen(right) && std::memcmp(data(), right, size()) == 0;
}

bool operator!=(const char *right) const noexcept
{
return length() != std::strlen(right) || std::memcmp(data(), right, length()) != 0;
return size() != std::strlen(right) || std::memcmp(data(), right, size()) != 0;
}

unsigned as_unsigned() const noexcept
uint32_t as_unsigned() const noexcept;

std::string as_string(void) const
{
return empty() ? std::numeric_limits<uint32_t>::max() :
(unsigned) atoi(reinterpret_cast<const char *>(c_str()));
return std::string(reinterpret_cast<const char *>(data()), size());
}

std::string c_str(void) const { return as_string(); }
};

inline bool operator==(const sexp_simple_string_t *left, const std::string &right) noexcept
Expand Down Expand Up @@ -193,7 +196,7 @@ class SEXP_PUBLIC_SYMBOL sexp_object_t {
}
virtual bool operator==(const char *right) const noexcept { return false; }
virtual bool operator!=(const char *right) const noexcept { return true; }
virtual unsigned as_unsigned() const noexcept
virtual uint32_t as_unsigned() const noexcept
{
return std::numeric_limits<uint32_t>::max();
}
Expand Down Expand Up @@ -250,17 +253,19 @@ class SEXP_PUBLIC_SYMBOL sexp_string_t : public sexp_object_t {
virtual bool operator!=(const char *right) const noexcept { return data_string != right; }

void parse(sexp_input_stream_t *sis);
virtual unsigned as_unsigned() const noexcept { return data_string.as_unsigned(); }
virtual uint32_t as_unsigned() const noexcept { return data_string.as_unsigned(); }
};

inline bool operator==(const sexp_string_t *left, const std::string &right) noexcept
{
return *left == right.c_str();
return left->get_string().size() == right.length() &&
memcmp(left->get_string().data(), right.c_str(), left->get_string().size()) == 0;
}

inline bool operator!=(const sexp_string_t *left, const std::string &right) noexcept
{
return *left != right.c_str();
return left->get_string().size() != right.length() ||
memcmp(left->get_string().data(), right.c_str(), left->get_string().size()) != 0;
}

/*
Expand Down
Loading
Loading