gregex: Clarify docs for end_pos

Actually say that it returns the byte after the end of the match (just
like `endptr` in `g_strtod()` does, for example). Previously that wasn’t
documented (but was clear from the unit tests).

Brought up in https://discourse.gnome.org/t/g-match-info-fetch-pos-returns-incorrect-end-pos/28998

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2025-05-21 23:31:50 +01:00
parent 05193cdd4d
commit a47659d186

View File

@@ -1445,7 +1445,7 @@ g_match_info_fetch (const GMatchInfo *match_info,
* @start_pos: (out) (optional): pointer to location where to store
* the start position, or %NULL
* @end_pos: (out) (optional): pointer to location where to store
* the end position, or %NULL
* the end position (the byte after the final byte of the match), or %NULL
*
* Retrieves the position in bytes of the @match_num'th capturing
* parentheses. 0 is the full text of the match, 1 is the first
@@ -1455,6 +1455,9 @@ g_match_info_fetch (const GMatchInfo *match_info,
* (e.g. sub pattern 1, matching "b" against "(a)?b") then @start_pos
* and @end_pos are set to -1 and %TRUE is returned.
*
* As @end_pos is set to the byte after the final byte of the match (on success),
* the length of the match can be calculated as `end_pos - start_pos`.
*
* If the match was obtained using the DFA algorithm, that is using
* g_regex_match_all() or g_regex_match_all_full(), the retrieved
* position is not that of a set of parentheses but that of a matched
@@ -1574,7 +1577,7 @@ g_match_info_fetch_named (const GMatchInfo *match_info,
* @start_pos: (out) (optional): pointer to location where to store
* the start position, or %NULL
* @end_pos: (out) (optional): pointer to location where to store
* the end position, or %NULL
* the end position (the byte after the final byte of the match), or %NULL
*
* Retrieves the position in bytes of the capturing parentheses named @name.
*
@@ -1582,6 +1585,9 @@ g_match_info_fetch_named (const GMatchInfo *match_info,
* (e.g. sub pattern `"X"`, matching `"b"` against `"(?P<X>a)?b"`)
* then @start_pos and @end_pos are set to -1 and %TRUE is returned.
*
* As @end_pos is set to the byte after the final byte of the match (on success),
* the length of the match can be calculated as `end_pos - start_pos`.
*
* Returns: %TRUE if the position was fetched, %FALSE otherwise.
* If the position cannot be fetched, @start_pos and @end_pos
* are left unchanged.