Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Check for hyphenated double names. v0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
HackTheOxidation committed Apr 24, 2023
1 parent e58b79d commit 136ca5d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)

project(OS2DSRules VERSION 0.0.4)
project(OS2DSRules VERSION 0.0.5)

# Detect available compiler on the host system.
set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
Expand Down
5 changes: 2 additions & 3 deletions lib/name_rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <array>
#include <string_view>

#include <os2dsrules.hpp>
#include <data_structures.hpp>
#include <name_rule.hpp>

Expand Down Expand Up @@ -34,9 +35,7 @@ MatchResult compose(const MatchResult &mr1, const MatchResult &mr2) noexcept {
NameRule::find_matches(const std::string &content) const noexcept {
MatchResults results;

static const auto is_end_of_word = [](char c) {
return c == '.' || c == ' ' || c == '\n' || c == '\0';
};
static constexpr auto is_end_of_word = make_predicate(' ', '.', '\n', '?', '-', '\t','\0');

bool in_word = false;
auto word_begin = content.cbegin();
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "os2ds-rules"
version = "0.0.4"
version = "0.0.5"
authors = [
{ name="HackTheOxidation", email="[email protected]" },
]
Expand Down
10 changes: 10 additions & 0 deletions tests/testname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ TEST_F(NameRuleTest, Test_Double_Name_Single_Match) {
ASSERT_EQ(9, results[0].end());
}

TEST_F(NameRuleTest, Test_Double_Hyphenated_Name_Single_Match) {
NameRule rule;
auto results = rule.find_matches("John-Peter");

ASSERT_EQ(1, results.size());
ASSERT_EQ(std::string("John Peter"), results[0].match());
ASSERT_EQ(0, results[0].start());
ASSERT_EQ(9, results[0].end());
}

TEST_F(NameRuleTest, Test_Double_Name_Single_Name_Two_Matches) {
NameRule rule;
auto results = rule.find_matches("John Peter is usually just called John.");
Expand Down

0 comments on commit 136ca5d

Please sign in to comment.