diff --git a/NEWS b/NEWS index 89e97808..c560a4fa 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,9 @@ lnav v0.9.1: in the copy if they are enabled. * Log messages that cannot be parsed properly will be given an "invalid" log level and the invalid portions colored yellow. + * The range_start and range_stop values of the regexp_capture() results + now start at 1 instead of zero to match with what the other SQL string + functions expect. Fixes: * Unicode text can now be entered in prompts. diff --git a/src/internals/sql-ref.rst b/src/internals/sql-ref.rst index 1dea32ea..653bcaa5 100644 --- a/src/internals/sql-ref.rst +++ b/src/internals/sql-ref.rst @@ -2683,12 +2683,12 @@ regexp_capture(*string*, *pattern*) ;SELECT * FROM regexp_capture('a=1; b=2', '(\w+)=(\d+)') match_index capture_index capture_name capture_count range_start range_stop content - 0 0 3 0 3 a=1 - 0 1 3 0 1 a - 0 2 3 2 3 1 - 1 0 3 5 8 b=2 - 1 1 3 5 6 b - 1 2 3 7 8 2 + 0 0 3 1 4 a=1 + 0 1 3 1 2 a + 0 2 3 3 4 1 + 1 0 3 6 9 b=2 + 1 1 3 6 7 b + 1 2 3 8 9 2 **See Also:** diff --git a/src/regexp_vtab.cc b/src/regexp_vtab.cc index 366541e6..2ab3e990 100644 --- a/src/regexp_vtab.cc +++ b/src/regexp_vtab.cc @@ -141,10 +141,10 @@ CREATE TABLE regexp_capture ( sqlite3_result_int64(ctx, vc.c_context.get_count()); break; case RC_COL_RANGE_START: - sqlite3_result_int64(ctx, cap.c_begin); + sqlite3_result_int64(ctx, cap.c_begin + 1); break; case RC_COL_RANGE_STOP: - sqlite3_result_int64(ctx, cap.c_end); + sqlite3_result_int64(ctx, cap.c_end + 1); break; case RC_COL_CONTENT: if (cap.is_valid()) { diff --git a/src/view_curses.cc b/src/view_curses.cc index 6b0500ec..47ec3cff 100644 --- a/src/view_curses.cc +++ b/src/view_curses.cc @@ -235,7 +235,7 @@ void view_curses::mvwattrline(WINDOW *window, } if (attr_range.lr_end == -1) { - attr_range.lr_end = line_width_chars; + attr_range.lr_end = lr_chars.lr_start + line_width_chars; } if (attr_range.lr_end < lr_chars.lr_start) { continue; diff --git a/test/test_sql_str_func.sh b/test/test_sql_str_func.sh index fffecc1f..59c3c945 100644 --- a/test/test_sql_str_func.sh +++ b/test/test_sql_str_func.sh @@ -174,6 +174,13 @@ Row 0: EOF +run_test ./drive_sql "SELECT substr('#foo', range_start) AS value FROM regexp_capture('#foo', '(\w+)') WHERE capture_index = 1" + +check_output "" <