diff --git a/Interpreter/DataValue.h b/Interpreter/DataValue.h index 31e20df3..69133784 100644 --- a/Interpreter/DataValue.h +++ b/Interpreter/DataValue.h @@ -2,7 +2,7 @@ #ifndef DATA_VALUE_H_ #define DATA_VALUE_H_ -#include "Util/string_view.h" +#include #include @@ -87,9 +87,9 @@ inline DataValue make_value(bool n) { return DV; } -inline DataValue make_value(view::string_view str) { +inline DataValue make_value(std::string_view str) { DataValue DV; - DV.value = str.to_string(); + DV.value = std::string(str); return DV; } diff --git a/Interpreter/interpret.cpp b/Interpreter/interpret.cpp index 66468bf2..b4028372 100644 --- a/Interpreter/interpret.cpp +++ b/Interpreter/interpret.cpp @@ -688,7 +688,7 @@ Symbol *InstallIteratorSymbol() { /* ** Lookup a constant string by its value. */ -Symbol *LookupStringConstSymbol(view::string_view value) { +Symbol *LookupStringConstSymbol(std::string_view value) { auto it = std::find_if(GlobalSymList.begin(), GlobalSymList.end(), [value](Symbol *s) { return (s->type == CONST_SYM && is_string(s->value) && to_string(s->value) == value); @@ -708,7 +708,7 @@ Symbol *InstallStringConstSymbolEx(const QString &str) { /* ** install string str in the global symbol table with a string name */ -Symbol *InstallStringConstSymbol(view::string_view str) { +Symbol *InstallStringConstSymbol(std::string_view str) { static int stringConstIndex = 0; @@ -729,7 +729,7 @@ Symbol *LookupSymbolEx(const QString &name) { return LookupSymbol(name.toStdString()); } -Symbol *LookupSymbol(view::string_view name) { +Symbol *LookupSymbol(std::string_view name) { // first look for a local symbol auto local = std::find_if(LocalSymList.begin(), LocalSymList.end(), [name](Symbol *s) { @@ -835,9 +835,9 @@ Symbol *PromoteToGlobal(Symbol *sym) { *Context.StackP++ = (dataVal); \ } while (0) -#define PEEK(dataVal, peekIndex) \ - do { \ - (dataVal) = *(Context.StackP - (peekIndex)-1); \ +#define PEEK(dataVal, peekIndex) \ + do { \ + (dataVal) = *(Context.StackP - (peekIndex) - 1); \ } while (0) #define POP_INT(number) \ diff --git a/Interpreter/interpret.h b/Interpreter/interpret.h index 55ccec50..3c3d62ce 100644 --- a/Interpreter/interpret.h +++ b/Interpreter/interpret.h @@ -3,7 +3,7 @@ #define INTERPRET_H_ #include "DataValue.h" -#include "Util/string_view.h" +#include #include @@ -144,13 +144,13 @@ bool AddSym(Symbol *sym, QString *msg); Inst *GetPC(); Program *FinishCreatingProgram(); Symbol *InstallIteratorSymbol(); -Symbol *InstallStringConstSymbol(view::string_view str); +Symbol *InstallStringConstSymbol(std::string_view str); Symbol *InstallStringConstSymbolEx(const QString &str); Symbol *InstallSymbol(const std::string &name, SymTypes type, const DataValue &value); Symbol *InstallSymbolEx(const QString &name, enum SymTypes type, const DataValue &value); -Symbol *LookupStringConstSymbol(view::string_view value); +Symbol *LookupStringConstSymbol(std::string_view value); Symbol *LookupSymbolEx(const QString &name); -Symbol *LookupSymbol(view::string_view name); +Symbol *LookupSymbol(std::string_view name); void BeginCreatingProgram(); void FillLoopAddrs(const Inst *breakAddr, const Inst *continueAddr); void StartLoopAddrList(); diff --git a/Regex/Common.h b/Regex/Common.h index 55dbe44e..d2dd6818 100644 --- a/Regex/Common.h +++ b/Regex/Common.h @@ -70,8 +70,8 @@ constexpr R literal_escape(Ch ch) noexcept { * octal escape. RegexError is thrown if \x0, \x00, \0, \00, \000, or * \0000 is specified. *--------------------------------------------------------------------*/ -template -R numeric_escape(Ch ch, const char **parse) { +template +R numeric_escape(Ch ch, Iterator *parse) { static const char digits[] = "fedcbaFEDCBA9876543210"; @@ -105,7 +105,7 @@ R numeric_escape(Ch ch, const char **parse) { return '\0'; // Not a numeric escape } - const char *scan = *parse; + Iterator scan = *parse; scan++; // Only change *parse on success. const char *pos_ptr = ::strchr(digit_str, static_cast(*scan)); diff --git a/Regex/Compile.cpp b/Regex/Compile.cpp index 8052fb47..8509fd74 100644 --- a/Regex/Compile.cpp +++ b/Regex/Compile.cpp @@ -13,14 +13,13 @@ #include #include #include -#include #include +#include namespace { const auto FirstPassToken = reinterpret_cast(1); - // Flags for function shortcut_escape() enum ShortcutEscapeFlag { CHECK_ESCAPE = 0, // Check an escape sequence for validity only. @@ -255,10 +254,10 @@ uint8_t *emit_special(Ch op_code, uint32_t test_val, size_t index) noexcept { case TEST_COUNT: pContext.Reg_Size += NEXT_PTR_SIZE; // Make room for a test value. - NEDIT_FALLTHROUGH(); + [[fallthrough]]; case INC_COUNT: pContext.Reg_Size += INDEX_SIZE; // Make room for an index value. - NEDIT_FALLTHROUGH(); + [[fallthrough]]; default: pContext.Reg_Size += NODE_SIZE; // Make room for the node. } @@ -411,7 +410,7 @@ uint8_t *shortcut_escape(Ch ch, int *flag_param) { auto ret_val = FirstPassToken; // Assume success. const char *valid_codes; - if (Flags == EMIT_CLASS_BYTES || Flags == CHECK_CLASS_ESCAPE) { + if constexpr (Flags == EMIT_CLASS_BYTES || Flags == CHECK_CLASS_ESCAPE) { valid_codes = codes + 3; // \B, \y and \Y are not allowed in classes } else { valid_codes = codes; @@ -421,14 +420,14 @@ uint8_t *shortcut_escape(Ch ch, int *flag_param) { return nullptr; // Not a valid shortcut escape sequence } - if (Flags == CHECK_ESCAPE || Flags == CHECK_CLASS_ESCAPE) { + if constexpr (Flags == CHECK_ESCAPE || Flags == CHECK_CLASS_ESCAPE) { return ret_val; // Just checking if this is a valid shortcut escape. } switch (ch) { case 'd': case 'D': - if (Flags == EMIT_CLASS_BYTES) { + if constexpr (Flags == EMIT_CLASS_BYTES) { clazz = ASCII_Digits; } else if (Flags == EMIT_NODE) { ret_val = (safe_islower(ch) ? emit_node(DIGIT) : emit_node(NOT_DIGIT)); @@ -436,21 +435,21 @@ uint8_t *shortcut_escape(Ch ch, int *flag_param) { break; case 'l': case 'L': - if (Flags == EMIT_CLASS_BYTES) { + if constexpr (Flags == EMIT_CLASS_BYTES) { clazz = Letter_Char; - } else if (Flags == EMIT_NODE) { + } else if constexpr (Flags == EMIT_NODE) { ret_val = (safe_islower(ch) ? emit_node(LETTER) : emit_node(NOT_LETTER)); } break; case 's': case 'S': - if (Flags == EMIT_CLASS_BYTES) { + if constexpr (Flags == EMIT_CLASS_BYTES) { if (pContext.Match_Newline) { emit_byte('\n'); } clazz = White_Space; - } else if (Flags == EMIT_NODE) { + } else if constexpr (Flags == EMIT_NODE) { if (pContext.Match_Newline) { ret_val = (safe_islower(ch) ? emit_node(SPACE_NL) : emit_node(NOT_SPACE_NL)); } else { @@ -460,7 +459,7 @@ uint8_t *shortcut_escape(Ch ch, int *flag_param) { break; case 'w': case 'W': - if (Flags == EMIT_CLASS_BYTES) { + if constexpr (Flags == EMIT_CLASS_BYTES) { clazz = Word_Char; } else if (Flags == EMIT_NODE) { ret_val = (safe_islower(ch) ? emit_node(WORD_CHAR) : emit_node(NOT_WORD_CHAR)); @@ -471,7 +470,7 @@ uint8_t *shortcut_escape(Ch ch, int *flag_param) { * \B, \Y and \Y can only generate a node. At run time, the delimiter * table will be available for these nodes to use. */ case 'y': - if (Flags == EMIT_NODE) { + if constexpr (Flags == EMIT_NODE) { ret_val = emit_node(IS_DELIM); } else { Raise("internal error #5 'shortcut_escape'"); @@ -479,14 +478,14 @@ uint8_t *shortcut_escape(Ch ch, int *flag_param) { break; case 'Y': - if (Flags == EMIT_NODE) { + if constexpr (Flags == EMIT_NODE) { ret_val = emit_node(NOT_DELIM); } else { Raise("internal error #6 'shortcut_escape'"); } break; case 'B': - if (Flags == EMIT_NODE) { + if constexpr (Flags == EMIT_NODE) { ret_val = emit_node(NOT_BOUNDARY); } else { Raise("internal error #7 'shortcut_escape'"); @@ -558,7 +557,7 @@ void branch_tail(uint8_t *ptr, int offset, uint8_t *val) { * text previously matched by another regex. *** IMPLEMENT LATER *** *--------------------------------------------------------------------*/ template -uint8_t *back_ref(const char *ch, int *flag_param) { +uint8_t *back_ref(std::string_view::iterator ch, int *flag_param) { size_t c_offset = 0; const bool is_cross_regex = false; @@ -589,7 +588,7 @@ uint8_t *back_ref(const char *ch, int *flag_param) { Raise("\\%d is an illegal back reference", paren_no); } - if (Flags == EMIT_NODE) { + if constexpr (Flags == EMIT_NODE) { if (is_cross_regex) { ++pContext.Reg_Parse; /* Skip past the '~' in a cross regex back * reference. We only do this if we are emitting code. */ @@ -612,7 +611,7 @@ uint8_t *back_ref(const char *ch, int *flag_param) { if (is_cross_regex || pContext.Paren_Has_Width[paren_no]) { *flag_param |= HAS_WIDTH; } - } else if (Flags == CHECK_ESCAPE) { + } else if constexpr (Flags == CHECK_ESCAPE) { ret_val = FirstPassToken; } else { ret_val = nullptr; @@ -960,12 +959,12 @@ uint8_t *atom(int *flag_param, len_range &range_param) { /* Fall through to Default case to handle literal escapes and numeric * escapes. */ - NEDIT_FALLTHROUGH(); + [[fallthrough]]; default: --pContext.Reg_Parse; /* If we fell through from the above code, we are now * pointing at the back slash (\) character. */ { - const char *parse_save; + std::string_view::iterator parse_save; int len = 0; if (pContext.Is_Case_Insensitive) { @@ -1286,13 +1285,13 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(NOTHING); // 2,3 offset_tail(ret_val, NODE_SIZE, next); // 2 - tail(ret_val, next); // 3 - insert(BRANCH, ret_val, 0UL, 0UL, 0); // 4,5 + tail(ret_val, next); // 3 + insert(BRANCH, ret_val, 0UL, 0UL, 0); // 4,5 tail(ret_val, ret_val + (2 * NODE_SIZE)); // 4 offset_tail(ret_val, 3 * NODE_SIZE, ret_val); // 5 if (op_code == '+') { - insert(NOTHING, ret_val, 0UL, 0UL, 0); // 6 + insert(NOTHING, ret_val, 0UL, 0UL, 0); // 6 tail(ret_val, ret_val + (4 * NODE_SIZE)); // 6 } } else if (op_code == '*') { @@ -1304,11 +1303,11 @@ uint8_t *piece(int *flag_param, len_range &range_param) { * \__3_______| 4 */ - insert(BRANCH, ret_val, 0UL, 0UL, 0); // 1,3 + insert(BRANCH, ret_val, 0UL, 0UL, 0); // 1,3 offset_tail(ret_val, NODE_SIZE, emit_node(BACK)); // 2 offset_tail(ret_val, NODE_SIZE, ret_val); // 1 - tail(ret_val, emit_node(BRANCH)); // 3 - tail(ret_val, emit_node(NOTHING)); // 4 + tail(ret_val, emit_node(BRANCH)); // 3 + tail(ret_val, emit_node(NOTHING)); // 4 } else if (op_code == '+') { /* Node structure for (x)+ construct. * @@ -1341,8 +1340,8 @@ uint8_t *piece(int *flag_param, len_range &range_param) { offset_tail(ret_val, 2 * NODE_SIZE, next); // 1 offset_tail(ret_val, NODE_SIZE, next); // 2 - tail(ret_val, next); // 3 - insert(BRANCH, ret_val, 0UL, 0UL, 0); // 4 + tail(ret_val, next); // 3 + insert(BRANCH, ret_val, 0UL, 0UL, 0); // 4 tail(ret_val, (ret_val + (2 * NODE_SIZE))); // 4 } else if (op_code == '?') { @@ -1358,7 +1357,7 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(NOTHING); // 2,3 - tail(ret_val, next); // 2 + tail(ret_val, next); // 2 offset_tail(ret_val, NODE_SIZE, next); // 3 } else if (op_code == '{' && min_max[0] == min_max[1]) { /* Node structure for (x){m}, (x){m}?, (x){m,m}, or (x){m,m}? constructs. @@ -1403,7 +1402,7 @@ uint8_t *piece(int *flag_param, len_range &range_param) { insert(NOTHING, ret_val, 0UL, 0UL, pContext.Num_Braces); // 5 insert(BRANCH, ret_val, 0UL, 0UL, pContext.Num_Braces); // 3,4,8 tail(emit_node(BACK), ret_val); // 3 - tail(ret_val, ret_val + (2 * NODE_SIZE)); // 4 + tail(ret_val, ret_val + (2 * NODE_SIZE)); // 4 next = emit_node(NOTHING); // 5,6,7 @@ -1439,13 +1438,13 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(NOTHING); // 5,6 - offset_tail(ret_val, NODE_SIZE, next); // 5 - tail(ret_val, next); // 6 - insert(BRANCH, ret_val, 0UL, 0UL, 0); // 7,8 - tail(ret_val, ret_val + (2 * NODE_SIZE)); // 7 - offset_tail(ret_val, 3 * NODE_SIZE, ret_val); // 8 - insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 9 - tail(ret_val, ret_val + INDEX_SIZE + (4 * NODE_SIZE)); // 9 + offset_tail(ret_val, NODE_SIZE, next); // 5 + tail(ret_val, next); // 6 + insert(BRANCH, ret_val, 0UL, 0UL, 0); // 7,8 + tail(ret_val, ret_val + (2 * NODE_SIZE)); // 7 + offset_tail(ret_val, 3 * NODE_SIZE, ret_val); // 8 + insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 9 + tail(ret_val, ret_val + INDEX_SIZE + (4 * NODE_SIZE)); // 9 } else { /* Node structure for (x){m,n}? construct. @@ -1476,13 +1475,13 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(NOTHING); // 5,6,7 - offset_tail(ret_val, NODE_SIZE, next); // 5 - offset_tail(ret_val, 2 * NODE_SIZE, next); // 6 - offset_tail(ret_val, 3 * NODE_SIZE, next); // 7 - tail(ret_val, ret_val + (2 * NODE_SIZE)); // 8 - offset_tail(next, -NODE_SIZE, ret_val); // 9 - insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 10 - tail(ret_val, ret_val + INDEX_SIZE + (4 * NODE_SIZE)); // 10 + offset_tail(ret_val, NODE_SIZE, next); // 5 + offset_tail(ret_val, 2 * NODE_SIZE, next); // 6 + offset_tail(ret_val, 3 * NODE_SIZE, next); // 7 + tail(ret_val, ret_val + (2 * NODE_SIZE)); // 8 + offset_tail(next, -NODE_SIZE, ret_val); // 9 + insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 10 + tail(ret_val, ret_val + INDEX_SIZE + (4 * NODE_SIZE)); // 10 } pContext.Num_Braces++; @@ -1508,8 +1507,8 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(BRANCH); // 4,5 - tail(ret_val, next); // 4 - tail(next, emit_node(NOTHING)); // 5,6 + tail(ret_val, next); // 4 + tail(next, emit_node(NOTHING)); // 5,6 offset_tail(ret_val, NODE_SIZE, next); // 6 next = insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 7 @@ -1537,10 +1536,10 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(BACK); // 4 - tail(next, ret_val); // 4 + tail(next, ret_val); // 4 offset_tail(ret_val, NODE_SIZE, next); // 5 - tail(ret_val, emit_node(BRANCH)); // 6 - tail(ret_val, emit_node(NOTHING)); // 7 + tail(ret_val, emit_node(BRANCH)); // 6 + tail(ret_val, emit_node(NOTHING)); // 7 insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 8 @@ -1572,16 +1571,16 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(BRANCH); // 5,8 - tail(ret_val, next); // 5 + tail(ret_val, next); // 5 offset_tail(next, -NODE_SIZE, ret_val); // 6 next = emit_node(NOTHING); // 7,8 offset_tail(ret_val, NODE_SIZE, next); // 7 - offset_tail(next, -NODE_SIZE, next); // 8 - insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 9 - tail(ret_val, ret_val + INDEX_SIZE + (2 * NODE_SIZE)); // 9 + offset_tail(next, -NODE_SIZE, next); // 8 + insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 9 + tail(ret_val, ret_val + INDEX_SIZE + (2 * NODE_SIZE)); // 9 } pContext.Num_Braces++; @@ -1881,7 +1880,7 @@ uint8_t *chunk(int paren, int *flag_param, len_range &range_param) { * Beware that the optimization and preparation code in here knows about * some of the structure of the compiled Regex. *----------------------------------------------------------------------*/ -Regex::Regex(view::string_view exp, int defaultFlags) { +Regex::Regex(std::string_view exp, int defaultFlags) { Regex *const re = this; diff --git a/Regex/Compile.h b/Regex/Compile.h index 2963ca13..36da8969 100644 --- a/Regex/Compile.h +++ b/Regex/Compile.h @@ -2,16 +2,17 @@ #ifndef COMPILE_H_ #define COMPILE_H_ -#include "Util/string_view.h" #include +#include +#include #include class Regex; // Global work variables for 'CompileRE'. struct ParseContext { - view::string_view::iterator Reg_Parse; // Input scan ptr (scans user's regex) - view::string_view InputString; + std::string_view::iterator Reg_Parse; // Input scan ptr (scans user's regex) + std::string_view InputString; std::vector Code; const char *Meta_Char; size_t Reg_Size; // Size of compiled regex code. diff --git a/Regex/Decompile.cpp b/Regex/Decompile.cpp index ca6195fc..865eb89c 100644 --- a/Regex/Decompile.cpp +++ b/Regex/Decompile.cpp @@ -1,6 +1,7 @@ #include "Decompile.h" #include "Regex.h" +#include namespace { diff --git a/Regex/Decompile.h b/Regex/Decompile.h index f9b1d6d4..783b239f 100644 --- a/Regex/Decompile.h +++ b/Regex/Decompile.h @@ -3,8 +3,8 @@ #define DECOMPILE_H_ #include "Opcodes.h" -#include #include +#include #include class Regex; diff --git a/Regex/Execute.cpp b/Regex/Execute.cpp index 4ebb71dc..60b0b5d1 100644 --- a/Regex/Execute.cpp +++ b/Regex/Execute.cpp @@ -596,7 +596,7 @@ bool match(uint8_t *prog, size_t *branch_index_param) { switch (GET_OP_CODE(scan)) { case LAZY_STAR: lazy = true; - NEDIT_FALLTHROUGH(); + [[fallthrough]]; case STAR: min = 0; max = std::numeric_limits::max(); @@ -604,7 +604,7 @@ bool match(uint8_t *prog, size_t *branch_index_param) { case LAZY_PLUS: lazy = true; - NEDIT_FALLTHROUGH(); + [[fallthrough]]; case PLUS: min = 1; max = std::numeric_limits::max(); @@ -612,7 +612,7 @@ bool match(uint8_t *prog, size_t *branch_index_param) { case LAZY_QUESTION: lazy = true; - NEDIT_FALLTHROUGH(); + [[fallthrough]]; case QUESTION: min = 0; max = 1; @@ -620,7 +620,7 @@ bool match(uint8_t *prog, size_t *branch_index_param) { case LAZY_BRACE: lazy = true; - NEDIT_FALLTHROUGH(); + [[fallthrough]]; case BRACE: min = static_cast(GET_OFFSET(scan + NEXT_PTR_SIZE)); max = static_cast(GET_OFFSET(scan + (2 * NEXT_PTR_SIZE))); diff --git a/Regex/Execute.h b/Regex/Execute.h index 2c37cc45..fb68203f 100644 --- a/Regex/Execute.h +++ b/Regex/Execute.h @@ -3,12 +3,12 @@ #define EXECUTE_H_ #include "Constants.h" -#include "Util/string_view.h" #include #include #include -#include #include +#include +#include // #define ENABLE_CROSS_REGEX_BACKREF diff --git a/Regex/Regex.cpp b/Regex/Regex.cpp index c1287986..a6521c22 100644 --- a/Regex/Regex.cpp +++ b/Regex/Regex.cpp @@ -115,7 +115,7 @@ ParseContext pContext; * @param reverse * @return */ -bool Regex::execute(view::string_view string, bool reverse) { +bool Regex::execute(std::string_view string, bool reverse) { return execute(string, 0, reverse); } @@ -126,7 +126,7 @@ bool Regex::execute(view::string_view string, bool reverse) { * @param reverse * @return */ -bool Regex::execute(view::string_view string, size_t offset, bool reverse) { +bool Regex::execute(std::string_view string, size_t offset, bool reverse) { return execute(string, offset, nullptr, reverse); } @@ -138,7 +138,7 @@ bool Regex::execute(view::string_view string, size_t offset, bool reverse) { * @param reverse * @return */ -bool Regex::execute(view::string_view string, size_t offset, const char *delimiters, bool reverse) { +bool Regex::execute(std::string_view string, size_t offset, const char *delimiters, bool reverse) { return execute(string, offset, string.size(), delimiters, reverse); } @@ -151,7 +151,7 @@ bool Regex::execute(view::string_view string, size_t offset, const char *delimit * @param reverse * @return */ -bool Regex::execute(view::string_view string, size_t offset, size_t end_offset, const char *delimiters, bool reverse) { +bool Regex::execute(std::string_view string, size_t offset, size_t end_offset, const char *delimiters, bool reverse) { return execute( string, offset, @@ -173,7 +173,7 @@ bool Regex::execute(view::string_view string, size_t offset, size_t end_offset, * @param reverse * @return */ -bool Regex::execute(view::string_view string, size_t offset, size_t end_offset, int prev, int succ, const char *delimiters, bool reverse) { +bool Regex::execute(std::string_view string, size_t offset, size_t end_offset, int prev, int succ, const char *delimiters, bool reverse) { assert(offset <= end_offset); assert(end_offset <= string.size()); return ExecRE( @@ -193,7 +193,7 @@ bool Regex::execute(view::string_view string, size_t offset, size_t end_offset, * * Builds a default delimiter table that persists across 'ExecRE' calls. *----------------------------------------------------------------------*/ -void Regex::SetDefaultWordDelimiters(view::string_view delimiters) { +void Regex::SetDefaultWordDelimiters(std::string_view delimiters) { Default_Delimiters = makeDelimiterTable(delimiters); } @@ -204,7 +204,7 @@ void Regex::SetDefaultWordDelimiters(view::string_view delimiters) { * lookup table for determining whether a character is a delimiter or * not. *----------------------------------------------------------------------*/ -std::bitset<256> Regex::makeDelimiterTable(view::string_view delimiters) { +std::bitset<256> Regex::makeDelimiterTable(std::string_view delimiters) { std::bitset<256> table; diff --git a/Regex/Regex.h b/Regex/Regex.h index 4e03d8a9..114d7d37 100644 --- a/Regex/Regex.h +++ b/Regex/Regex.h @@ -4,7 +4,7 @@ #include "Constants.h" #include "RegexError.h" -#include "Util/string_view.h" +#include #include #include @@ -21,7 +21,7 @@ enum RE_DEFAULT_FLAG { class Regex { public: - Regex(view::string_view exp, int defaultFlags); + Regex(std::string_view exp, int defaultFlags); Regex(const Regex &) = delete; Regex &operator=(const Regex &) = delete; ~Regex() = default; @@ -47,7 +47,7 @@ class Regex { * @param string Text to search within * @param reverse Backward search. */ - bool execute(view::string_view string, bool reverse = false); + bool execute(std::string_view string, bool reverse = false); /** * Match a 'Regex' structure against a string. @@ -57,7 +57,7 @@ class Regex { * @param offset Offset into the string to begin search * @param reverse Backward search. */ - bool execute(view::string_view string, size_t offset, bool reverse = false); + bool execute(std::string_view string, size_t offset, bool reverse = false); /** * Match a 'Regex' structure against a string. @@ -68,7 +68,7 @@ class Regex { * @param delimiters Word delimiters to use (nullptr for default) * @param reverse Backward search. */ - bool execute(view::string_view string, size_t offset, const char *delimiters, bool reverse = false); + bool execute(std::string_view string, size_t offset, const char *delimiters, bool reverse = false); /** * Match a 'Regex' structure against a string. Will only match things between offset and end_offset @@ -80,7 +80,7 @@ class Regex { * @param delimiters Word delimiters to use (nullptr for default) * @param reverse Backward search. */ - bool execute(view::string_view string, size_t offset, size_t end_offset, const char *delimiters, bool reverse = false); + bool execute(std::string_view string, size_t offset, size_t end_offset, const char *delimiters, bool reverse = false); /** * Match a 'Regex' structure against a string. Will only match things between offset and end_offset @@ -94,7 +94,7 @@ class Regex { * @param succ Character immediately after 'end'. Set to '\n' or -1 if true beginning of text. * @param reverse Backward search. */ - bool execute(view::string_view string, size_t offset, size_t end_offset, int prev, int succ, const char *delimiters, bool reverse = false); + bool execute(std::string_view string, size_t offset, size_t end_offset, int prev, int succ, const char *delimiters, bool reverse = false); /** * Perform substitutions after a 'Regex' match. @@ -104,7 +104,7 @@ class Regex { * @param dest * @return */ - bool SubstituteRE(view::string_view source, std::string &dest) const; + bool SubstituteRE(std::string_view source, std::string &dest) const; /** * @brief isValid @@ -115,7 +115,7 @@ class Regex { public: /* Builds a default delimiter table that persists across 'ExecRE' calls that is identical to 'delimiters'.*/ - static void SetDefaultWordDelimiters(view::string_view delimiters); + static void SetDefaultWordDelimiters(std::string_view delimiters); public: std::array startp = {}; /* Captured text starting locations. */ @@ -129,7 +129,7 @@ class Regex { public: static std::bitset<256> Default_Delimiters; - static std::bitset<256> makeDelimiterTable(view::string_view delimiters); + static std::bitset<256> makeDelimiterTable(std::string_view delimiters); }; #endif diff --git a/Regex/Substitute.cpp b/Regex/Substitute.cpp index b7616b84..aa361316 100644 --- a/Regex/Substitute.cpp +++ b/Regex/Substitute.cpp @@ -5,11 +5,12 @@ #include "Util/utils.h" #include +#include /* ** SubstituteRE - Perform substitutions after a 'Regex' match. */ -bool Regex::SubstituteRE(view::string_view source, std::string &dest) const { +bool Regex::SubstituteRE(std::string_view source, std::string &dest) const { constexpr auto InvalidParenNumber = static_cast(-1); @@ -73,8 +74,8 @@ bool Regex::SubstituteRE(view::string_view source, std::string &dest) const { ch = '\\'; } else { ch = *in++; // Allow any escape sequence (This is - } // INCONSISTENT with the 'CompileRE' - } // mind set of issuing an error! + } // INCONSISTENT with the 'CompileRE' + } // mind set of issuing an error! if (paren_no == InvalidParenNumber) { // Ordinary character. *out++ = ch; diff --git a/Regex/test/Test.cpp b/Regex/test/Test.cpp index 95f02d37..5a398ab1 100644 --- a/Regex/test/Test.cpp +++ b/Regex/test/Test.cpp @@ -6,11 +6,11 @@ namespace { struct Test { - view::string_view input; - view::string_view output; + std::string_view input; + std::string_view output; }; -int test_regex_match(view::string_view regex, view::string_view input) { +int test_regex_match(std::string_view regex, std::string_view input) { Regex re(regex, RE_DEFAULT_STANDARD); if (re.execute(input)) { @@ -737,13 +737,13 @@ int main() { } if (bytes != t.output) { - std::cerr << "ERROR : " << t.input.to_string() << '\n'; - std::cerr << "EXPECTED : " << t.output.to_string() << '\n'; + std::cerr << "ERROR : " << t.input << '\n'; + std::cerr << "EXPECTED : " << t.output << '\n'; std::cerr << "GOT : " << bytes << std::endl; return -1; } } catch (...) { - std::cerr << "EXCEPTION: " << t.input.to_string() << '\n'; + std::cerr << "EXCEPTION: " << t.input << '\n'; return -1; } } @@ -786,7 +786,7 @@ int main() { Regex re(t.input, RE_DEFAULT_STANDARD); decompileRegex(re); } catch (...) { - std::cerr << "EXCEPTION: " << t.input.to_string() << '\n'; + std::cerr << "EXCEPTION: " << t.input << '\n'; return -1; } } diff --git a/Util/CMakeLists.txt b/Util/CMakeLists.txt index 04c3eca7..1d89be55 100644 --- a/Util/CMakeLists.txt +++ b/Util/CMakeLists.txt @@ -90,7 +90,6 @@ add_library(Util include/Util/Resource.h include/Util/ServerCommon.h include/Util/String.h - include/Util/string_view.h include/Util/System.h include/Util/User.h include/Util/utils.h diff --git a/Util/FileSystem.cpp b/Util/FileSystem.cpp index d5285551..af819a76 100644 --- a/Util/FileSystem.cpp +++ b/Util/FileSystem.cpp @@ -114,7 +114,7 @@ QString GetTrailingPathComponents(const QString &path, int components) { ** the sampled portion of a Macintosh looking file), the file is judged to be ** Unix format. */ -FileFormats FormatOfFile(view::string_view text) { +FileFormats FormatOfFile(std::string_view text) { size_t nNewlines = 0; size_t nReturns = 0; diff --git a/Util/String.cpp b/Util/String.cpp index 21eb0151..e085bfaa 100644 --- a/Util/String.cpp +++ b/Util/String.cpp @@ -29,7 +29,7 @@ QString ensure_newline(const QString &string) { * @param s * @return */ -std::string to_upper(view::string_view s) { +std::string to_upper(std::string_view s) { std::string str; str.reserve(s.size()); @@ -44,7 +44,7 @@ std::string to_upper(view::string_view s) { * @param s * @return */ -std::string to_lower(view::string_view s) { +std::string to_lower(std::string_view s) { std::string str; str.reserve(s.size()); diff --git a/Util/include/Util/Compiler.h b/Util/include/Util/Compiler.h index a307b440..b5247886 100644 --- a/Util/include/Util/Compiler.h +++ b/Util/include/Util/Compiler.h @@ -2,29 +2,6 @@ #ifndef COMPILER_H_ #define COMPILER_H_ -#include - -#if __cplusplus > 202002L -#define HAS_CXX20 -#endif - -#if __cplusplus >= 201703L -#define HAS_CXX17 -#endif - -#if __cplusplus >= 201402L -#define HAS_CXX14 -#endif - -#if __cplusplus >= 201103L -#define HAS_CXX11 -#endif - -#if __cplusplus >= 199711L -#define HAS_CXX03 -#define HAS_CXX89 -#endif - #if defined(__GNUC__) #define COLD_CODE __attribute__((noinline, cold)) #define FORCE_INLINE __attribute__((always_inline)) inline @@ -35,14 +12,4 @@ #define NO_DISCARD #endif -#ifdef HAS_CXX17 -#define NEDIT_FALLTHROUGH() [[fallthrough]] -#else -#ifdef Q_FALLTHROUGH -#define NEDIT_FALLTHROUGH() Q_FALLTHROUGH() -#else -#define NEDIT_FALLTHROUGH() (void)0 -#endif -#endif - #endif diff --git a/Util/include/Util/FileSystem.h b/Util/include/Util/FileSystem.h index a77b1c97..1570d22c 100644 --- a/Util/include/Util/FileSystem.h +++ b/Util/include/Util/FileSystem.h @@ -2,11 +2,11 @@ #ifndef UTIL_FILESYSTEM_H_ #define UTIL_FILESYSTEM_H_ -#include "string_view.h" #include #include #include #include +#include enum class FileFormats : int; @@ -15,7 +15,7 @@ struct PathInfo { QString filename; }; -FileFormats FormatOfFile(view::string_view text); +FileFormats FormatOfFile(std::string_view text); QString GetTrailingPathComponents(const QString &path, int components); QString NormalizePathname(const QString &pathname); QString ReadAnyTextFile(const QString &fileName, bool forceNL); diff --git a/Util/include/Util/String.h b/Util/include/Util/String.h index c2768125..cdd23279 100644 --- a/Util/include/Util/String.h +++ b/Util/include/Util/String.h @@ -2,13 +2,13 @@ #ifndef UTIL_STRING_H_ #define UTIL_STRING_H_ -#include "Util/string_view.h" #include +#include class QString; QString ensure_newline(const QString &string); -std::string to_upper(view::string_view s); -std::string to_lower(view::string_view s); +std::string to_upper(std::string_view s); +std::string to_lower(std::string_view s); #endif diff --git a/Util/include/Util/algorithm.h b/Util/include/Util/algorithm.h index 00a55745..49c52d37 100644 --- a/Util/include/Util/algorithm.h +++ b/Util/include/Util/algorithm.h @@ -2,9 +2,11 @@ #ifndef ALGORITHM_H_ #define ALGORITHM_H_ -#include "string_view.h" #include #include +#include +#include +#include // container algorithms @@ -34,15 +36,6 @@ void moveItem(Cont &cont, int from, int to) { QT_WARNING_POP -// string_view algorithms -template > -constexpr view::basic_string_view substr(const Ch *first, const Ch *last) { - - const Ch *data = first; - auto size = std::distance(first, last); - return view::basic_string_view(data, static_cast(size)); -} - template void insert_or_replace(Cont &cont, T &&item, Pred &&pred) { @@ -54,4 +47,15 @@ void insert_or_replace(Cont &cont, T &&item, Pred &&pred) { } } +template +constexpr auto ssize(const C &c) -> std::common_type_t> { + using R = std::common_type_t>; + return static_cast(c.size()); +} + +template +constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept { + return N; +} + #endif diff --git a/Util/include/Util/string_view.h b/Util/include/Util/string_view.h deleted file mode 100644 index d5cb95d0..00000000 --- a/Util/include/Util/string_view.h +++ /dev/null @@ -1,643 +0,0 @@ - -#ifndef STRING_VIEW_H_ -#define STRING_VIEW_H_ - -#include "Raise.h" -#include -#include -#include -#include -#include -#include -#include -#include - -namespace view { - -template > -class basic_string_view { -public: - using traits_type = Tr; - using value_type = Ch; - using pointer = Ch *; - using const_pointer = const Ch *; - using reference = Ch &; - using const_reference = const Ch &; - using const_iterator = const_pointer; - using iterator = const_iterator; - using const_reverse_iterator = std::reverse_iterator; - using reverse_iterator = const_reverse_iterator; - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - -public: - static constexpr auto npos = size_type(-1); - -public: - constexpr basic_string_view() noexcept - : data_(nullptr) { - } - - constexpr basic_string_view(const basic_string_view &other) noexcept = default; - - template - basic_string_view(const std::basic_string &str) noexcept - : data_(str.data()), size_(str.size()) { - } - - constexpr basic_string_view(const Ch *str, size_type len) - : data_(str), size_(len) { - } - - constexpr basic_string_view(const Ch *str) - : data_(str), size_(Tr::length(str)) { - } - - basic_string_view &operator=(const basic_string_view &rhs) noexcept = default; - -public: - constexpr const_iterator begin() const noexcept { return data_; } - constexpr const_iterator cbegin() const noexcept { return data_; } - constexpr const_iterator end() const noexcept { return data_ + size_; } - constexpr const_iterator cend() const noexcept { return data_ + size_; } - - const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } - const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } - const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } - -public: - constexpr const_reference operator[](size_type pos) const noexcept { - return data_[pos]; - } - - constexpr const_reference at(size_t pos) const { - return pos >= size_ ? Raise("string_view::at"), data_[0] : data_[pos]; - } - - constexpr const_reference front() const { - return data_[0]; - } - - constexpr const_reference back() const { - return data_[size_ - 1]; - } - - constexpr const_pointer data() const noexcept { - return data_; - } - -public: - constexpr size_type size() const noexcept { - return size_; - } - - constexpr size_type length() const noexcept { - return size_; - } - - constexpr size_type max_size() const noexcept { - return size_type(-1) / sizeof(Ch); - } - - constexpr bool empty() const noexcept { - return size_ == 0; - } - -public: - constexpr void remove_prefix(size_type n) { - if (n > size_) { - n = size_; - } - - data_ += n; - size_ -= n; - } - - constexpr void remove_suffix(size_type n) { - if (n > size_) { - n = size_; - } - - size_ -= n; - } - - constexpr void swap(basic_string_view &s) noexcept { - using std::swap; - swap(data_, s.data_); - swap(size_, s.size_); - } - -public: - template - explicit operator std::basic_string() const { - return std::basic_string(begin(), end()); - } - - template > - std::basic_string to_string(const A &a = A()) const { - return std::basic_string(begin(), end(), a); - } - -public: - size_type copy(Ch *dest, size_type count, size_type pos = 0) const { - - using std::min; - - if (pos > size()) { - Raise("string_view::copy"); - } - - size_type rlen = min(count, size_ - pos); - Tr::copy(dest, data() + pos, rlen); - return rlen; - } - - constexpr basic_string_view substr(size_type pos, size_type n = npos) const { - - using std::min; - - if (pos > size()) { - Raise("string_view::substr"); - } - - return basic_string_view(data() + pos, min(size() - pos, n)); - } - -public: - constexpr int compare(basic_string_view x) const noexcept { - const int cmp = Tr::compare(data_, x.data_, (std::min)(size_, x.size_)); - return cmp != 0 ? cmp : (size_ == x.size_ ? 0 : size_ < x.size_ ? -1 - : 1); - } - - constexpr int compare(size_type pos1, size_type n1, basic_string_view x) const noexcept { - return substr(pos1, n1).compare(x); - } - - constexpr int compare(size_type pos1, size_type n1, basic_string_view x, size_type pos2, size_type n2) const { - return substr(pos1, n1).compare(x.substr(pos2, n2)); - } - - constexpr int compare(const Ch *x) const { - return compare(basic_string_view(x)); - } - - constexpr int compare(size_type pos1, size_type n1, const Ch *x) const { - return substr(pos1, n1).compare(basic_string_view(x)); - } - - constexpr int compare(size_type pos1, size_type n1, const Ch *x, size_type n2) const { - return substr(pos1, n1).compare(basic_string_view(x, n2)); - } - -public: - constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept { - if (pos > size()) { - return npos; - } - - if (s.empty()) { - return pos; - } - - auto it = std::search(cbegin() + pos, cend(), s.cbegin(), s.cend(), Tr::eq); - return it == cend() ? npos : std::distance(cbegin(), it); - } - - constexpr size_type find(Ch c, size_type pos = 0) const noexcept { - return find(basic_string_view(&c, 1), pos); - } - - constexpr size_type find(const Ch *s, size_type pos, size_type n) const noexcept { - return find(basic_string_view(s, n), pos); - } - - constexpr size_type find(const Ch *s, size_type pos = 0) const noexcept { - return find(basic_string_view(s), pos); - } - -public: - constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept { - if (size_ < s.size_) { - return npos; - } - - if (pos > size_ - s.size_) { - pos = size_ - s.size_; - } - - if (s.size_ == 0u) { - return pos; - } - - for (const Ch *cur = data_ + pos;; --cur) { - if (Tr::compare(cur, s.data_, s.size_) == 0) { - return cur - data_; - } - - if (cur == data_) { - return npos; - } - } - } - - constexpr size_type rfind(Ch c, size_type pos = npos) const noexcept { - return rfind(basic_string_view(&c, 1), pos); - } - - constexpr size_type rfind(const Ch *s, size_type pos, size_type n) const noexcept { - return rfind(basic_string_view(s, n), pos); - } - - constexpr size_type rfind(const Ch *s, size_type pos = npos) const noexcept { - return rfind(basic_string_view(s), pos); - } - -public: - constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept { - if (pos >= size_ || s.size_ == 0) { - return npos; - } - - auto it = std::find_first_of(cbegin() + pos, cend(), s.cbegin(), s.cend(), Tr::eq); - return it == cend() ? npos : std::distance(cbegin(), it); - } - - constexpr size_type find_first_of(Ch c, size_type pos = 0) const noexcept { - return find_first_of(basic_string_view(&c, 1), pos); - } - - constexpr size_type find_first_of(const Ch *s, size_type pos, size_type n) const noexcept { - return find_first_of(basic_string_view(s, n), pos); - } - - constexpr size_type find_first_of(const Ch *s, size_type pos = 0) const noexcept { - return find_first_of(basic_string_view(s), pos); - } - -public: - constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept { - if (s.size_ == 0u) { - return npos; - } - - if (pos >= size_) { - pos = 0; - } else { - pos = size_ - (pos + 1); - } - - auto it = std::find_first_of(crbegin() + pos, crend(), s.cbegin(), s.cend(), Tr::eq); - return it == crend() ? npos : reverse_distance(crbegin(), it); - } - - constexpr size_type find_last_of(Ch c, size_type pos = npos) const noexcept { - return find_last_of(basic_string_view(&c, 1), pos); - } - - constexpr size_type find_last_of(const Ch *s, size_type pos, size_type n) const noexcept { - return find_last_of(basic_string_view(s, n), pos); - } - - constexpr size_type find_last_of(const Ch *s, size_type pos = npos) const noexcept { - return find_last_of(basic_string_view(s), pos); - } - -public: - constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept { - if (pos >= size_) { - return npos; - } - - if (s.size_ == 0) { - return pos; - } - - auto it = find_not_of(cbegin() + pos, cend(), s); - return it == cend() ? npos : std::distance(cbegin(), it); - } - - constexpr size_type find_first_not_of(Ch c, size_type pos = 0) const noexcept { - return find_first_not_of(basic_string_view(&c, 1), pos); - } - - constexpr size_type find_first_not_of(const Ch *s, size_type pos, size_type n) const noexcept { - return find_first_not_of(basic_string_view(s, n), pos); - } - - constexpr size_type find_first_not_of(const Ch *s, size_type pos = 0) const noexcept { - return find_first_not_of(basic_string_view(s), pos); - } - -public: - constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept { - if (pos >= size_) { - pos = size_ - 1; - } - - if (s.size_ == 0u) { - return pos; - } - - pos = size_ - (pos + 1); - auto it = find_not_of(crbegin() + pos, crend(), s); - return it == crend() ? npos : reverse_distance(crbegin(), it); - } - - constexpr size_type find_last_not_of(Ch c, size_type pos = npos) const noexcept { - return find_last_not_of(basic_string_view(&c, 1), pos); - } - - constexpr size_type find_last_not_of(const Ch *s, size_type pos, size_type n) const noexcept { - return find_last_not_of(basic_string_view(s, n), pos); - } - - constexpr size_type find_last_not_of(const Ch *s, size_type pos = npos) const noexcept { - return find_last_not_of(basic_string_view(s), pos); - } - -private: - template - size_type reverse_distance(It first, It last) const noexcept { - return size_ - 1 - std::distance(first, last); - } - - template - It find_not_of(It first, It last, basic_string_view s) const noexcept { - for (; first != last; ++first) { - if (0 == Tr::find(s.data_, s.size_, *first)) { - return first; - } - } - return last; - } - -private: - const Ch *data_; - std::size_t size_ = 0; -}; - -template -constexpr bool operator==(basic_string_view lhs, basic_string_view rhs) noexcept { - if (lhs.size() != rhs.size()) { - return false; - } - return lhs.compare(rhs) == 0; -} - -template -constexpr bool operator!=(basic_string_view lhs, basic_string_view rhs) noexcept { - if (lhs.size() != rhs.size()) { - return true; - } - return lhs.compare(rhs) != 0; -} - -// Less than -template -constexpr bool operator<(basic_string_view lhs, basic_string_view rhs) noexcept { - return lhs.compare(rhs) < 0; -} - -// Greater than -template -constexpr bool operator>(basic_string_view lhs, basic_string_view rhs) noexcept { - return lhs.compare(rhs) > 0; -} - -// Less than or equal to -template -constexpr bool operator<=(basic_string_view lhs, basic_string_view rhs) noexcept { - return lhs.compare(rhs) <= 0; -} - -// Greater than or equal to -template -constexpr bool operator>=(basic_string_view lhs, basic_string_view rhs) noexcept { - return lhs.compare(rhs) >= 0; -} - -// "sufficient additional overloads of comparison functions" -template -constexpr bool operator==(basic_string_view lhs, const std::basic_string &rhs) noexcept { - return lhs == basic_string_view(rhs); -} - -template -constexpr bool operator==(const std::basic_string &lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) == rhs; -} - -template -constexpr bool operator==(basic_string_view lhs, const Ch *rhs) noexcept { - return lhs == basic_string_view(rhs); -} - -template -constexpr bool operator==(const Ch *lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) == rhs; -} - -template -constexpr bool operator!=(basic_string_view lhs, const std::basic_string &rhs) noexcept { - return lhs != basic_string_view(rhs); -} - -template -constexpr bool operator!=(const std::basic_string &lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) != rhs; -} - -template -constexpr bool operator!=(basic_string_view lhs, const Ch *rhs) noexcept { - return lhs != basic_string_view(rhs); -} - -template -constexpr bool operator!=(const Ch *lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) != rhs; -} - -template -constexpr bool operator<(basic_string_view lhs, const std::basic_string &rhs) noexcept { - return lhs < basic_string_view(rhs); -} - -template -constexpr bool operator<(const std::basic_string &lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) < rhs; -} - -template -constexpr bool operator<(basic_string_view lhs, const Ch *rhs) noexcept { - return lhs < basic_string_view(rhs); -} - -template -constexpr bool operator<(const Ch *lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) < rhs; -} - -template -constexpr bool operator>(basic_string_view lhs, const std::basic_string &rhs) noexcept { - return lhs > basic_string_view(rhs); -} - -template -constexpr bool operator>(const std::basic_string &lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) > rhs; -} - -template -constexpr bool operator>(basic_string_view lhs, const Ch *rhs) noexcept { - return lhs > basic_string_view(rhs); -} - -template -constexpr bool operator>(const Ch *lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) > rhs; -} - -template -constexpr bool operator<=(basic_string_view lhs, const std::basic_string &rhs) noexcept { - return lhs <= basic_string_view(rhs); -} - -template -constexpr bool operator<=(const std::basic_string &lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) <= rhs; -} - -template -constexpr bool operator<=(basic_string_view lhs, const Ch *rhs) noexcept { - return lhs <= basic_string_view(rhs); -} - -template -constexpr bool operator<=(const Ch *lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) <= rhs; -} - -template -constexpr bool operator>=(basic_string_view lhs, const std::basic_string &rhs) noexcept { - return lhs >= basic_string_view(rhs); -} - -template -constexpr bool operator>=(const std::basic_string &lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) >= rhs; -} - -template -constexpr bool operator>=(basic_string_view lhs, const Ch *rhs) noexcept { - return lhs >= basic_string_view(rhs); -} - -template -constexpr bool operator>=(const Ch *lhs, basic_string_view rhs) noexcept { - return basic_string_view(lhs) >= rhs; -} - -using string_view = basic_string_view; -using wstring_view = basic_string_view; -using u16string_view = basic_string_view; -using u32string_view = basic_string_view; -} - -// NOTE(eteran): see https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function -// for more details on this algorithm -namespace detail { - -template -struct hash_constants_impl; - -template <> -struct hash_constants_impl<8> { - static constexpr uint64_t FNV_offset_basis = 0xcbf29ce484222325ull; - static constexpr uint64_t FNV_prime = 1099511628211ull; -}; - -template <> -struct hash_constants_impl<4> { - static constexpr uint32_t FNV_offset_basis = 0x811c9dc5; - static constexpr uint32_t FNV_prime = 16777619; -}; - -template -struct hash_constants : hash_constants_impl { -}; - -} - -namespace std { - -template <> -struct hash { - using argument_type = view::string_view; - using result_type = size_t; - - result_type operator()(argument_type key) const { - - result_type h = detail::hash_constants::FNV_offset_basis; - for (char ch : key) { - h = (h * detail::hash_constants::FNV_prime) ^ static_cast(ch); - } - return h; - } -}; - -template <> -struct hash { - using argument_type = view::wstring_view; - using result_type = size_t; - - result_type operator()(argument_type key) const { - auto p = reinterpret_cast(&*key.begin()); - auto last = reinterpret_cast(&*key.end()); - - result_type h = detail::hash_constants::FNV_offset_basis; - while (p != last) { - h = (h * detail::hash_constants::FNV_prime) ^ static_cast(*p++); - } - return h; - } -}; - -template <> -struct hash { - using argument_type = view::u16string_view; - using result_type = size_t; - - result_type operator()(argument_type key) const { - auto p = reinterpret_cast(&*key.begin()); - auto last = reinterpret_cast(&*key.end()); - - result_type h = detail::hash_constants::FNV_offset_basis; - while (p != last) { - h = (h * detail::hash_constants::FNV_prime) ^ static_cast(*p++); - } - return h; - } -}; - -template <> -struct hash { - using argument_type = view::u32string_view; - using result_type = size_t; - - result_type operator()(argument_type key) const { - auto p = reinterpret_cast(&*key.begin()); - auto last = reinterpret_cast(&*key.end()); - - result_type h = detail::hash_constants::FNV_offset_basis; - while (p != last) { - h = (h * detail::hash_constants::FNV_prime) ^ static_cast(*p++); - } - return h; - } -}; - -} - -#endif diff --git a/client/nc.cpp b/client/nc.cpp index b0bed204..5f2fa87b 100644 --- a/client/nc.cpp +++ b/client/nc.cpp @@ -16,11 +16,13 @@ #include #include -#include +#include #include -#include #include #include +#include + +#include namespace { @@ -450,7 +452,7 @@ int main(int argc, char *argv[]) { /* Make sure that the time out unit is at least 1 second and not too large either (overflow!). */ - ServerPreferences.timeOut = qBound(1, ServerPreferences.timeOut, 1000); + ServerPreferences.timeOut = std::clamp(ServerPreferences.timeOut, 1, 1000); /* For Clearcase users who have not set a server name, use the clearcase view name. Clearcase views make files with the same absolute path names diff --git a/cspell.config.yaml b/cspell.config.yaml index 3fb1c4fe..f5f4737a 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -15,6 +15,7 @@ words: - clearcase - cornsilk - decompile + - decompiler - Edel - eteran - fground diff --git a/src/DialogSyntaxPatterns.h b/src/DialogSyntaxPatterns.h index d668b447..ffe98a5d 100644 --- a/src/DialogSyntaxPatterns.h +++ b/src/DialogSyntaxPatterns.h @@ -8,8 +8,8 @@ #include -#include #include +#include class HighlightPattern; class HighlightPatternModel; diff --git a/src/DocumentWidget.cpp b/src/DocumentWidget.cpp index 6ccf6b82..48e606b8 100644 --- a/src/DocumentWidget.cpp +++ b/src/DocumentWidget.cpp @@ -26,7 +26,9 @@ #include "Util/ClearCase.h" #include "Util/FileSystem.h" #include "Util/Input.h" +#include "Util/Raise.h" #include "Util/User.h" +#include "Util/algorithm.h" #include "Util/regex.h" #include "Util/utils.h" #include "WindowHighlightData.h" @@ -159,7 +161,7 @@ QString errorString(int error) { * @param deletedText * @param user */ -void modifiedCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, view::string_view deletedText, void *user) { +void modifiedCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, std::string_view deletedText, void *user) { if (auto document = static_cast(user)) { document->modifiedCallback(pos, nInserted, nDeleted, nRestyled, deletedText); } @@ -231,7 +233,7 @@ void handleUnparsedRegionCB(const TextArea *area, TextCursor pos, const void *us */ // TODO(eteran): I think the bufReplaceEx function already sanitizes its input, // so it's possible that this function is redundant. -void safeBufReplace(TextBuffer *buf, TextCursor *start, TextCursor *end, view::string_view text) { +void safeBufReplace(TextBuffer *buf, TextCursor *start, TextCursor *end, std::string_view text) { const TextCursor last = buf->BufEndOfBuffer(); @@ -981,7 +983,7 @@ void DocumentWidget::updateMarkTable(TextCursor pos, int64_t nInserted, int64_t * @param deletedText * @param area */ -void DocumentWidget::modifiedCallback(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, view::string_view deletedText, TextArea *area) { +void DocumentWidget::modifiedCallback(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, std::string_view deletedText, TextArea *area) { Q_UNUSED(nRestyled) // number of distinct chars the user can type before NEdit gens. new backup file @@ -1057,7 +1059,7 @@ void DocumentWidget::modifiedCallback(TextCursor pos, int64_t nInserted, int64_t * @param nRestyled * @param deletedText */ -void DocumentWidget::modifiedCallback(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, view::string_view deletedText) { +void DocumentWidget::modifiedCallback(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, std::string_view deletedText) { modifiedCallback(pos, nInserted, nDeleted, nRestyled, deletedText, nullptr); } @@ -1573,7 +1575,7 @@ void DocumentWidget::updateSelectionSensitiveMenu(QMenu *menu, const gsl::spanundo.empty() && info_->undo.front().inUndo); const int isRedo = (!info_->redo.empty() && info_->redo.front().inUndo); @@ -1643,7 +1645,7 @@ void DocumentWidget::saveUndoInformation(TextCursor pos, int64_t nInserted, int6 // if text was deleted, save it if (nDeleted > 0) { - undo.oldText = deletedText.to_string(); + undo.oldText = std::string(deletedText); } // increment the operation count for the autosave feature @@ -1702,7 +1704,7 @@ void DocumentWidget::clearRedoList() { ** for continuing of a string of one character deletes or replaces, but will ** work with more than one character. */ -void DocumentWidget::appendDeletedText(view::string_view deletedText, int64_t deletedLen, Direction direction) { +void DocumentWidget::appendDeletedText(std::string_view deletedText, int64_t deletedLen, Direction direction) { UndoInfo &undo = info_->undo.front(); // re-allocate, adding space for the new character(s) @@ -2247,7 +2249,7 @@ bool DocumentWidget::compareDocumentToFile(const QString &fileName) const { nRead += offset; // check for on-disk file format changes, but only for the first chunk - if (bufPos == 0 && info_->fileFormat != FormatOfFile(view::string_view(fileString, static_cast(nRead)))) { + if (bufPos == 0 && info_->fileFormat != FormatOfFile(std::string_view(fileString, static_cast(nRead)))) { return true; } @@ -2548,7 +2550,7 @@ bool DocumentWidget::doSave() { } // write to the file - if (file.write(text.data(), static_cast(text.size())) == -1) { + if (file.write(text.data(), ssize(text)) == -1) { QMessageBox::critical(this, tr("Error saving File"), tr("%1 not saved:\n%2").arg(info_->filename, file.errorString())); file.close(); file.remove(); @@ -2982,7 +2984,7 @@ void DocumentWidget::closeDocument() { // clear the buffer, but ignore changes info_->ignoreModify = true; - info_->buffer->BufSetAll(view::string_view()); + info_->buffer->BufSetAll(std::string_view()); info_->ignoreModify = false; info_->filenameSet = false; @@ -4841,7 +4843,7 @@ void DocumentWidget::processFinished(int exitCode, QProcess::ExitStatus exitStat area->TextSetCursorPos(buf->BufCursorPosHint()); if (reselectStart != -1) { - buf->BufSelect(reselectStart, reselectStart + static_cast(outText.size())); + buf->BufSelect(reselectStart, reselectStart + ssize(outText)); } } else { safeBufReplace(buf, &shellCmdData_->leftPos, &shellCmdData_->rightPos, outText); diff --git a/src/DocumentWidget.h b/src/DocumentWidget.h index a12d1d2b..89b66eff 100644 --- a/src/DocumentWidget.h +++ b/src/DocumentWidget.h @@ -19,9 +19,9 @@ #include "TextBufferFwd.h" #include "UndoInfo.h" #include "Util/FileFormats.h" -#include "Util/string_view.h" #include "Verbosity.h" #include "WrapStyle.h" +#include #include "ui_DocumentWidget.h" @@ -89,8 +89,8 @@ class DocumentWidget : public QWidget { public: void dragEndCallback(TextArea *area, const DragEndEvent *event); void dragStartCallback(TextArea *area); - void modifiedCallback(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, view::string_view deletedText); - void modifiedCallback(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, view::string_view deletedText, TextArea *area); + void modifiedCallback(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, std::string_view deletedText); + void modifiedCallback(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, std::string_view deletedText, TextArea *area); void movedCallback(TextArea *area); void smartIndentCallback(TextArea *area, SmartIndentEvent *event); @@ -252,7 +252,7 @@ class DocumentWidget : public QWidget { void addRedoItem(UndoInfo &&redo); void addUndoItem(UndoInfo &&undo); void addWrapNewlines(); - void appendDeletedText(view::string_view deletedText, int64_t deletedLen, Direction direction); + void appendDeletedText(std::string_view deletedText, int64_t deletedLen, Direction direction); void attachHighlightToWidget(TextArea *area); void beginLearn(); void cancelLearning(); @@ -285,7 +285,7 @@ class DocumentWidget : public QWidget { void removeUndoItem(); void replay(); void revertToSaved(); - void saveUndoInformation(TextCursor pos, int64_t nInserted, int64_t nDeleted, view::string_view deletedText); + void saveUndoInformation(TextCursor pos, int64_t nInserted, int64_t nDeleted, std::string_view deletedText); void setModeMessage(const QString &message); void setWindowModified(bool modified); void trimUndoList(size_t maxLength); diff --git a/src/DragEndEvent.h b/src/DragEndEvent.h index 850454da..2cedb77d 100644 --- a/src/DragEndEvent.h +++ b/src/DragEndEvent.h @@ -3,14 +3,14 @@ #define DRAG_END_EVENT_H_ #include "TextCursor.h" -#include "Util/string_view.h" #include +#include struct DragEndEvent { TextCursor startPos; int64_t nCharsDeleted; int64_t nCharsInserted; - view::string_view deletedText; + std::string_view deletedText; }; #endif diff --git a/src/Highlight.cpp b/src/Highlight.cpp index 4fb712fc..eadb3834 100644 --- a/src/Highlight.cpp +++ b/src/Highlight.cpp @@ -11,6 +11,7 @@ #include "Settings.h" #include "TextBuffer.h" #include "Util/Input.h" +#include "Util/Raise.h" #include "Util/Resource.h" #include "Util/algorithm.h" #include "WindowHighlightData.h" @@ -98,16 +99,14 @@ TextCursor lastModified(const Ptr &buffer) { } /* -** Return true if patSet exactly matches one of the default pattern sets +** Return true if `patternSet` exactly matches one of the default pattern sets */ bool isDefaultPatternSet(const PatternSet &patternSet) { - - std::optional defaultPatSet = readDefaultPatternSet(patternSet.languageMode); - if (!defaultPatSet) { - return false; + if (std::optional defaultPatSet = readDefaultPatternSet(patternSet.languageMode)) { + return patternSet == *defaultPatSet; } - return patternSet == *defaultPatSet; + return false; } /* @@ -1061,7 +1060,7 @@ std::vector readDefaultPatternSets() { ** Note: This routine must be kept efficient. It is called for every ** character typed. */ -void SyntaxHighlightModifyCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, view::string_view deletedText, void *user) { +void SyntaxHighlightModifyCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, std::string_view deletedText, void *user) { Q_UNUSED(nRestyled) Q_UNUSED(deletedText) @@ -1131,16 +1130,19 @@ bool parseString(const HighlightData *pattern, const char *&string_ptr, uint8_t return false; } + const char *const begin_ptr = ctx->text.data(); + const char *const end_ptr = ctx->text.data() + ctx->text.size(); + if (!look_behind_to) { - look_behind_to = ctx->text.begin(); + look_behind_to = begin_ptr; } if (!match_to) { - match_to = ctx->text.end(); + match_to = end_ptr; } bool subExecuted; - const int next_char = (match_to != ctx->text.end()) ? (*match_to) : -1; + const int next_char = (match_to != end_ptr) ? (*match_to) : -1; const char *stringPtr = string_ptr; uint8_t *stylePtr = style_ptr; @@ -1159,7 +1161,7 @@ bool parseString(const HighlightData *pattern, const char *&string_ptr, uint8_t delimitersPtr, look_behind_to, match_to, - ctx->text.end())) { + end_ptr)) { /* Beware of the case where only one real branch exists, but that branch has sub-branches itself. In that case the top_branch refers @@ -1197,7 +1199,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 end match in parseString"); return false; } @@ -1296,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; } diff --git a/src/Highlight.h b/src/Highlight.h index f7558299..fa62940a 100644 --- a/src/Highlight.h +++ b/src/Highlight.h @@ -5,10 +5,10 @@ #include "TextBufferFwd.h" #include "TextCursor.h" #include "Util/QtHelper.h" -#include "Util/string_view.h" +#include -#include #include +#include #include #include @@ -47,7 +47,7 @@ Q_DECLARE_NAMESPACE_TR(Highlight) struct ParseContext { int *prev_char = nullptr; QString delimiters; - view::string_view text; + std::string_view text; }; bool FontOfNamedStyleIsBold(const QString &styleName); @@ -68,7 +68,7 @@ std::optional readDefaultPatternSet(const QString &langModeName); TextCursor backwardOneContext(TextBuffer *buf, const ReparseContext &context, TextCursor fromPos); TextCursor forwardOneContext(TextBuffer *buf, const ReparseContext &context, TextCursor fromPos); void RenameHighlightPattern(const QString &oldName, const QString &newName); -void SyntaxHighlightModifyCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, view::string_view deletedText, void *user); +void SyntaxHighlightModifyCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, std::string_view deletedText, void *user); extern std::vector HighlightStyles; extern std::vector PatternSets; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 7b81a7e8..185df8aa 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -55,6 +55,7 @@ #include #include +#include #include #ifdef Q_OS_LINUX @@ -97,7 +98,7 @@ std::optional StringToLineAndCol(const QString &text) { if (!row_ok) { r = -1; } else { - r = qBound(0, r, INT_MAX); + r = std::clamp(r, 0, INT_MAX); } bool col_ok; @@ -105,7 +106,7 @@ std::optional StringToLineAndCol(const QString &text) { if (!col_ok) { c = -1; } else { - c = qBound(0, c, INT_MAX); + c = std::clamp(c, 0, INT_MAX); } if (r == -1 && c == -1) { @@ -6283,7 +6284,7 @@ bool MainWindow::searchWindow(DocumentWidget *document, const QString &searchStr } // get the entire text buffer from the text area widget - view::string_view fileString = buffer->BufAsString(); + std::string_view fileString = buffer->BufAsString(); /* If we're already outside the boundaries, we must consider wrapping immediately (Note: fileEnd+1 is a valid starting position. Consider @@ -6614,7 +6615,7 @@ bool MainWindow::replaceAndSearch(DocumentWidget *document, TextArea *area, cons Search::defaultRegexFlags(searchType)); buffer->BufReplace(selectionRange, replaceResult); - replaceLen = static_cast(replaceResult.size()); + replaceLen = ssize(replaceResult); } else { buffer->BufReplace(selectionRange, replaceString.toStdString()); replaceLen = replaceString.size(); @@ -6743,7 +6744,7 @@ bool MainWindow::searchAndReplace(DocumentWidget *document, TextArea *area, cons Search::defaultRegexFlags(searchType)); buffer->BufReplace(selectionRange, replaceResult); - replaceLen = static_cast(replaceResult.size()); + replaceLen = ssize(replaceResult); } else { buffer->BufReplace(selectionRange, replaceString.toStdString()); replaceLen = replaceString.size(); @@ -6999,7 +7000,7 @@ void MainWindow::replaceInSelection(DocumentWidget *document, TextArea *area, co } tempBuf.BufReplace(TextCursor(searchResult->start + realOffset), TextCursor(searchResult->end + realOffset), replaceResult); - replaceLen = static_cast(replaceResult.size()); + replaceLen = ssize(replaceResult); } else { // at this point plain substitutions (should) always work tempBuf.BufReplace(TextCursor(searchResult->start + realOffset), TextCursor(searchResult->end + realOffset), replaceString.toStdString()); @@ -7138,7 +7139,7 @@ bool MainWindow::replaceAll(DocumentWidget *document, TextArea *area, const QStr TextBuffer *buffer = document->buffer(); // view the entire text buffer from the text area widget as a string - view::string_view fileString = buffer->BufAsString(); + std::string_view fileString = buffer->BufAsString(); QString delimiters = document->getWindowDelimiters(); diff --git a/src/Preferences.cpp b/src/Preferences.cpp index 6e2c5d99..ee1eb968 100644 --- a/src/Preferences.cpp +++ b/src/Preferences.cpp @@ -11,6 +11,7 @@ #include "Theme.h" #include "Util/ClearCase.h" #include "Util/Input.h" +#include "Util/Raise.h" #include "Util/Resource.h" #include "Util/User.h" #include "Util/algorithm.h" @@ -20,6 +21,8 @@ #include +#include + #include #include #include @@ -28,7 +31,6 @@ #include #include - namespace Preferences { namespace { @@ -93,9 +95,9 @@ std::optional readLanguageModeYaml(const YAML::Node &language) { const YAML::Node value = it->second; if (key == "name") { - lm.name = QString::fromUtf8(value.as().c_str()); + lm.name = QString::fromStdString(value.as()); } else if (key == "delimiters") { - lm.delimiters = QString::fromUtf8(value.as().c_str()); + lm.delimiters = QString::fromStdString(value.as()); } else if (key == "tab_distance") { lm.tabDist = value.as(); } else if (key == "em_tab_distance") { @@ -103,9 +105,9 @@ std::optional readLanguageModeYaml(const YAML::Node &language) { } else if (key == "insert_tabs") { lm.insertTabs = value.as(); } else if (key == "regex") { - lm.recognitionExpr = QString::fromUtf8(value.as().c_str()); + lm.recognitionExpr = QString::fromStdString(value.as()); } else if (key == "wrap") { - auto string_val = QString::fromUtf8(value.as().c_str()); + auto string_val = QString::fromStdString(value.as()); auto it = std::find(std::begin(AutoWrapTypes), std::end(AutoWrapTypes), string_val); if (it == std::end(AutoWrapTypes)) { Raise(tr("unrecognized wrap style")); @@ -113,7 +115,7 @@ std::optional readLanguageModeYaml(const YAML::Node &language) { lm.wrapStyle = static_cast(it - std::begin(AutoWrapTypes)); } else if (key == "indent") { - auto string_val = QString::fromUtf8(value.as().c_str()); + auto string_val = QString::fromStdString(value.as()); auto it = std::find(std::begin(AutoIndentTypes), std::end(AutoIndentTypes), string_val); if (it == std::end(AutoIndentTypes)) { Raise(tr("unrecognized indent style")); @@ -121,7 +123,7 @@ std::optional readLanguageModeYaml(const YAML::Node &language) { lm.indentStyle = static_cast(it - std::begin(AutoIndentTypes)); } else if (key == "default_tips") { - lm.defTipsFile = QString::fromUtf8(value.as().c_str()); + lm.defTipsFile = QString::fromStdString(value.as()); } else if (key == "extensions") { QStringList extensions; for (size_t i = 0; i < value.size(); i++) { @@ -1381,7 +1383,7 @@ bool SkipDelimiter(Input &in, QString *errMsg) { bool reportError(QWidget *toDialog, const QString &string, int stoppedAt, const QString &errorIn, const QString &message) { // NOTE(eteran): hack to work around the fact that stoppedAt can be a "one past the end iterator" - stoppedAt = qBound(0, stoppedAt, string.size() - 1); + stoppedAt = std::clamp(stoppedAt, 0, string.size() - 1); int nNonWhite = 0; int c; diff --git a/src/Rangeset.cpp b/src/Rangeset.cpp index 15180a18..e42def17 100644 --- a/src/Rangeset.cpp +++ b/src/Rangeset.cpp @@ -1,6 +1,7 @@ #include "Rangeset.h" #include "TextBuffer.h" +#include "Util/algorithm.h" #include #include #include @@ -597,7 +598,7 @@ int64_t Rangeset::RangesetFindRangeOfPos(TextCursor pos, bool incl_end) const { } auto ranges = reinterpret_cast(ranges_.data()); // { s1,e1, s2,e2, s3,e3,... } - const auto len = static_cast(ranges_.size()) * 2; + const auto len = ssize(ranges_) * 2; const int64_t ind = at_or_before(ranges, 0, len, pos); if (ind == len) { @@ -621,7 +622,7 @@ int64_t Rangeset::RangesetFindRangeOfPos(TextCursor pos, bool incl_end) const { ** Get number of ranges in rangeset. */ int64_t Rangeset::size() const { - return static_cast(ranges_.size()); + return ssize(ranges_); } /* @@ -666,7 +667,7 @@ int64_t Rangeset::RangesetInverse() { } RangesetRefreshRange(buffer_, first, last); - return static_cast(ranges_.size()); + return ssize(ranges_); } /* @@ -724,7 +725,7 @@ int64_t Rangeset::RangesetCheckRangeOfPos(TextCursor pos) { int64_t index; - auto len = static_cast(ranges_.size()); + auto len = ssize(ranges_); if (ranges_.empty()) { return -1; // no ranges } @@ -786,7 +787,7 @@ int64_t Rangeset::RangesetAdd(const Rangeset &other) { if (other.ranges_.empty()) { // no ranges in plusSet - nothing to do - return static_cast(ranges_.size()); + return ssize(ranges_); } if (ranges_.empty()) { @@ -797,7 +798,7 @@ int64_t Rangeset::RangesetAdd(const Rangeset &other) { RangesetRefreshRange(buffer_, range.start, range.end); } - return static_cast(ranges_.size()); + return ssize(ranges_); } auto origRanges = ranges_.cbegin(); @@ -856,7 +857,7 @@ int64_t Rangeset::RangesetAdd(const Rangeset &other) { // finally, forget the old rangeset values, and reallocate the new ones ranges_ = std::move(newRanges); - return static_cast(ranges_.size()); + return ssize(ranges_); } /* @@ -946,7 +947,7 @@ int64_t Rangeset::RangesetRemove(const Rangeset &other) { // finally, forget the old rangeset values, and reallocate the new ones ranges_ = std::move(newRanges); - return static_cast(ranges_.size()); + return ssize(ranges_); } /* @@ -960,14 +961,14 @@ int64_t Rangeset::RangesetAdd(TextRange r) { std::swap(r.start, r.end); } else if (r.start == r.end) { // no-op - empty range == no range - return static_cast(ranges_.size()); + return ssize(ranges_); } // if it's the first range, just insert it if (ranges_.empty()) { ranges_.push_back(r); RangesetRefreshRange(buffer_, r.start, r.end); - return static_cast(ranges_.size()); + return ssize(ranges_); } auto next = std::lower_bound(ranges_.begin(), ranges_.end(), r); @@ -1003,7 +1004,7 @@ int64_t Rangeset::RangesetAdd(TextRange r) { } RangesetRefreshRange(buffer_, r.start, r.end); - return static_cast(ranges_.size()); + return ssize(ranges_); } /* @@ -1017,11 +1018,11 @@ int64_t Rangeset::RangesetRemove(TextRange r) { std::swap(r.start, r.end); } else if (r.start == r.end) { // no-op - empty range == no range - return static_cast(ranges_.size()); + return ssize(ranges_); } if (ranges_.empty()) { - return static_cast(ranges_.size()); + return ssize(ranges_); } auto next = std::lower_bound(ranges_.begin(), ranges_.end(), r); @@ -1048,7 +1049,7 @@ int64_t Rangeset::RangesetRemove(TextRange r) { } RangesetRefreshRange(buffer_, r.start, r.end); - return static_cast(ranges_.size()); + return ssize(ranges_); } /** @@ -1089,7 +1090,7 @@ RangesetInfo Rangeset::RangesetGetInfo() const { RangesetInfo info; info.defined = true; info.label = static_cast(label_); - info.count = static_cast(ranges_.size()); + info.count = ssize(ranges_); info.color = color_name_; info.name = name_; info.mode = update_name_; diff --git a/src/RangesetTable.cpp b/src/RangesetTable.cpp index 8a9aa1d7..8eb7fba3 100644 --- a/src/RangesetTable.cpp +++ b/src/RangesetTable.cpp @@ -18,7 +18,7 @@ constexpr std::array rangeset_labels = { // -------------------------------------------------------------------------- -void RangesetBufModifiedCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, view::string_view deletedText, void *user) { +void RangesetBufModifiedCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, std::string_view deletedText, void *user) { Q_UNUSED(nRestyled) if (auto *table = static_cast(user)) { diff --git a/src/Search.cpp b/src/Search.cpp index e142e591..fa2e3f56 100644 --- a/src/Search.cpp +++ b/src/Search.cpp @@ -37,7 +37,7 @@ int HistStart = 0; * @param defaultFlags * @return */ -std::optional forwardRegexSearch(view::string_view string, view::string_view searchString, WrapMode wrap, int64_t beginPos, const char *delimiters, int defaultFlags) { +std::optional forwardRegexSearch(std::string_view string, std::string_view searchString, WrapMode wrap, int64_t beginPos, const char *delimiters, int defaultFlags) { try { Regex compiledRE(searchString, defaultFlags); @@ -89,7 +89,7 @@ std::optional forwardRegexSearch(view::string_view string, view: * @param defaultFlags * @return */ -std::optional backwardRegexSearch(view::string_view string, view::string_view searchString, WrapMode wrap, int64_t beginPos, const char *delimiters, int defaultFlags) { +std::optional backwardRegexSearch(std::string_view string, std::string_view searchString, WrapMode wrap, int64_t beginPos, const char *delimiters, int defaultFlags) { try { Regex compiledRE(searchString, defaultFlags); @@ -148,7 +148,7 @@ std::optional backwardRegexSearch(view::string_view string, view * @param defaultFlags * @return */ -std::optional searchRegex(view::string_view string, view::string_view searchString, Direction direction, WrapMode wrap, int64_t beginPos, const char *delimiters, int defaultFlags) { +std::optional searchRegex(std::string_view string, std::string_view searchString, Direction direction, WrapMode wrap, int64_t beginPos, const char *delimiters, int defaultFlags) { switch (direction) { case Direction::Forward: @@ -170,7 +170,7 @@ std::optional searchRegex(view::string_view string, view::string * @param beginPos * @return */ -std::optional searchLiteral(view::string_view string, view::string_view searchString, Direction direction, WrapMode wrap, int64_t beginPos, Qt::CaseSensitivity caseSensitivity) { +std::optional searchLiteral(std::string_view string, std::string_view searchString, Direction direction, WrapMode wrap, int64_t beginPos, Qt::CaseSensitivity caseSensitivity) { if (searchString.empty()) { return {}; @@ -180,8 +180,8 @@ std::optional searchLiteral(view::string_view string, view::stri std::string ucString; if (caseSensitivity == Qt::CaseSensitive) { - lcString = searchString.to_string(); - ucString = searchString.to_string(); + lcString = std::string(searchString); + ucString = std::string(searchString); } else { ucString = to_upper(searchString); lcString = to_lower(searchString); @@ -191,7 +191,7 @@ std::optional searchLiteral(view::string_view string, view::stri const auto mid = first + beginPos; const auto last = string.end(); - auto do_search = [&](view::string_view::iterator it) -> std::optional { + auto do_search = [&](std::string_view::iterator it) -> std::optional { if (*it == ucString[0] || *it == lcString[0]) { // matched first character auto ucPtr = ucString.begin(); @@ -281,7 +281,7 @@ std::optional searchLiteral(view::string_view string, view::stri ** will suffice in that case. ** */ -std::optional searchLiteralWord(view::string_view string, view::string_view searchString, Direction direction, WrapMode wrap, int64_t beginPos, const char *delimiters, Qt::CaseSensitivity caseSensitivity) { +std::optional searchLiteralWord(std::string_view string, std::string_view searchString, Direction direction, WrapMode wrap, int64_t beginPos, const char *delimiters, Qt::CaseSensitivity caseSensitivity) { if (searchString.empty()) { return {}; @@ -296,7 +296,7 @@ std::optional searchLiteralWord(view::string_view string, view:: const auto mid = first + beginPos; const auto last = string.end(); - auto do_search_word = [&](const view::string_view::iterator it) -> std::optional { + auto do_search_word = [&](const std::string_view::iterator it) -> std::optional { if (*it == ucString[0] || *it == lcString[0]) { // matched first character @@ -347,8 +347,8 @@ std::optional searchLiteralWord(view::string_view string, view:: } if (caseSensitivity == Qt::CaseSensitive) { - ucString = searchString.to_string(); - lcString = searchString.to_string(); + ucString = std::string(searchString); + lcString = std::string(searchString); } else { ucString = to_upper(searchString); lcString = to_lower(searchString); @@ -406,7 +406,7 @@ std::optional searchLiteralWord(view::string_view string, view:: ** for regular expression "<" and ">" characters, or simply passed as nullptr ** for the default delimiter set. */ -std::optional SearchStringEx(view::string_view string, view::string_view searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, const char *delimiters) { +std::optional SearchStringEx(std::string_view string, std::string_view searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, const char *delimiters) { switch (searchType) { case SearchType::CaseSenseWord: return searchLiteralWord(string, searchString, direction, wrap, beginPos, delimiters, Qt::CaseSensitive); @@ -434,7 +434,7 @@ std::optional SearchStringEx(view::string_view string, view::str ** code to continue using strings to represent the search and replace ** items. */ -bool replaceUsingRegex(view::string_view searchStr, view::string_view replaceStr, view::string_view sourceStr, int64_t beginPos, std::string &dest, int prevChar, const char *delimiters, int defaultFlags) { +bool replaceUsingRegex(std::string_view searchStr, std::string_view replaceStr, std::string_view sourceStr, int64_t beginPos, std::string &dest, int prevChar, const char *delimiters, int defaultFlags) { try { Regex compiledRE(searchStr, defaultFlags); compiledRE.execute(sourceStr, static_cast(beginPos), sourceStr.size(), prevChar, -1, delimiters, false); @@ -453,7 +453,7 @@ bool replaceUsingRegex(view::string_view searchStr, view::string_view replaceStr ** first replacement (returned in "copyStart", and the end of the last ** replacement (returned in "copyEnd") */ -std::optional Search::ReplaceAllInString(view::string_view inString, const QString &searchString, const QString &replaceString, SearchType searchType, int64_t *copyStart, int64_t *copyEnd, const QString &delimiters) { +std::optional Search::ReplaceAllInString(std::string_view inString, const QString &searchString, const QString &replaceString, SearchType searchType, int64_t *copyStart, int64_t *copyEnd, const QString &delimiters) { Result searchResult; int64_t lastEndPos; @@ -594,7 +594,7 @@ std::optional Search::ReplaceAllInString(view::string_view inString * @param delimiters * @return */ -std::optional Search::SearchString(view::string_view string, const QString &searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, const QString &delimiters) { +std::optional Search::SearchString(std::string_view string, const QString &searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, const QString &delimiters) { return SearchStringEx(string, searchString.toStdString(), direction, searchType, wrap, beginPos, delimiters.isNull() ? nullptr : delimiters.toLatin1().data()); } @@ -610,7 +610,7 @@ std::optional Search::SearchString(view::string_view string, con * @param delimiters * @return */ -bool Search::SearchString(view::string_view string, const QString &searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, Result *result, const QString &delimiters) { +bool Search::SearchString(std::string_view string, const QString &searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, Result *result, const QString &delimiters) { assert(result); @@ -622,7 +622,7 @@ bool Search::SearchString(view::string_view string, const QString &searchString, return false; } -bool Search::replaceUsingRE(const QString &searchStr, const QString &replaceStr, view::string_view sourceStr, int64_t beginPos, std::string &dest, int prevChar, const QString &delimiters, int defaultFlags) { +bool Search::replaceUsingRE(const QString &searchStr, const QString &replaceStr, std::string_view sourceStr, int64_t beginPos, std::string &dest, int prevChar, const QString &delimiters, int defaultFlags) { return replaceUsingRegex( searchStr.toStdString(), replaceStr.toStdString(), diff --git a/src/Search.h b/src/Search.h index e09c1d63..e68fe8ff 100644 --- a/src/Search.h +++ b/src/Search.h @@ -4,8 +4,8 @@ #include "Direction.h" #include "SearchType.h" -#include "Util/string_view.h" #include "WrapMode.h" +#include #include #include @@ -31,12 +31,12 @@ struct Result { }; bool isRegexType(SearchType searchType); -bool replaceUsingRE(const QString &searchStr, const QString &replaceStr, view::string_view sourceStr, int64_t beginPos, std::string &dest, int prevChar, const QString &delimiters, int defaultFlags); -bool SearchString(view::string_view string, const QString &searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, Result *result, const QString &delimiters); -std::optional SearchString(view::string_view string, const QString &searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, const QString &delimiters); +bool replaceUsingRE(const QString &searchStr, const QString &replaceStr, std::string_view sourceStr, int64_t beginPos, std::string &dest, int prevChar, const QString &delimiters, int defaultFlags); +bool SearchString(std::string_view string, const QString &searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, Result *result, const QString &delimiters); +std::optional SearchString(std::string_view string, const QString &searchString, Direction direction, SearchType searchType, WrapMode wrap, int64_t beginPos, const QString &delimiters); int defaultRegexFlags(SearchType searchType); int historyIndex(int nCycles); -std::optional ReplaceAllInString(view::string_view inString, const QString &searchString, const QString &replaceString, SearchType searchType, int64_t *copyStart, int64_t *copyEnd, const QString &delimiters); +std::optional ReplaceAllInString(std::string_view inString, const QString &searchString, const QString &replaceString, SearchType searchType, int64_t *copyStart, int64_t *copyEnd, const QString &delimiters); void saveSearchHistory(const QString &searchString, QString replaceString, SearchType searchType, bool isIncremental); HistoryEntry *HistoryByIndex(int index); diff --git a/src/SmartIndentEvent.h b/src/SmartIndentEvent.h index 3d56a23b..2430bbdd 100644 --- a/src/SmartIndentEvent.h +++ b/src/SmartIndentEvent.h @@ -3,7 +3,7 @@ #define SMART_INDENT_EVENT_H_ #include "TextCursor.h" -#include "Util/string_view.h" +#include enum SmartIndentReason { NEWLINE_INDENT_NEEDED, @@ -14,7 +14,7 @@ struct SmartIndentEvent { SmartIndentReason reason; TextCursor pos; int request; - view::string_view charsTyped; + std::string_view charsTyped; }; #endif diff --git a/src/Tags.cpp b/src/Tags.cpp index 06b5d450..fcab4a7d 100644 --- a/src/Tags.cpp +++ b/src/Tags.cpp @@ -10,8 +10,7 @@ #include "Util/FileSystem.h" #include "Util/Input.h" #include "Util/User.h" - -#include +#include "Util/algorithm.h" #include #include @@ -31,6 +30,8 @@ #include #endif +#include + namespace Tags { namespace { @@ -94,7 +95,7 @@ QList getTagFromTable(QMultiHash &table, const QString &name) * separators (for now) are \n. If the end of string is reached before n * lines, return the number of lines advanced, else normally return -1. */ -int64_t moveAheadNLines(view::string_view str, int64_t &pos, int64_t n) { +int64_t moveAheadNLines(std::string_view str, int64_t &pos, int64_t n) { int64_t i = n; while (static_cast(pos) != str.size() && n > 0) { @@ -1114,7 +1115,7 @@ QList lookupTag(const QString &name, SearchMode mode) { ** into NEdit compatible regular expressions and does the search. ** Etags search expressions are plain literals strings, which */ -bool fakeRegExSearch(view::string_view buffer, const QString &searchString, int64_t *startPos, int64_t *endPos) { +bool fakeRegExSearch(std::string_view buffer, const QString &searchString, int64_t *startPos, int64_t *endPos) { if (searchString.isEmpty()) { return false; @@ -1124,7 +1125,7 @@ bool fakeRegExSearch(view::string_view buffer, const QString &searchString, int6 Direction dir; bool ctagsMode; - view::string_view fileString = buffer; + std::string_view fileString = buffer; // determine search direction and start position if (*startPos != -1) { // etags mode! @@ -1137,7 +1138,7 @@ bool fakeRegExSearch(view::string_view buffer, const QString &searchString, int6 ctagsMode = true; } else if (searchString.size() > 1 && searchString[0] == QLatin1Char('?')) { dir = Direction::Backward; - searchStartPos = static_cast(fileString.size()); + searchStartPos = ssize(fileString); ctagsMode = true; } else { qWarning("NEdit: Error parsing tag file search string"); diff --git a/src/Tags.h b/src/Tags.h index 5d51c923..98209be0 100644 --- a/src/Tags.h +++ b/src/Tags.h @@ -4,7 +4,7 @@ #include "CallTip.h" #include "Util/QtHelper.h" -#include "Util/string_view.h" +#include #include @@ -62,7 +62,7 @@ QList lookupTag(const QString &name, SearchMode mode); bool addRelTagsFile(const QString &tagSpec, const QString &windowPath, SearchMode mode); bool addTagsFile(const QString &tagSpec, SearchMode mode); bool deleteTagsFile(const QString &tagSpec, SearchMode mode, bool force_unload); -bool fakeRegExSearch(view::string_view buffer, const QString &searchString, int64_t *startPos, int64_t *endPos); +bool fakeRegExSearch(std::string_view buffer, const QString &searchString, int64_t *startPos, int64_t *endPos); int tagsShowCalltip(TextArea *area, const QString &text); void showMatchingCalltip(QWidget *parent, TextArea *area, int id); diff --git a/src/TextArea.cpp b/src/TextArea.cpp index 0da9b6d2..19e6d348 100644 --- a/src/TextArea.cpp +++ b/src/TextArea.cpp @@ -14,6 +14,7 @@ #include "TextAreaMimeData.h" #include "TextBuffer.h" #include "TextEditEvent.h" +#include "Util/algorithm.h" #include "X11Colors.h" #include @@ -40,9 +41,11 @@ #include #endif -#include +#include #include +#include + #define EMIT_EVENT_0(name) \ do { \ if (!(flags & SuppressRecording)) { \ @@ -67,7 +70,7 @@ namespace { * @param len * @return */ -QString asciiToUnicode(view::string_view string) { +QString asciiToUnicode(std::string_view string) { QString s; s.reserve(static_cast(string.size())); @@ -250,7 +253,7 @@ void bufPreDeleteCB(TextCursor pos, int64_t nDeleted, void *arg) { /* ** Callback attached to the text buffer to receive modification information */ -void bufModifiedCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, view::string_view deletedText, void *arg) { +void bufModifiedCB(TextCursor pos, int64_t nInserted, int64_t nDeleted, int64_t nRestyled, std::string_view deletedText, void *arg) { auto area = static_cast