kiwiirc / irc-framework

🛠️ A better IRC framework for node.js. For bots and full clients.
MIT License
181 stars 64 forks source link

Support CASEMAPPING, add a helper function to casefold #260

Closed xPaw closed 3 years ago

xPaw commented 4 years ago

Example code: https://github.com/jesopo/ircstates/blob/ca9abfc34b78b12e34bacd5515b5cae64d690dd5/ircstates/casemap.py#L9

We use toLowerCase now, but that's not correct as that will also apply to unicode characters, not just ascii.

Something like IrcClient.casefold(string) would probably work here. It would look at options.CASEMAPPING to determine how to fold.

@prawnsalad thoughts? Neither kiwi or lounge currently handle it.

prawnsalad commented 4 years ago

Makes sense to add this. Wouldn't it have an upper and lower function rather than a single casefold function though?

xPaw commented 4 years ago

I guess so. I haven't seen upper case being relevant anywhere though.

What would custom casefolding apply to? Nicks and channel names? Should it also be done on command names and whatnot?

prawnsalad commented 4 years ago

Spoke to the inspircd dev on this:

[13:20:03]  prawnsalad: so if we use it to just compare channel names and nicks, then thats prtty much all it would be used for in the client side?
[13:21:27]  SadieP: yeah

So I guess a fast (since it would be a very hot function getting called all the time in clients) simple string compare function would work I guess? IrcClient.caseCompare(str1, str2)?

xPaw commented 4 years ago

I think a separate function to lowercase would be good to have too. I think TL has a couple of places where it's beneficial.

But caseCompare likely solves quite a few of these use cases.

xPaw commented 4 years ago

Prototyped here: https://github.com/kiwiirc/irc-framework/compare/casefolding

xPaw commented 4 years ago

The functions should be good to go. Can you verify the use of these functions across the code base and write up some docs for it?