Closed Bug 826144 Opened 10 years ago Closed 10 years ago

MOZ_UTF16() macro needs intermediary macro to handle stringification and concatenation


(Core :: MFBT, defect)

Not set



Tracking Status
firefox19 --- wontfix
firefox20 --- fixed


(Reporter: cpeterson, Assigned: cpeterson)




(1 file)

As described in nsStringAPI.h, the NS_LL macro needed an intermediary macro (NS_L) to correctly handle stringification and concatenation of macro parameters to NS_LL. Char16.h's MOZ_UTF16() macro needs to do the same thing.

I chose the name `MOZ_UTF16_()` for the intermediary macro because it's a private implementation detail of MOZ_UTF16() and AFAIK does not need to be called by other code. I am open to suggestions for better names. <:)

Note that comm-central has a few uses of NS_L instead of NS_LL, but I don't see why they couldn't just use NS_LL:
Attachment #697300 - Flags: review?(jwalden+bmo)
What about "MOZ_u" for the public name? It looks more close to "u" prefix.
(In reply to Masatoshi Kimura [:emk] from comment #1)
> What about "MOZ_u" for the public name? It looks more close to "u" prefix.

"MOZ_u" sounds OK to me, though macro naming conventions prefer uppercase names. "MOZ_U", however, would be a bad name because it looks like C++11's U"" prefix for UTF-32 string literals.
Comment on attachment 697300 [details] [diff] [review]

Review of attachment 697300 [details] [diff] [review]:

::: mfbt/Char16.h
@@ +27,5 @@
>      * to Windows's 16-bit wchar_t so we can declare UTF-16 literals as constant
>      * expressions (and pass char16_t pointers to Windows APIs). We #define our
>      * char16_t as a macro to override yval.h's typedef of the same name.
>      */
> +#  define MOZ_UTF16_(s) L##s

I think we usually use a _HELPER suffix for macros like this, so make this MOZ_UTF16_HELPER.  Such a name is also less amenable to typos that might use this macro outside its one intended use in this file.
Attachment #697300 - Flags: review?(jwalden+bmo) → review+
waldo: do you have an opinion on the public macro's name "MOZ_UTF16" versus emk's "MOZ_u" suggestion?
MOZ_UTF16 seems more readable to me than MOZ_u, plus it's what we already have, so I'd stick with that name.
Closed: 10 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.