Topic: Defect Report: Need error indication from codecvt<>::do_length


Author: Greg Bumgardner <bumgard@roguewave.com>
Date: 26 Jan 01 06:08:23 GMT
Raw View
 [Moderator's note: this defect report has been
 forwarded to the C++ committee. -moderator(fjh).]

Section: 22.2.1.5.1 2 - codecvt virtual functions
[lib.locale.codecvt.virtuals]
Submitter: Gregory Bumgardner (bumgard@roguewave.com)

As indicated in issue 75 of Rev 16 of the issues list, the
codecvt<>::do_length() method must process the source data and update the
stateT argument just as if the data had been processed by codecvt<>::in()
method.  However, the standard does not specify how the do_length() member
would report a translation failure, should the source sequence contain
untranslatable or illegal character sequences.

The other conversion methods return an "error" result value to indicate that
an untranslatable character has been encountered, but do_length() already
has a return value (the number of source characters that have been processed
by the method).

Proposed Resolution:

This issue cannot be resolved without modifying the interface. An exception
cannot be used, as there would be no way to determine how many characters
have been processed and the state object would be left in an indeterminate
state.

A source compatible solution involves adding a fifth argument to length()
and do_length() that could be used to return position of the offending
character sequence. This argument would have a default value that would
allow it to be ignored:

  int length(stateT& state,
             const externT* from,
             const externT* from_end,
             size_t max,
             const externT** from_next = 0);

  virtual
  int do_length(stateT& state,
                const externT* from,
                const externT* from_end,
                size_t max,
                const externT** from_next);

Then an exception could be used to report any translation errors and the
from_next argument , if used, could then be used to retrieve the location of
the offending character sequence.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]