Skip to content

Use Ratcliff-Obershelp string matcher to check file names and paths #2485

Open
@MyreMylar

Description

@MyreMylar

Currently we use pythons difflib in sysfont.py to prompt the user with suggestions on near miss errors in their font file names.

e.g.

"File not found: You tried to load /images/Cat.png - Did you mean /images/cat.png"

The difflib library apparently uses the Ratcliff-Obershelp algorithm to determine nearness of a string to other strings in a set. There is no particular reason we couldn't also be doing this in our C code with file paths for loaded sounds, images and fonts. Try a load and then if we get an error, gather up (at least) a few filename strings in the same directory as the requested file path and then suggest the nearest one to the request as an alternative.

I found one example of this algorithm under a permissive unlicense license here: https://github.com/wernsey/miscsrc/blob/master/simil.c

That we could consider vendoring to solve this fairly quickly.

Metadata

Metadata

Assignees

Labels

fontpygame.fontimagepygame.imagemixerpygame.mixerrwopsSDL's IO loading/streaming code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions