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
9 changes: 5 additions & 4 deletions src/escape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ std::string unescape(string_view in)
auto rit = std::regex_iterator<string_view::const_iterator>{ in.cbegin(), in.cend(), re };
auto const rend = std::regex_iterator<string_view::const_iterator>{ };
auto last = decltype(*rit){ };

if (rit == rend)
return std::string{ in };

auto unescaped = ""s;
unescaped.reserve(in.length());

if (rit == rend) {
unescaped.assign(in.data(), in.size());
return unescaped;
}

for (; rit != rend; ++rit) {
last = *rit;
unescaped += rit->prefix();
Expand Down
3 changes: 3 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ endif
if meson.get_compiler('cpp').has_argument('-Wconversion') # msvc doesnt have
add_cpp_args += [ '-Wconversion' ]
endif
if meson.get_compiler('cpp').has_argument('-Wnrvo') # msvc: included in permissive-
add_cpp_args += [ '-Wnrvo' ]
endif

deps = dependency('threads')

Expand Down
7 changes: 4 additions & 3 deletions src/replace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ namespace gul14 {

std::string replace(string_view haystack, string_view needle, string_view hammer)
{
if (needle.empty())
return std::string(haystack);

auto result = ""s;
result.reserve(haystack.length());
if (needle.empty()) {
result.assign(haystack.data(), haystack.length());
return result;
}

std::size_t pos = 0;
std::size_t last_pos = 0;
Expand Down
Loading