You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2005/04/29 01:43:21 UTC

cvs commit: logging-log4cxx/src charsetdecoder.cpp

carnold     2005/04/28 16:43:21

  Modified:    src      charsetdecoder.cpp
  Log:
  LOGCXX-59: Decoding switching to mbsRtowcs
  
  Revision  Changes    Path
  1.5       +15 -11    logging-log4cxx/src/charsetdecoder.cpp
  
  Index: charsetdecoder.cpp
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/src/charsetdecoder.cpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- charsetdecoder.cpp	28 Apr 2005 23:26:33 -0000	1.4
  +++ charsetdecoder.cpp	28 Apr 2005 23:43:21 -0000	1.5
  @@ -155,23 +155,27 @@
                     enum { BUFSIZE = 256 };
                     wchar_t buf[BUFSIZE];
   
  +                  mbstate_t mbstate;
  +
                     while(in.remaining() > 0) {
                         size_t requested = in.remaining();
                         if (requested > BUFSIZE - 1) {
                             requested = BUFSIZE - 1;
                         }
   
  -                      for(; requested > 0; requested--) {
  -                        memset(buf, 0, BUFSIZE*sizeof(wchar_t));
  -                        size_t converted = mbstowcs(buf, in.data() + in.position(), requested);
  -                        if (converted != (size_t) -1) {
  -                            stat = append(out, buf);
  -                            in.position(in.position() + converted);
  -                            break;
  -                        }
  -                      }
  -                      if (requested == 0) {
  -                          return APR_BADARG;
  +                      memset(buf, 0, BUFSIZE*sizeof(wchar_t));
  +                      const char* src = in.current();
  +                      size_t converted = mbsrtowcs(buf,
  +                           &src,
  +                           requested,
  +                           &mbstate);
  +                      if (converted == (size_t) -1) {
  +                          stat = APR_BADARG;
  +                          in.position(src - in.data());
  +                          break;
  +                      } else {
  +                         stat = append(out, buf);
  +                         in.position(in.position() + converted);
                         }
                     }
                     return stat;