Module talk:BaseConvert
Fringe feature
About possible hexadecimal input. Unicode defines that the regular characters "0...9A...F" can be recognised as hexadecimal characters. There are no separate characters defined for hex notation. All fine. Now there are more characters that, according to Unicode, may be recognised as hexadecimal. They are socalled Fullwidth form characters. (see here and here).
Characters in Unicode marked Hex_Digit=Yes [a]
| |||
---|---|---|---|
0123456789ABCDEF |
Basic Latin, capitals | Also ASCII_Hex_Digit=Yes
| |
0123456789abcdef |
Basic Latin, small letters | Also ASCII_Hex_Digit=Yes
| |
0123456789ABCDEF |
Fullwidth forms, capitals | ||
0123456789abcdef |
Fullwidth forms, small letters | ||
a. ^ "Unicode 16.0 UCD: PropList.txt". 2024-05-31. Retrieved 2024-09-13. |
Their code points are U+FF10 .. U+FF19 (numbers 0-9), U+FF21 .. U+FF26 (A-F), U+FF41 .. U+FF46 (a-f). So, generally spoken, there could be hex input by this regular Unicode input. We could decide that this input should be recognised (and so converted in this template).
When or where does that Halfwidth input occur? The characters are pre-Unicode glyphs. If I understand it well, they are used in East Asian (CJK) texts, possibly for Western quotes (including Western numbers). So including them would make BaseConvert a more full generic template, especially when exporting the module from enwiki. -DePiep (talk) 21:43, 24 February 2013 (UTC)
- Ok, makes sense that this could be useful if this module is exported to other language wikis. I've added normalization of full-width chars. Toohool (talk) 00:11, 25 February 2013 (UTC)
- Amazingly and bright! And this way all bases are covered, not just 16. Thanks (also for taking time to decipher my post). -DePiep (talk) 09:18, 25 February 2013 (UTC)
Strip off "#" from incoming hex numbers
![]() | This edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
Toohool can you make this work? I tried and it seemed to work fine on the Module:BaseConvert/sandbox and the Template:Module:BaseConvert/testcases (now deleted per my request). Thanks Technical 13 (talk) 17:54, 9 September 2013 (UTC)
Not done: You are already autoconfirmed. You do not need to use this template to edit a semi-protected page. Thanks, Celestra (talk) 02:44, 11 September 2013 (UTC)
It would be easy to do, but why? Is there some particular use case where this would be helpful? Toohool (talk) 06:09, 11 September 2013 (UTC)
Suggestion: metatable allowing this to be called as 10to16 etc
In the sandbox (diff) there is a metatable set that allows this module to be called as
Markup | Renders as |
---|---|
{{#invoke:BaseConvert/sandbox|16to10| FF }} |
255 |
{{#invoke:BaseConvert/sandbox|10to36|500}} |
DW |
{{#invoke:BaseConvert/sandbox|10to16|Foo|default=0}} |
0 |
This looks nicer and is clearer than the |base=
argument which doesn't specify whether it's the input base or output base. All options except |base=
, |from=
and |n=
are supported.
On a technical note: it doesn't interfere with the original convert function as the "real" members of p are checked before __index
is called. It will run for anything of this form so e.g. 500to400 will be passed on to _convert, but if someone tries to call a function not of this form they will get the usual error message. User:GKFXtalk 08:27, 25 April 2021 (UTC)
convert with 'Module:No globals' error?
I have used the code as documented (2 lines, see below). It looks like that, by adding require('Module:No globals')
, an error is triggered.
Reproduce: see Module:User:DePiep/BCdemo:
- |testBC: Script error: No such module "User:DePiep/BCdemo".
- |testBCnoglobals: Script error: No such module "User:DePiep/BCdemo".
Something I can do? I want to use the Module:No globals in top (not in functions), i.e. for the whole module. @GKFX and Toohool: DePiep (talk) 18:27, 11 April 2022 (UTC)
- @DePiep: I think you just need to precede the first two function declarations with
local
(solocal function ...
. User:GKFXtalk 19:14, 11 April 2022 (UTC)- Done, see Module:User:DePiep/BCdemo. Not solved; note that I needed public function p.xxx(). BTW, you are fee to edit in there (it's a dedicated test-demo). -DePiep (talk) 19:26, 11 April 2022 (UTC)
Got it. In Module:BaseConvert/sandbox, I have made local
three functions: diff. To consider: should _convert()
be public i.e., be p._convert()
(not local
)? Depends on the frame/args handling in p.convert()
if I'm right.
- Testing Module:BaseConvert/sandbox i.c.w. Module:No globals
- |testBCsbox: Script error: No such module "User:DePiep/BCdemo".
- |testBCsboxnoglobals: Script error: No such module "User:DePiep/BCdemo".
Anyway, how to arrive at an edit proposal? -DePiep (talk) 19:46, 11 April 2022 (UTC)
- Re. _convert, it has too many positional arguments to be a nice API. I would stick with convert as the public function since it takes a table which emulates named arguments. User:GKFXtalk 19:56, 11 April 2022 (UTC)
Preparing Edit Request, tech review please
I propose to change all code in Module:BaseConvert with code from Module:BaseConvert/sandbox (diff).
The issue: when Module:No globals is used per documentation, Module:BaseConvert throws an error for r/w a global variable (like "Tried to write global normalizeFullWidthChars"). This is solved by declaring all internal functions explicitly local
. There are three, see the diff; the sandbox was tested with 'No globals' too.
If no (tech) issues or questions arise, I'll make this a formal Edit Request. (32k transclusions). -DePiep (talk) 20:18, 11 April 2022 (UTC)
- There are still some globals in the sandbox. I'll fix it soon (a couple of hours from now). Johnuniq (talk) 05:34, 12 April 2022 (UTC)
- I cleaned the whitespace in both the sandbox and main modules (no trailing spaces, use tabs for indents). I also fixed the remaining globals in the sandbox and made a couple of minor tweaks. The diff with the main module is very minor and I don't think an edit request is needed. I'll watch this for a while and if you want, I'll update the main module if there are no other suggestions. Johnuniq (talk) 07:27, 12 April 2022 (UTC)
- @Johnuniq: OK, thx. Pls proceed as you think best. -DePiep (talk) 11:18, 12 April 2022 (UTC)
- OK, I updated the main module so it now has no globals. Johnuniq (talk) 04:59, 13 April 2022 (UTC)
- @Johnuniq: OK, thx. Pls proceed as you think best. -DePiep (talk) 11:18, 12 April 2022 (UTC)
- I cleaned the whitespace in both the sandbox and main modules (no trailing spaces, use tabs for indents). I also fixed the remaining globals in the sandbox and made a couple of minor tweaks. The diff with the main module is very minor and I don't think an edit request is needed. I'll watch this for a while and if you want, I'll update the main module if there are no other suggestions. Johnuniq (talk) 07:27, 12 April 2022 (UTC)