Go to the source code of this file.
◆ edit_distance_t
Find near-matches for strings and identifiers.
Copyright (C) 2015-2025 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>.
◆ find_closest_string()
const char * find_closest_string |
( |
const char * | target, |
|
|
const auto_vec< const char * > * | candidates ) |
|
extern |
Given TARGET, a non-NULL string, and CANDIDATES, a non-NULL ptr to
an autovec of non-NULL strings, determine which element within
CANDIDATES has the lowest edit distance to TARGET. If there are
multiple elements with the same minimal distance, the first in the
vector wins.
If more than half of the letters were misspelled, the suggestion is
likely to be meaningless, so return NULL for this case.
References candidate(), candidates, best_match< GOAL_TYPE, CANDIDATE_TYPE >::consider(), FOR_EACH_VEC_ELT, gcc_assert, best_match< GOAL_TYPE, CANDIDATE_TYPE >::get_best_meaningful_candidate(), and i.
Referenced by candidates_list_and_hint(), gcc::dump_manager::dump_switch_p(), and option_proposer::suggest_option().
◆ get_edit_distance() [1/2]
◆ get_edit_distance() [2/2]
edit_distance_t get_edit_distance |
( |
const char * | s, |
|
|
int | len_s, |
|
|
const char * | t, |
|
|
int | len_t ) |
|
extern |
spellcheck.cc
Get the edit distance between the two strings: the minimal
number of edits that are needed to change one string into another,
where edits can be one-character insertions, removals, or substitutions,
or transpositions of two adjacent characters (counting as one "edit").
This implementation uses a modified variant of the Wagner-Fischer
algorithm for the Damerau-Levenshtein distance; specifically, the
"optimal string alignment distance" or "restricted edit distance"
variant. This implementation has been further modified to take
case into account.
References BASE_COST, CASE_COST, debug, i, and MIN.
Referenced by best_match< GOAL_TYPE, CANDIDATE_TYPE >::consider(), and get_edit_distance().
◆ get_edit_distance_cutoff()
edit_distance_t get_edit_distance_cutoff |
( |
size_t | goal_len, |
|
|
size_t | candidate_len ) |
|
extern |
Generate the maximum edit distance for which we consider a suggestion
to be meaningful, given a goal of length GOAL_LEN and a candidate of
length CANDIDATE_LEN.
This is a third of the length of the candidate or of the goal,
whichever is bigger.
References BASE_COST, gcc_assert, MAX, and MIN.
◆ MAX_EDIT_DISTANCE