Skip to content

Conversation

@Shamzik
Copy link
Contributor

@Shamzik Shamzik commented Dec 29, 2025

In this PR I'm adding pcre2-functions.h and pcre2-functions.cpp, into which I've extracted all PCRE2 specifics.

@Shamzik Shamzik added this to the next milestone Dec 29, 2025
@Shamzik Shamzik self-assigned this Dec 29, 2025
@Shamzik Shamzik added the k2 k2 related label Dec 29, 2025
@Shamzik Shamzik marked this pull request as ready for review December 29, 2025 12:27
#include <optional>
#include <string_view>

#include "runtime-light/stdlib/diagnostics/logs.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove unused includes and add ones you actually use

}

private:
const PCRE2_UCHAR8* m_ptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's move all member declarations to the a type declaration's beginning

using value_type = group_name;
using difference_type = std::ptrdiff_t;
using pointer = group_name*;
using reference = group_name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should here be group_name&?


group_name operator*() const noexcept {
const auto index{static_cast<size_t>(m_ptr[0] << 8 | m_ptr[1])};
const auto* name_ptr{reinterpret_cast<const char*>(std::next(m_ptr, 2))};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we name this constants somehow to show what offsets they represent?

return *this;
}

group_name_iterator operator++(int) noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add // NOLINT here


struct group_name {
std::string_view name;
size_t index;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add default initializers to all members of primitive types

size_t& buffer_len, uint32_t match_options, pcre2_match_context_8* ctx = nullptr) const noexcept;

private:
explicit regex(pcre2_code_8& code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think it's safer to pass regex_pcre2_code_t here. Thus, it's explicit that we accept a managed object
  2. Please, add noexcept to all functions

private:
explicit regex(pcre2_code_8& code)
: m_code{std::addressof(code), pcre2_code_free_8} {}
regex_pcre2_code_t m_code;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's better for readability to move those types into kphp::pcre2 namespace. For example, it could be kphp::pcre2::code

public:
friend class matcher;

static std::expected<regex, compile_error> compile(std::string_view pattern, uint32_t options = 0, pcre2_compile_context_8* ctx = nullptr) noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need the ctx = nullptr case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

k2 k2 related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants