![]() |
|
|
message formatting IntroductionProgrammers often compose sentences from smaller pieces using mechanisms such as C's printf family of functions. Since sentence syntax is highly dependent on human language, it is necessary to vary the order in which Subject, Verb and Object appear in the sentence.ProposalSome operating systems provide this functionality as part of their implementation of the C printf family. NSPR has also implemented this. Here is an example of such a call:
#include "prprf.h"
...
char buf[128];
char *dir;
int nFiles;
...
PR_snprintf(buf, sizeof(buf), "There are %1$d files in directory %2$s.", nFiles, dir);
Note that the above example is bad since it hard-codes English into the binary. See the String Resources document for proper externalization details. The proposal is to use NSPR's printf family for language-sensitive message formatting. ProblemsCurrently, NSPR's printf functions support regular char* strings with %s. However, the NGLayout-based client is using Unicode (unsigned short) strings almost everywhere. We could solve this problem by writing a new set of functions for Unicode strings. Or extend the current functions using e.g. %ls for Unicode strings. (The ISO C standard uses %lc and %ls for wint_t and wchar_t* respectively.) Or convert from Unicode to UTF-8 and use the current NSPR functions.
|
|||||||
| Copyright © 1998 The Mozilla Organization. | ||||||||