• Print

Author Topic: Converting UTF-8 to closest available ASCII  (Read 14 times)

0 Members and 1 Guest are viewing this topic.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Converting UTF-8 to closest available ASCII
« on: November 15, 2015, 05:25:09 am »
Check out this ULX mod someone made -- https://scriptfodder.com/scripts/view/32/reviews/

Think it's worth duplicating that behavior ourselves?

Not sure how he accomplished this though. Given that UTF-8 (which is what I assume Steam uses) has 1,112,064 valid code points, I doubt that he's compiled a translation table containing all options. Googling seems to pull up a Unix utility called "iconv" (http://stackoverflow.com/questions/1975057), which when I tested locally, works great. However, it's not much help Lua-side. There are even Lua bindings for iconv, but that's more work than most server administrators are willing to put in.

Thoughts?
Experiencing God's grace one day at a time.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Converting UTF-8 to closest available ASCII
« Reply #1 on: November 15, 2015, 05:28:23 am »
Searching around on script fodder is pretty fun -- https://scriptfodder.com/scripts/search/ULX/

We have the usual "extra command" packs. One of them has a feature to copy a user's information to the system clipboard -- a new API I didn't realize Garry introduced. We could probably find some utility for that in ULX as well. :)
Experiencing God's grace one day at a time.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Converting UTF-8 to closest available ASCII
« Reply #2 on: November 15, 2015, 06:22:35 pm »
That name mod does look intriguing. I believe it was made by !cake, and I've seen him around a bit on Facepunch. According to the description, he is using a database of known similar characters: "Uses an auxiliary database of over 1500 character mappings, developed over two years of server hosting experience"
"Character mappings are updated regularly. Just download the latest version of this addon!"

That iconv solution is very interesting.. I wonder how we could make that work to our advantage. :)

As for the clipboard thing.. I recall some devs complaining recently that direct access to clipboard was removed from lua due to potentially nefarious purposes. I don't remember the outcome, just that there was complaining. :P There are likely still ways to use it, but it might require some sort of user interaction first.
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Converting UTF-8 to closest available ASCII
« Reply #3 on: November 15, 2015, 07:03:54 pm »
It's indeed by !cake.
Clicking on the gear hitting the stick character icon brings up all his scriptfodder projects, one of which is !cake AntiCheat

I like the idea, not quite sure how it's used though.
Autocomplete in the chat?
I mean, I see the picture he's got, but, how is the user presented with and know that (square * many times) is user 'blah', especially if there is more than one user with non-utf8
« Last Edit: November 15, 2015, 07:05:59 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Converting UTF-8 to closest available ASCII
« Reply #4 on: November 17, 2015, 07:29:13 am »
This looks promising, though needs more research -- https://github.com/ashtuchkin/iconv-lite (tables could be adapted for our needs?)

JamminR, it converts each character to the closest available ASCII. Presumably boxes would be blank or excluded, since nothing maps.

So --
"?M?e???S?o???A?w?e?s?o?m?e" => "MeSoAwesome"

Experiencing God's grace one day at a time.

  • Print