View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002000 | 1003.1(2024)/Issue8 | System Interfaces | public | 2026-09-17 19:23 | 2026-11-17 11:46 |
| Reporter | kre | Assigned To | msbrown | ||
| Priority | normal | Severity | Objection | Type | Error |
| Status | Interpretation Required | Resolution | Accepted As Marked | ||
| Name | Robert Elz | ||||
| Organization | |||||
| User Reference | |||||
| Section | XSH 3.strfmon | ||||
| Page Number | 2129-2133 | ||||
| Line Number | 69523 69524-69526 69529 69537-65538 69540-69542 69545-69546 69557-69558 69560-69561 69567-69571 69577 69581-69590 69591-69594 69598 69613-69616 69628-69630 69632-69670 69640-69651 69672-69676 69678-69680 69684-69686 | ||||
| Interp Status | Proposed | ||||
| Final Accepted Text | 0002000:0007531 | ||||
| Summary | 0002000: XSH 3/strfmon misses info and needs attention | ||||
| Description |
| ||||
| Desired Action |
| ||||
| Tags | issue9 | ||||
|
|
All suggested wordings can obviously be improved for spelling, grammar, better standards-speak, etc. Please don't reduce precision when so doing. The suggested changes: #1) is from issues 12 and 13. I'd hope there's nothing controversial about that. Part of the change might give rise to "Of course, that's obvious" -- I don't believe in such things, nothing is too obvious to be explicit about. There is also no "output stream" involved, the output is to an array of bytes. #2 is from issues 3, 4, 5, 6 probably, maybe more. The wording suggested can probably be improved. This one is assuming that the objective is to produce nicely aligned printed (or displayed) output, not anything where particular byte offsets in the result have any particular meaning. #3 is issue 3, or a part of it. Issue 5 as well. In particular, regardless what criteria are to apply to the fill character, making the behaviour undefined if those are not met is absurd. All the implementation should ever do is insert N copies of the fill character (calculated as described in change #12). That might have the effect of not producing nicely aligned results as expected, but that's hardly undefined behaviour as the standard defines that phrase. Nor is it even unspecified, or implementation defined. It's just not what the application was hoping for. #4 is part of issue 6, and just a general tidying of the language, for added precision. #5 is issue 10. #6 is more general cleanup for better precision. #7 is issue 10 (again). #8 is more that perhaps should have been added by 0001199, and issue 2. #9 is more of issue 3. #10 is just a wording cleanup, related to a part of issue 3 (the numeric fill character has a name, and "special character" is not it!) #11 and #12 (which go together) are from issue 6. By all means improve the wording of #12. #13 is issue 4. Also more of issue 3. #14 is issue 1. Choice 1 for this one seems obvious to me, if there is no monetary decimal point character in the locale, then clearly the locale does not want fractional currency values. If it simply prefers to have no fractions, in the normal case, it can set frac_digits to 0, then the application can override that with an explicit precision. setting the decimal point to "" should thus mean "never have fractional values for this locale". However it seems relatively common in implementations to simply use the numeric decimal point if the monetary one is not defined. Personally I see no justification for that at all (even though it is what NetBSD's implementation does (or did)). Note that if you choose choice 2, then you MUST pick one of the others (1 (though that would be unlikely if the aim is to allow some decimal point string), or one of 3..7). Despite how it may appear, the standard does not require a locale to have a non-empty numeric decimal point character - it requires localedef to reject a specification where a non-empty numeric decimal point character is not defined, but nowhere does it require an implementation to use localedef when generating locale data, just that it be available to be used if desired. What's more, if it did, the POSIX (aka C) locale would be unable to be created, as that one violates all kinds of constraints imposed upon locales that localedef deals with. Choices 3 and 4 would be perhaps plausible (after all, strfmon defines "-" as a plausible negative sign should none be provided) - perhaps as follow-ons to choice 2. The rest of the choices, while possible, are absurd. #15 is just a minor cleanup, adding some precision - making it clear that the numeric decimal point is not a fallback for the monetary decimal point (perhaps the wording for that could be better). Of course should you choose choice 2 for action #14, then this one should probably be ignored. #16 is issue 8. #17 is issue 7 (or part thereof). #18 is more from issue 7. #19 is simply a grammar fix (should perhaps have been submitted as a separate "Editorial" defect report, but it seemed saner to deal with it at the same time as everything else). #20 is issue 11. #21 is more from issue 11. The actual examples will depend upon the resolution of issue 1 (action #14). #22 is kind of a follow-on to issues 9 and 8, and a correction to what is currently implied by the text. Trying with the '+' flag if a sign is wanted, is clear enough, but omitting the '+' flag and "parentheses are acceptable" are unrelated concepts, parentheses will only be used when there is no + or ( flag given, if the locale has one (and only one) of its [int_]p_sign_posn and [int_]n_sign_posn, set to 0. Both 0 and the the parentheses would be useless (this is another case just like having the positive_sign and negative_sign both empty, or identical, and makes using parentheses useless as well. But if neither of the [int_]p|n_sign_posn values is 0, parentheses won't be used, so the text "but parentheses are acceptable" is misleading. Instead, omitting the + just allows strfmon() to format the value in locales like the POSIX locale, when none of the LC_MONETARY values provides much, or any, assistance at all, while generating something reasonable. #23 is a follow-on to #22, and also relates to issue 7, and specifies how an application, for which "parentheses are acceptable" might achieve that if using the + flag fails (by using the '(' flag instead). The '(' flag also ends up (as a result of action #6) being defined in such a way that it always works (always uses (n) for negative values and just p for positive ones, regardless of what the locale specifies (or doesn't). #24 is a (potential) consequence of action #17 (issue 7), and depends upon what the resolution of the [EINVAL] issue turns out to be. #25 is a bonus extra - no issue for this one. However, dividing number/ name spaces into pieces for use by different kinds of users, when done by a standards organisation, is doomed to always either fail, or cause problems. The whole basis for the standard is to specify what the applications can expect to have happen for specific actions they take, and to tell the implementers what they need to do to produce those results. If an implementer sees the existing FUTURE DIRECTIONS and has a need for a new conversion character (perhaps to generate values in units of millions, or something, with an 'M' suffix/prefix somewhere) and does as advised by picking an upper case character for that conversion (here, probably 'M'). That's fine, they do that, and this group won't accidentally allocate M to some other use. But this implementation's new feature becomes popular, and ends up copied by all of the other implementations, because applications want to use it (assuming one can find an application that uses strfmon()!). What happens next? Clearly the new conversion character needs to be standardised. And to be compatible with what every implementation has implemented, it would need to use the 'M' as the conversion character. But the existing FUTURE DIRECTIONS says "no" to that, the standard must use a lower case character. So, we either do what it says, in which case the standard is promising an action that no implementation supports (not good, and leads to implementers needing to provide both - the conversion character the applications all use, along with the one the standard defines for the purpose - that's simply wasteful and stupid), or the standard just ignores the FUTURE DIRECTIONS and does the sane thing in a case like this. If that is to be what is likely to happen, there is no point having the FUTURE DIRECTIONS so let's just delete it now, and be done with it. Beyond that, the more likely things for an implementation to want to add, are more flag characters. After all, the difference between the conversion characters are whether they are national or international conversions ... what else could there be? Extra-terrestial currency conversions? Household currency conversions? None of that is likely, and the 'M' mooted above is more likely to be implemented as a flag, than as a conversion specification (I see no reason why an alphabetic flag can't be used - just as long as it can't be confused with a conversion character). For that usage, there's no guidance as to what new flag characters implementations might add, whilst avoiding conflicts with any new flag characters added in the standard. Since (I submit) new flags are far more likely than new conversion characters, the current FUTURE DIRECTIONS is simply useless, even if you don't agree with the argument in the previous paragraphs. There is no resolution provided for issue 14. Good luck with that one. |
|
|
Interpretation response ------------------------ The standard is unclear on this issue, and no conformance distinction can be made between alternative implementations based on this. This is being referred to the sponsor. Rationale: ------------- Existing implementations have extended the description provided. Notes to the Editor (not part of this interpretation): ------------------------------------------------------- Make the following changes, all in the XSH section 3 group of pages for strfmon (pages 2129-2133).
|
|
|
Interpretation proposed: November 4 2026 |
|
|
The proposed resolution needs some obvious corrections. First, item 22, says "On page 2133 on line 69676, after the end of the existing sentence, but within the same paragraph, add the first, or both, of the following two new sentences:" - that is not an instruction to the editor, but a request for the editor to decide what to do. Given the other changes adopted, I would expect that should be changed to: "On page 2133 on line 69676, after the end of the existing sentence, but within the same paragraph, add the following two new sentences:" (or any equivalent wording). Second: In item 14, you decided that if no mon_decimal_point is defined, the locale's LC_NUMERIC decimal_point setting should be used as the mon_decimal_point (which is fine, it allows decimal output in the C locale if requested by the format string) - but it is not what I expected the choice to be which was reflected in the examples added in item 20 of the resolution. In particular the example for the "%.2n" format should now produce 2 decimal places in the results in all cases, with '.' as the decimal point. I have yet to check the others to validate that they all remain correct. While those are clear issues that need correcting, I also still believe that making the behaviour undefined in the resolution number 3 is overly draconian. It could be unspecified if an even less specific result (which would be vaguer to be sure) is unacceptable. But "undefined" for this is absurd. |
|
|
I also see several instances of very poor grammar in the proposed new text - most of those probably stemming originally from my Desired Action text (there gets to be a point when writing something that long that going back one more time to re-read and correct it just gets to be too much). Those I think could be left for the editor to fix -- the intended meaning is obvious, the proposed words simply don't make acceptable English text --- or if it is preferred, I could supply corrections. |
|
|
I have run the examples to be added for the C (POSIX) locale through my updated test program, with a strfmon() updated to match the decision to allow the LC_NUMERIC decimal point to be used if there is no LC_MONETARY mon_decimal_point defined. They agree with the earlier examples (provided in the Desired Action, and incorporated into 0002000:0007531 (the proposed resolution) except for the results for the "%.2n" format string, where the results should be:
|
|
|
In 0002000:0007531 item 13, the text of the third sentence proposed to be added is:
but that is poor grammar. The original form of the sentence started "Only if" rather than just "If", and that could be replaced to improve things, but I now suggest that sentence be changed to be:
which I think better expresses the intent of the exception to things being nicely aligned. In the case where no left precision is specified, no alignment is ever to be expected, so I don't think that case needs mentioning. |
|
|
In 0002000:0007531 item 17, the decision to allow EILSEQ for badly encoded character data in the locale's definition is OK, though my implementation does not generate that - it simply treats badly encoded data as if it did not exist, but the way this is written I do not believe can be correct:
Imagine an application, which for whatever bizarre reason has set LC_CTYPE to zh_CN.GB2312 and has LC_MONETARY set to de_DE.UTF-8. Does the committee really believe that the encodings of the characters in values like the mon_thousands_sep (or decimal point, etc) should be GB2312 in that German locale? Or is it the intent that when obtaining locale values, the implementation must transcode all string values into the current LC_CTYPE locale's encoding (and language??) I'd suggest that similar wording be used as was added in the proposed resolution item 14, where it is the mon_decimal_point from the LC_NUMERIC category of the locale set for LC_MONETARY that is used, not whatever the current LC_NUMERIC setting happens to be. |
|
|
This is a test note, please ignore. |
|
|
KRE: Actions to be taken: 0002000:0007531 will be edited in place to add the following corrections: Correcting item 22 i change the instruction On page 2133 on line 69676, after the end of the existing sentence, but within the same paragraph, add the following two new sentences: Correcting item 20 in the same bugnote: change the example to be: %.2n [123.45] Use the POSIX locale LC_NUMERIC decimal_point [-123.45] [3456.78] Correcting item 13 in the same Bugnote: Change: If the Left Precision was not specified, or was specified and was not large enough for the value, the resulting width may differ from the length produced by any other value for which the Left Precision is sufficient. (Rationale for this one, we did want to say this but the word "may" was in the wrong place and you caught that). For 0002000:0007549, we need more clarification on the exact change you are suggesting, if you could. |
|
|
For 0002000:0007549 the text I would suggest adding would be something like
But that's just the beginning of locale related issues, for which I don't have answers. More coming in another note later (I had yet another "session timeout" - invalid security parameter, when attempting a much longer version of this note - to try and explain what I see as the harder problems, so that is going to need to wait. |
|
|
Also, just to avoid this falling through the cracks, in 0002000:0007531, item #3 in the list of changes to make, in the proposed new text to be inserted, I would change the last wordsif not, the behavior is undefined.to be if not, the behaviour is unspecified (and no, the spelling of "behaviour" is not the issue, leave out the 'u' if you really must). If there is some justification for making it undefined when the character given after the '=' flag is not a 1 column wide character, I'd like to know what it is. As I see it, the implementation has 3 rational choices - it can check the width of the character, and simply refuse to use it (either generating EINVAL or silently ignoring the flag and just using <space>), or it can ignore the issue, and simply use whatever (valid) character is given, inserting N 2-column characters (or 3 or 4, or even 0) where N columns need to be filled, resulting in ugly results, or the implementation can try hard to do what has been requested, when N columns need to be filled, with a fill character that is W columns wide, insert N/W copies of the fill character (or 0 if W==0), and then fill any columns remaining: N if W==0, or N%W (or maybe it is N-N%W - I can't be bothered checking the arithmetic) with spaces. It is very hard to imagine anything different the implementation can do, and if the standard does not specify one of those as the one true way, then that might count as unspecified behaviour (as it will not be specified), but nothing there rises to being undefined behaviour. Note none of this has anything whatever to do with the number of bytes needed to encode the fill character, a one column wide character may be represented (using UTF-8) as anything from 1 to 4 bytes, and implementations are expected to cope with whatever is needed there - if the resulting output exceeds maxsize then an E2BIG will result - that part is straightforward. |
|
|
> Does the committee really believe that the encodings of the characters in values like the mon_thousands_sep (or decimal point, etc) should be GB2312 in that German locale? I don't think that's what that text was suggesting. mon_thousands_sep is not interesting since in de_DE.UTF-8 it's just going to be '.', but suppose we're talking about currency_symbol which will be "\342\202\254" ("€" in UTF-8) which is not a valid byte sequence in GB2312. I don't think the text was saying that "€" could be re-coded in GB2312 by some implementation (the character doesn't exist there anyway), I think the text was saying it is valid for an implementation that internally uses wide characters to fail to decode this byte sequence and return the error to the caller. This would also be useful for the application, as otherwise the application would just be given a series of bytes that do not form valid characters and would result in errors later on. |
|
|
Re 0002000:0007555 - I agree, using the German locales as an example was a poor choice, those are far too mundane to cause issues, a French locale might be better, I believe that a "narrow non-breaking space" is the French generic thousands separator (which unicode code point is the appropriate one, I don't know, our French locale simply uses a normal width non-breaking space, code point 160, or in UTF-8 \302\240 (two bytes). Whatever the intent of the text in question, it wasn't specifying anything useful, as attempting to encode locale data for some locale using some other locale's character encoding is patently absurd. A much bigger locale related issue will address that (which has a very simple solution, unlike other issues with locales) - it doesn't need to be addressed here, just not incorrectly worded. But the substance of your point is a good one, and one I attempted to raise in my first attempt at 0002000:0007553 (the one Mantis wouldn't accept - because of its timeout) and relates to in what encoding the results from functions like strfmon() (but also XSH/printf and many others) are supposed to render their results. I know that our implementation doesn't care what the encoding of the decimal point or thousands separator characters are (or the mon_* versions for strfmon) - it simply copies whatever the locale specifies as that string into the formatted result, with no regard at all what LC_CTYPE might be, and whether or not it specifies the same encoding as LC_NUMERIC or LC_MONETARY. This might turn out to be a huge problem to fix, or it might be simple, and simply result in making things unspecified whenever conflicting encoding types or character sets have been selected via setlocale() (or equivalents). None of that is stfrmon() specific however. |
|
|
ACTION: Mark Brown to edit in place (https://www.austingroupbugs.net/view.php?id=2000#c7531) the actions for the bugnote https://www.austingroupbugs.net/view.php?id=2000#c7554 The committee has chosen not to take the suggested action in 0002000:0007553 as it considers the current proposed wording sufficient. Additional rationale for this change is required. |
|
|
Re 0002000:0007560 The text in question from 0002000:0007531 is [EILSEQ] A string provided in the LC_MONETARY locale was not validly encoded according to the character set specified by the LC_CTYPE category of the application's current locale. That suggests that if the application has successfully done setlocale(LC_ALL, "zh_CN.GB2312"); setlocale(LC_MONETARY, "en_US.UTF-8"); that all of the strings in the LC_MONETARY category of en_US.UTF-8 must be encoded as GB2312 as that is what the LC_CTYPE category of the application's current locale currently is. Forget for a minute that an actual US locale would only be using ASCII strings, which are probably identically encoded in GB2312 as in other locales (I know nothing about GB2312, I just plucked that out of the air) and assume for a minute that my system has a en_US.UTF-8 locale where the mon_deminal_point (for example) was set to a centrally spaced (and perhaps bigger) "dot", rather than the standard "." (full-stop character) that is commonly used these days. In the data returned by localeconv() is the mon_decimal_point string expected to be encoded in UTF-8 (as was chosen for the LC_MONETARY category), or in the GB2312 encoding, whatever that looks like. As written in the proposed text, there should (or could) be an EILSEQ error generated if the strings in the LC_MONETARY data are not GB2312 encoded. Really??? But there would be no EILSEQ if they seem to be UTF-8 encoded, but specify the code point that is one of the UTF-16 high or low surrogate values (invalid UTF-8) because UTF-8 is not the applications LC_CTYPE catehory? (and assuming the values happen to be valid GB2312 encodings). That's the distinction I would like to be made clear - if the strings are actually expected to be in the LC_CTYPE cagegory of the application's locale, then localeconv() needs to transcode the values it reads from the locale data, as there is very unlikely to be anything prepared in advance for a "en_US.GB2312" monetary locale with the strings encoded for that. Are there implementations which actually do that? |
|
|
I have some questions, for which I have no idea what the answers should be, and personally, have no way to discover what the answers should be. Hence this note. While all of these affect strfmon() and arise in conjunction with its specification, implementation, and testing - some (perhaps most) won't affect the XSH/strfmon page of the standard (if they end up affecting anything at all), but the LC_MONETARY section of XBD 7.3.3. But given that as best I can tell, strfmon() is the sole user of the LC_MONETARY locale in the standard, this seems like at least a suitable place to at least find out if there might need to be changes made elsewhere in the standard, before creating a defect report just for that. Before I start, two requests - first in some of what follows I will state that some things are irrelevant. Feel free to disagree if you believe otherwise, and say why, but please do not both disagree and answer the question based upon that disagreement. I am fairly sure I am correct about certain data/values being irrelevant, when I claim they are. If you disagree, it probably means that you are not understanding my question - which probably means my question is not clear enough. Hence, by all means object, so that problem can be fixed, and I can make things more clear, and I can get an answer to the actual question which is bothering me. If you answer based upon a misunderstanding about what I am asking, you will just be muddying the waters, and causing confusion, so please don't do that. Second, I am going to ask you to suspend disbelief in some cases ... there will be a strong temptation to just say "no-one would ever do that", and you'd almost certainly be correct in that view. However, as things are currently specified, all kinds of wild things are possible, and the implementations need to allow for anything that is allowed, and hence might happen - however absurd it would be for an actual use case (locale particularly) to set things up that way. OK, first question: In the locale specification, the international currency symbol ('int_curr_symbol') is defined to be that from ISO4217, that is a three letter defined string (that part of it is simple) and after that is a fourth character, to be used as the space in certain cases. Also clear as it stands. NetBSD's locale definitions actually have a comment which says (words to the effect of) "the fourth character must be a space" but that's clearly nonsense, if it was required to be a <space>, it wouldn't be there at all. What the specification actually says about it is:
That is presuming that a character is going to separate those two items, or is it requiring it? I am presuming that int_[pn]_sep_by_space are intended to apply when 0, which says (for the non-international case):
Or does that only apply if the "fourth character" is <space> and if it is something else, that character is always used? Or is the 4th character intended to replace the <space> when the sep_by_space value says to include one, wherever it is included? The way our implementation has treated that, is that this character is used instead of the space in a case like: USD 100 where if the fourth character of 'in_curr_symbol were 'x' we would see instead of that: USDx100 That usage is clear and quite certainly correct, as it would be as: 100xUSD if the international currency symbol follows the value. Our implementation also uses that character in this case: $x100 that is instead of a "space" between the national currency symbol and the value. That isn't what the spec says to do. It will also appear with negative values as -USDx100 -100xUSD (etc) and the same using the national currency symbol. However we do not use it in this case: USD -100 as in that case, the space is not "separating the international currency symbol from the monetary quantity", that space is separating the international currency symbol from the sign string. and that also means that (despite what is shown above) we can also generate: USD 100 not using the 'x', if there just happens to be an empty sign string immediately to the left of the value, between the value and the space - that it cannot be seen, doesn't mean it isn't there! (The implementation happily inserts the 0 length string at that point, more or less.) There are other cases it isn't used as well, for similar reasons, eg: - 100USD the space there is certainly not between the currency symbol and the value, hence it is a "normal" space, and not the special one. I am however coming to the suspect that much of this is incorrect, or perhaps more precisely, not what was intended, and that the magic space (the 'x' I am using here) should be used in all of these cases. That is, while no-one is going to use an actual 'x' as the space character, it is entirely reasonable to presume that the reason it exists is so that it can be a "thin space" or an "unbreakable space" (or both of those) with the intent being to retain the entire numeric value, including the sign and the currency symbol as one unbreakable "word" in the output. If that is true, then perhaps the intent is that it be used in place of all space characters in the formatted output, from the first significant (non padding) character of the result, to the last. I'd like opinions on this - also information on what other implementations do, and perhaps also input from people who might like to actually use these interfaces (accountants, finance people, ...) as to what they would expect, before there is any effort spent considering making any changes to more precisely specify what should happen here. Next question (unrelated): In the (immediate) following, I am going to assume that all four of the int_p_xxx p_xxx int_n_xxx and n_xxx values for the various LC_MONETARY "xxx" strings, happen to be the same (and of course, no, they are not required to be) - it just means that I can write just "xxx" and you can assume it means whichever of the 4 possibilities happens to be the appropriate one for the value and format in question. The specification for 'sep_by_space', I believe, needs work, but what? First, when sep_by_space is 0,
Is that intended to imply that there is also no space between the currency symbol and the sign string if they are adjacent, or between the sign string and the value if the sign string occurs between the currency symbol and the value? It doesn't say any of that. It says of the value 2 (and similar of 1, the only difference is where the space goes if currency symbol and sign string are not adjacent))
But, what if they are (intended to be) adjacent, but there is no defined sign string? Or no defined currency symbol? Or neither? Is there a space inserted despite those other strings not appearing? If anything can be inferred about the "would appear but happens to be empty" cases, then that is all it is, an inference. Consider if both the currency symbol was absent, and the positive sign string is also absent (which is the case for the POSIX locale for example) and then if sep_by_space happened to be 2 (so not the POSIX locale), do we generate: " 123" (or perhaps "123 " if 'cs_precedes' is 0), or just "123" (in both 'cs_precedes' cases)? Further in these cases, when sign_posn is 0, does the '(' or ')' count as a sign string, so if the output would be, with no spaces, (USD100) and sep_by_space is 2, are we intended to produce ( USD100) and if sep_by_space is 1, are we expected to make (USD 100 ) ? Note that the spec just says "the sign string", not "positive_sign or negative_sign strings" or similar. Wouldn't it also be more complete if there was a way to specify that the currency symbol, sign string, and value, be each separated from whichever of those they appear next to with a space? Also, might it not be useful to have something like:
This needs to be better specified, in XBD 6, though it would also be good to have some comprehensive examples in XSH/strfmon. That is, all possible cases of all the possible parameters considered (with just the two cases each of for the sign and currency symbols, empty or set, what the actual string values are would be irrelevant). Yes, this will add a LARGE example to the page, but I believe it would be worth it, to make things clearer. If it is decided to add such a thing, and if it is made clear what the results should be, in every case, then I can generate the data to fill the spaces (someone else will need to turn that into tables, unless you send me the macro set you use for formatting all of this, and I am able to use that to test things). Next question: Assuming we have a left precision in the format, indicating that the intent is to generate (filled and) aligned values, just how aligned is the result intended to be? I believe we can now (after the current proposed resolution of this issue) say that the formatting of the value part is (will be) clear enough, but what about the surrounding strings? That is, if for example, p_sign_posn = 2 and n_sign_posn = 1, (which is what the spec will say to use if the values in the locale are missing, as for the C/POSIX locale) and positive_sign is "+" and the negative sign is "-" (which is not the C locale, as that has neither, and the strfmon spec only says to use "-" in that case for negative, nothing for positive .. but assuming we have an explicit "+" makes for a simpler first example here). Also, assume "sep_by_space" is 0 (simpler for now). Then if we were to format the two values 100 and -100 with a "%!^#3.0n" format string, the results will be (and this is I believe now clear enough) _100+ -100_ where I am using underscore '_' to represent where a space would appear, to make clear the difference between an actual space in the output, and one that is just for indentation in this note. An alternative way of expressing this might be to make the format string be "<%!^#3.0n>", in which case the output would be < 100+> <-100 > but that is (to me anyway) just adding complexity, so I will continue using '_' when I mean a literal space in the output. Any actual spaces that appear to be present are purely for formatting of this note, and not part of anything else. OK, that part is the part that is clear, but what happens when the positive_sign is missing (an empty string)? In this simple case it is easy enough... _100 -100 still all nicely aligned, nothing needs adding to the right of the value in either case. Next for some more complex examples, which will lead up to the case where I am genuinely unsure what is intended. If we omit the '!' from the format, and assume that the 'currency_symbol' is '$', and 'n_cs_precedes' is 1, and 'p_cs_precedes' is 0, then we get (for the four cases above) __100$+ -$100__ __100$ -$100_ The spaces (underscores here) in each case are needed to cause the values to be aligned properly. Only one space is required in the final example, as the empty positive sign occupies no columns. The two groups aren't required to be aligned with each other, as they are from different locales (the former one with a "+" positive_sign, the latter from one with a "" positive_sign.) These are all simple, and (now) properly specified I believe. But now, let us change our assumptions a little. Make 'cs_precedes' be 0 (all versions), 'sep_by_space' be 1, and have 'sign_posn' be 3, with 'negative_sign' "-" and 'positive_sign' "", then for the value -100 using "%^#3n" we will get: 100_-$ that's clear, but for the positive value "100", do we get: 100_$_ or 100__$ ? This is the "how aligned should the result be" question? The first of those outputs is the "natural" result of the settings, the value precedes the currency symbol and sign, there is a space between the value and the currency symbol, the (empty) sign string precedes the currency symbol. The final space is padding added to ensure that the values are aligned as intended. But in that interpretation, the currency symbols are not aligned. Should they be? (I have no clue.) In the second possible result the currency symbols are aligned, the padding space is inserted where the negative sign would be, to make the sign strings be of equal width. But what justifies strfmon() doing that? The analogous question where sep_by_space is 0 and sign_posn is 3 (both for both positive and negative values) would be, for a negative value using %^#3.0n format string: 100-$ that much is simple enough, and similarly for a positive value, if there is a "+" positive sign, the result would be: 100+$ But in the case where there is no visible positive sign (""), where to retain alignment we need 2 columns after the value, is the expectation for the result: 100$_ or 100_$ ? If there was no left precision, so alignment is not requested, no question but the result would be 100$ that is, with no spaces, which suggests the first of the two when we need 2 columns, but then the currency strings end up unaligned (with each other) when there are both positive and negative values. Which is the expected result? There is currently nothing in the spec which says which way that should be resolved. This was (derived from) an actual case in my tests of the NetBSD strfmon() ... I wrote the test cases, and (manually) generated the expected output, for positive and negative test values, assuming that all that would change in the result would be value and sign, the absent positive sign would be replaced by padding, and the currency symbol would remain in the exact same column (the 2nd output possibility above for positive values). My implementation however did exactly what the spec says to do (as much as it currently states), and generated the first form. That test generated a failure. I don't know which of the two to alter, the expectations from the test, or the code which generates the output. The same issue arises in other cases, all of them can be answered if we supply an answer to the "how aligned" question - if the currency symbols (assuming they are positioned such that it is possible, along with the sign positioning) are intended to be aligned, and not just the values, then one result follows, in this, and other, cases. If it is only the value that matters, we get the other result. Note that this is assuming that we are to be generating a column of output, different values in each row, some positive, some negative, but all intended to line up neatly. That assumption should be made clear, if we can find someone who actually deals with these issues on a day to day basis (ideally several such people, from regions where the positioning of the various symbols in the output differs) they should be aware this is the intended usage. But this gives rise to another issue, strfmon() has only one "switch" which gets used for two different purposes, we might need to separate those, and add a new flag character or something. That is, the left precision does two things, it generates aligned results (with how aligned yet to be determined), and it generates fill characters, to make the value field a specific minimum width, while (optionally) not leaving blank spaces, which would allow someone to alter the number, usually making it much bigger (old style very common printed cheque forgery technique). If only one value is to be produced, so alignment is not of concern (nothing with which to align) but fill characters are desired, then the answer to the "how aligned" question, and where the additional padding should be inserted, might very well be different that it would be when generating what is intended to be an aligned column of numbers. Note that in all of these issues, questions of whether or not there is a decimal point, or what its representation might be, whether or not there is a grouping algorithm for the value, what the thousands separator might be, etc., are irrelevant. Nor is it relevant whether the national or international currency symbols and formats are being used - other than perhaps for the first question way up above (In which cases should the 4th character of the 'int_curr_symbol' be used instead of <space>?), and provided that the appropriate LC_MONETARY parameters are set (by the locale) in the correct fields of the lconv struct for the example, and usage, being questioned. And just for completeness, when I say "NetBSD's implmentation does..." I am actually referring to what it will do, when I commit what I have been working on - the actual released code is based upon what appeared in POSIX Issue 7, and has plenty of problems. The updated code should be in NetBSD HEAD within days now (perhaps even today). |
|
|
Re 0002000:0007562: The below is of course only my interpretation and I cite no authority, but I hope it nonetheless helps. > [EILSEQ] A string provided in the LC_MONETARY locale was not validly encoded according to the character set specified by the LC_CTYPE category of the application's current locale. > > That suggests that if the application has successfully done > > setlocale(LC_ALL, "zh_CN.GB2312"); > setlocale(LC_MONETARY, "en_US.UTF-8"); > > that all of the strings in the LC_MONETARY category of en_US.UTF-8 must be encoded as GB2312 > as that is what the LC_CTYPE category of the application's current locale currently is. Yes, but this is a requirement on the application/user, not on the implementation. In glibc, as you suggest later, all strings in the LC_MONETARY category of en_US.UTF-8 are in US-ASCII, which happens to be the common subset of GB2312 and UTF-8. All the strings in the LC_MONETARY category of en_US.UTF-8 are therefore encoded as GB2312 and there is no issue. The LC_MONETARY category suggests that strfmon("%n", 1.23) (yes that is not the actual C syntax) produces the string "$1.23", and as this is also a valid string in GB2312, the exception does not apply and "$1.23" must be the result. Suppose the example is changed to setlocale(LC_MONETARY, "nl_NL.UTF-8") such that currency_symbol is "\342\202\254" ("€" in UTF-8). This happens to be an invalid byte sequence in GB2312. The LC_MONETARY category suggests that strfmon("%n", 1.23) produces the string "\342\202\254 1,23", but because of this not being a valid string, the behaviour is unspecified: either this invalid string is returned, or the call fails with EILSEQ. No transcoding happens. Suppose the example is changed to setlocale(LC_MONETARY, "en_GB.UTF-8") such that currency_symbol is "\302\243" ("£" in UTF-8). This happens to also be a valid byte sequence in GB2312 for the character "拢". The LC_MONETARY category suggests that strfmon("%n", 1.23) produces the string "\302\2431.23", and as this is also a valid string in GB2312, the exception does not apply and "拢1.23" must be the result, however nonsensical that is. Again, no transcoding happens. These combinations of locale categories with incompatible character sets are application errors, or if they arise from user input, user errors. Re 0002000:0007563: most of it I cannot comment on, but there is one thing worth specifically addressing: > NetBSD's locale definitions actually have a comment which says (words to the effect of) "the fourth character must be a space" but that's clearly nonsense, if it was required to be a <space>, it wouldn't be there at all. That isn't nonsense as long as NetBSD does not have a localedef command. I agree that the spec is unclear about what happens when the fourth character is not a space, but NetBSD can make this a requirement for NetBSD's locales and largely avoid the issue. Such locales would comply with the POSIX requirements. It's also a space in all of glibc's locales that have it defined. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-09-17 19:23 | kre | New Issue | |
| 2026-09-17 19:28 | kre | Note Added: 0007502 | |
| 2026-10-12 16:17 | msbrown | Tag Attached: issue9 | |
| 2026-10-19 19:26 | msbrown | Assigned To | => msbrown |
| 2026-10-19 19:26 | msbrown | Status | New => Interpretation Required |
| 2026-10-19 19:26 | msbrown | Resolution | Open => Accepted As Marked |
| 2026-10-19 19:26 | msbrown | Interp Status | => --- |
| 2026-10-19 19:26 | msbrown | Note Added: 0007531 | |
| 2026-11-04 14:48 | agadmin | Interp Status | --- => Proposed |
| 2026-11-04 14:48 | agadmin | Final Accepted Text | => 0002000:0007531 |
| 2026-11-04 14:48 | agadmin | Note Added: 0007542 | |
| 2026-11-06 21:26 | kre | Note Added: 0007545 | |
| 2026-11-06 21:43 | kre | Note Added: 0007546 | |
| 2026-11-09 01:51 | kre | Note Edited: 0007545 | |
| 2026-11-09 02:02 | kre | Note Added: 0007547 | |
| 2026-11-09 02:48 | kre | Note Added: 0007548 | |
| 2026-11-09 03:33 | kre | Note Added: 0007549 | |
| 2026-11-09 03:36 | kre | Note Edited: 0007549 | |
| 2026-11-09 03:37 | kre | Note Edited: 0007549 | |
| 2026-11-09 15:26 | msbrown | Note Added: 0007550 | |
| 2026-11-09 16:39 | msbrown | Note Added: 0007551 | |
| 2026-11-09 16:43 | msbrown | Note Edited: 0007531 | |
| 2026-11-09 16:49 | msbrown | Note Edited: 0007551 | |
| 2026-11-09 16:49 | msbrown | Note Edited: 0007531 | |
| 2026-11-10 00:57 | kre | Note Added: 0007553 | |
| 2026-11-10 01:23 | kre | Note Added: 0007554 | |
| 2026-11-10 01:25 | hvd | Note Added: 0007555 | |
| 2026-11-10 01:26 | hvd | Note Edited: 0007555 | |
| 2026-11-10 02:30 | kre | Note Added: 0007556 | |
| 2026-11-10 02:35 | kre | Note Edited: 0007556 | |
| 2026-11-16 16:53 | msbrown | Note Added: 0007560 | |
| 2026-11-16 16:55 | msbrown | Note Edited: 0007531 | |
| 2026-11-16 19:12 | kre | Note Added: 0007562 | |
| 2026-11-16 19:27 | kre | Note Added: 0007563 | |
| 2026-11-16 19:28 | kre | Note Edited: 0007563 | |
| 2026-11-17 11:46 | hvd | Note Added: 0007565 |