[KoCo-CVS] [Commit] cjkcodecs/src multibytecodec.c
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-05-19 22:56:38
|
perky 03/05/19 15:56:37 Modified: src multibytecodec.c Log: Fix several copy&paste errors. Revision Changes Path 1.7 +17 -22 cjkcodecs/src/multibytecodec.c Index: multibytecodec.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/multibytecodec.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- multibytecodec.c 19 May 2003 22:37:13 -0000 1.6 +++ multibytecodec.c 19 May 2003 22:56:37 -0000 1.7 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: multibytecodec.c,v 1.6 2003/05/19 22:37:13 perky Exp $ + * $Id: multibytecodec.c,v 1.7 2003/05/19 22:56:37 perky Exp $ */ #include "Python.h" @@ -162,14 +162,14 @@ size_t esize; int retstrsize, newpos, start, end; - if (e == MBERR_TOOSMALL) { - RESERVE_ENCODEBUFFER(buf, -1); - return 0; /* retry it */ - } else if (e > 0) { + if (e > 0) { reason = "illegal multibyte sequence"; esize = e; } else { switch (e) { + case MBERR_TOOSMALL: + RESERVE_ENCODEBUFFER(buf, -1); + return 0; /* retry it */ case MBERR_TOOFEW: reason = "incomplete multibyte sequence"; esize = (size_t)(buf->inbuf_end - buf->inbuf); @@ -291,14 +291,14 @@ size_t esize; int start, end, retunisize, newpos; - if (e == MBERR_TOOSMALL) { - RESERVE_DECODEBUFFER(buf, -1); - return 0; /* retry it */ - } else if (e > 0) { + if (e > 0) { reason = "illegal multibyte sequence"; esize = e; } else { switch (e) { + case MBERR_TOOSMALL: + RESERVE_DECODEBUFFER(buf, -1); + return 0; /* retry it */ case MBERR_TOOFEW: reason = "incomplete multibyte sequence"; esize = (size_t)(buf->inbuf_end - buf->inbuf); @@ -407,22 +407,19 @@ buf.outbuf = (unsigned char *)PyString_AS_STRING(buf.outobj); buf.outbuf_end = buf.outbuf + PyString_GET_SIZE(buf.outobj); - for (;;) { + while (buf.inbuf < buf.inbuf_end) { int r; size_t inleft, outleft; /* we don't reuse inleft and outleft here. * error callbacks can relocate the cursor anywhere on buffer */ inleft = (size_t)(buf.inbuf_end - buf.inbuf); - if (inleft == 0) break; outleft = (size_t)(buf.outbuf_end - buf.outbuf); r = codec->encode(state, &buf.inbuf, inleft, &buf.outbuf, outleft); if (r == 0) break; else if (multibytecodec_encerror(codec, state, &buf, errors, r)) goto errorexit; - else if (buf.inbuf >= buf.inbuf_end) - break; } finalsize = (int)((char*)buf.outbuf - PyString_AS_STRING(buf.outobj)); @@ -483,7 +480,7 @@ MultibyteDecodeBuffer buf; PyObject *errorcb; const char *data, *errors = NULL; - int datalen, finalsize, r; + int datalen, finalsize; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|z:decode", codeckwarglist, &data, &datalen, &errors)) @@ -509,21 +506,19 @@ buf.outbuf_end = buf.outbuf + PyUnicode_GET_SIZE(buf.outobj); state.p = NULL; - for (;;) { + while (buf.inbuf < buf.inbuf_end) { size_t inleft, outleft; int r; - inleft = (size_t)(bufinbuf_end - bufinbuf); - if (inleft == 0) break; - outleft = (size_t)(bufoutbuf_end - bufoutbuf); + inleft = (size_t)(buf.inbuf_end - buf.inbuf); + outleft = (size_t)(buf.outbuf_end - buf.outbuf); - r = codec->decode(&state, &bufinbuf, inleft, &bufoutbuf, outleft); + r = self->codec->decode(&state, &buf.inbuf, inleft, + &buf.outbuf, outleft); if (r == 0) break; - else if (multibytecodec_decerror(codec, &state, &buf, errors, r)) + else if (multibytecodec_decerror(self->codec, &state, &buf, errorcb, r)) goto errorexit; - else if (bufinbuf >= bufinbuf_end) - break; } finalsize = (int)(buf.outbuf - PyUnicode_AS_UNICODE(buf.outobj)); |