import std/editdistance
var moduleNamespace = "pangocairo"
var h1 = ["libpango-1.0.so.0", "libpangocairo-1.0.so.0", "libpangoft2-1.0.so.0"]
for el in h1:
echo editDistanceAscii(el, moduleNamespace), " ", el, " ", moduleNamespace
$ nim c -r t.nim
Hint: /tmp/hhh/t [Exec]
11 libpango-1.0.so.0 pangocairo
12 libpangocairo-1.0.so.0 pangocairo
14 libpangoft2-1.0.so.0 pangocairo
Goal was to pick the middle of the two strings -- obviously not a clever idea. But I still wonder why the distance is only 11 for the first string but 12 for the middle?
If you wonder why we need that, the issue was discussed in
https://discourse.gnome.org/t/title-in-text-due-to-discourse-bug/4477
libpango-1.0.so.0 x is delete, r replace xxxpangorrrrxxoxx 7 deletions, 4 replacements
libpangocairo-1.0.so.0 xxxpangocairoxxxxxxxxx 12 deletions
Check for instance with this funny online calculator, which shows the corresponding table:
https://phiresky.github.io/levenshtein-demo/
Turns out, the reason is that the o of the cairo in the moduleNamespace can be matched with the .so of libpango-1.0.so.0. For the longer libpangocairo-1.0.so.0 the o is already "used" for the "cairo" part and thus you end up with one more.
So just a bad algorithm for what you're trying to achieve.
Turns out, the reason is that the o of the cairo in the moduleNamespace can be matched with the .so
Ah yes, I missed the so string part! Thanks.