Closed Bug 384979 Opened 17 years ago Closed 17 years ago

Remove nsTextFormatter from the mailnews code.

Categories

(MailNews Core :: Internationalization, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: prasad, Assigned: prasad)

References

Details

Attachments

(1 file, 2 obsolete files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4) Gecko/20070508 Iceweasel/2.0.0.4 (Debian-2.0.0.4-1)
Build Identifier: 

nsTextFormatter is not available in frozen code.  The only current alternative to part of its functionality is nsIStringBundle.  While string bundle are probably the only place where nsTextFormatter is used, the interface, for technical reasons could not have a variable argument function.

It ended up exporting FormatStringFromID and FormatStringFromName, both of which take an array of 10 elements as params for nsTextFormatter::smprintf - All params PRUnichar arrays.

Hence, as in all other parts of the mozilla tree (browser specially) it is a good idea to migrate all localization strings to use %S as format instead of %d and %ld.  The backend code could then convert the numbers to strings before calling FormatStringById/FormatStringByName.

This migration has a potential to break existing localized versions.  Simple strings in properties files like "4009=Received %ld of %ld messages" in localMsgs.properties will have to change to "4009=Received %s of %s messages"

Reproducible: Always
The other option would be to make nsTextFormatter available. Benjamin?
I might be relevant to note that there are only about 25 strings that use %d and %ld in the format string.
Blocks: 379070
Status: UNCONFIRMED → NEW
Ever confirmed: true
any update on this bug??? Benjamin, any comments?
No, not really, however you want to fix it is probably ok.
Attached file Variable Arguments with Variable Types (obsolete) —
Currently nsIStringBundle exposes FormatStringFromID and FormatStringFromName, but imposes a restriction of having not more than ten arguments, which is practical.

How about having overloaded functions FormatStringFromID/Name which take an array of structures instead of array of strings as arguments?  What I am getting at is to have something like the do_print function the attached file.

The options I think we currently have are:
1. Convert all the strings to use only %S as the format specifier and convert all other types to integers before calling FormatStringFromID/Name
2. Make nsTextFormatter available through frozen linkage
3. Something like what is in the attached file.

Comments and any other alternatives welcome
Prasad, I would vote for option 2: expose nsTextFormatter to frozen linkage.
Scott, as your vote goes, exposing nsTextFormatter to frozen linkage seems to be the cleanest solution.  Will do that.
Status: NEW → ASSIGNED
Assignee: smontagu → prasad
Status: ASSIGNED → NEW
This patch adds creates a copy of nsTextFormatter in XPCOM glue code.  It uses frozen linkage and nsMemory based memory model.
Attachment #270768 - Attachment is obsolete: true
Attachment #278220 - Flags: review?(benjamin)
Comment on attachment 278220 [details] [diff] [review]
nsTextFormatter in xpcom glue code.

mozilla-new/xpcom/glue/nsTextFormatterAPI.cpp

>+#ifdef DEBUG
>+PRBool nsTextFormatterAPI::SelfTest()

1) This function shouldn't be here. It should be in xpcom/tests and should be hooked up to "make check"
2) This patch doesn't remove the xpcom/ds version of the same code. Why not?

But overall this looks correct. Please submit a new patch with these things fixed.
Attachment #278220 - Flags: review?(benjamin) → review-
This patch moves nsTextFormatter to glue code.  I changed the memory model and few non-frozen uses of CRT and strings.

This should solve the issue of using nsTextFormatter in mailnews and other places.
Attachment #278220 - Attachment is obsolete: true
Attachment #279891 - Flags: review?(benjamin)
Comment on attachment 279891 [details] [diff] [review]
Move nsTextFormatter to Glue

>diff -N -U 8 -p -r -x CVS xpcom/glue/nsTextFormatter.h xpcom-new/glue/nsTextFormatter.h

>+class NS_COM nsTextFormatter {

needs to be NS_COM_GLUE now
Attachment #279891 - Flags: review?(benjamin)
Attachment #279891 - Flags: review+
Attachment #279891 - Flags: approval1.9+
I've checked in this change with the NS_COM_GLUE change for Prasad.
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
FYI, I had to adjust the Makefile in xpcom\tests to look like:

@$(RUN_TEST_PROGRAM) $(FINAL_TARGET)/TestTextFormatter$(BIN_SUFFIX)

in order to fix the mac builds which were orange. Thanks to benjamin for suggesting the fix. 
Product: Core → MailNews Core
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: