Skip to content

Commit 4bf7886

Browse files
committed
Separate find_newline function
1 parent f9e0c41 commit 4bf7886

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

src/java_symbols.hpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,25 @@ inline bool name_matches(std::string_view name, std::span<const Named_regex> pat
418418
return false;
419419
}
420420

421+
/*!
422+
* Iterates over @p content to find newline starting from position @p pos.
423+
*
424+
* @return The position of the newline or `-1` if not found.
425+
*/
426+
inline std::ptrdiff_t find_newline(std::string_view content, std::ptrdiff_t pos)
427+
{
428+
while (pos != std::ssize(content) and std::isspace(static_cast<unsigned char>(content[pos])))
429+
{
430+
if (content[pos] == '\n')
431+
{
432+
return pos;
433+
}
434+
++pos;
435+
}
436+
437+
return -1;
438+
}
439+
421440
/*!
422441
* Iterates over @p content to remove all import statements provided
423442
* as @p patterns and @p names. Patterns match the string representation
@@ -472,20 +491,9 @@ inline std::tuple<std::string, String_map> remove_imports(
472491
std::tie(symbol, end_pos) = next_symbol(content, end_pos);
473492
}
474493

475-
// Skip whitespace until one newline but only if a newline is found
494+
if (auto skip_space = find_newline(content, end_pos); skip_space != -1)
476495
{
477-
auto skip_space = end_pos;
478-
479-
while (skip_space != std::ssize(content) and std::isspace(static_cast<unsigned char>(content[skip_space])))
480-
{
481-
++skip_space;
482-
483-
if (content[skip_space - 1] == '\n')
484-
{
485-
end_pos = skip_space;
486-
break;
487-
}
488-
}
496+
end_pos = skip_space + 1;
489497
}
490498

491499
copy_end = end_pos;

0 commit comments

Comments
 (0)