Skip to content

Commit

Permalink
more trying to get the iterator/pointer stuff right in a cross platfo…
Browse files Browse the repository at this point in the history
…rm way
  • Loading branch information
eteran committed Jan 11, 2025
1 parent 98ca392 commit 3109e5e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions Util/include/Util/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ void moveItem(Cont &cont, int from, int to) {
QT_WARNING_POP

// string_view algorithms
template <class Ch, class Tr = std::char_traits<Ch>>
constexpr std::basic_string_view<Ch, Tr> substr(const Ch *first, const Ch *last) {
template <class Iter>
constexpr auto substr(Iter start, Iter end) {

const Ch *data = first;
auto size = std::distance(first, last);
return std::basic_string_view<Ch, Tr>(data, static_cast<size_t>(size));
using Ch = typename std::iterator_traits<Iter>::value_type;

const Ch *first = &*start;
const Ch *last = &*end;
auto size = std::distance(first, last);
return std::basic_string_view<Ch>(first, static_cast<size_t>(size));
}

template <class Cont, class T, class Pred>
Expand Down
2 changes: 1 addition & 1 deletion src/Highlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ bool parseString(const HighlightData *pattern, const char *&string_ptr, uint8_t
delimitersPtr,
look_behind_to,
match_to,
ctx->text.end())) {
end_ptr)) {
qCritical("NEdit: Internal error, failed to recover start match in parseString");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gap_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <algorithm>
#include <cassert>
#include <exception>
#include <memory>
#include <stdexcept>
#include <string>
#include <string_view>

Expand Down
4 changes: 3 additions & 1 deletion src/shift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,9 @@ std::string shiftText(std::string_view text, ShiftDirection direction, int tabsA

auto segment = substr(lineStartPtr, text.end());

std::string shiftedLineString = (direction == ShiftDirection::Right) ? shiftLineRight(segment, textPtr - lineStartPtr, tabsAllowed, tabDist, nChars) : shiftLineLeft(segment, textPtr - lineStartPtr, tabDist, nChars);
std::string shiftedLineString = (direction == ShiftDirection::Right)
? shiftLineRight(segment, textPtr - lineStartPtr, tabsAllowed, tabDist, nChars)
: shiftLineLeft(segment, textPtr - lineStartPtr, tabDist, nChars);

std::copy(shiftedLineString.begin(), shiftedLineString.end(), shiftedPtr);

Expand Down

0 comments on commit 3109e5e

Please sign in to comment.