You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does not break backwards compatibility, and improves compatibility when translating from Ruby.
Would be nice to make a search if #swapcase is used in any real world Ruby projects.
There have been varying opinions about it in the past about both its usefulness and whether the library should implement "nice to have" trivial methods like this.
One actual use case of swapcase I found is supporting base 62 in BigInt#to_s, which is actually supported by GMP (plus bases 37..61 which Crystal doesn't support at all):
For base in the range 2..36, digits and lower-case letters are used; for -2..-36, digits and upper-case letters are used; for 37..62, digits, upper-case letters, and lower-case letters (in that significance order) are used.
The problem is, the current to_s for primitive integers uses lowercase letters for the digits 10..35, and uppercase letters for 36..61, so swapcase would precisely fix the string returned by GMP with one call. Unfortunately it is also inappropriate here because it is way faster to modify the C string in-place and Int#to_s needs to be as fast as possible.
A Unicode-correct implementation requires us to invent mappings from e.g. U+01F2 LATIN CAPITAL LETTER D WITH SMALL LETTER Z Dz to the 2-character string dZ.
While I personally do not have a realworld problem for this request, it's a common coding challenge method, and Ruby has String#swapcase
Does not break backwards compatibility, and improves compatibility when translating from Ruby.
Would be nice to make a search if #swapcase is used in any real world Ruby projects.
There have been varying opinions about it in the past about both its usefulness and whether the library should implement "nice to have" trivial methods like this.
Related Issues #2230 #2805 #2889 #7142 #8554
The text was updated successfully, but these errors were encountered: