Skip to content

Commit

Permalink
Simplify match_url code.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Aug 20, 2022
1 parent 0d2ddc2 commit 4206246
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
17 changes: 3 additions & 14 deletions td/telegram/MessageEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,23 +748,12 @@ static vector<Slice> match_urls(Slice str) {

const unsigned char *last_at_ptr = nullptr;
const unsigned char *domain_end_ptr = begin + dot_pos;
if (domain_begin_ptr == begin || domain_begin_ptr[-1] != '@') {
// try to find '@' to the right if there is no '@' to the left
while (domain_end_ptr != end) {
uint32 code = 0;
auto next_ptr = next_utf8_unsafe(domain_end_ptr, &code);
if (code == '@') {
last_at_ptr = domain_end_ptr;
} else if (!is_domain_symbol(code)) {
break;
}
domain_end_ptr = next_ptr;
}
}
while (domain_end_ptr != end) {
uint32 code = 0;
auto next_ptr = next_utf8_unsafe(domain_end_ptr, &code);
if (!is_domain_symbol(code)) {
if (code == '@') {
last_at_ptr = domain_end_ptr;
} else if (!is_domain_symbol(code)) {
break;
}
domain_end_ptr = next_ptr;
Expand Down
1 change: 1 addition & 0 deletions test/message_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ TEST(MessageEntities, url) {
check_url("http://test―‑@―google―.―com―/―–―‐―/―/―/―?―‑―#―――", {"http://test―‑@―google―.―com―/―–―‐―/―/―/―?―‑―#―――"});
check_url("http://google.com/‖", {"http://google.com/"});
check_url("a@[email protected]", {}, {});
check_url("[email protected]@d.com", {});
check_url("[email protected]:c@1", {}, {"[email protected]"});
check_url("[email protected]", {}, {"[email protected]"});
check_url("a:[email protected]", {});
Expand Down

0 comments on commit 4206246

Please sign in to comment.