/*
**********************************************************************
-* Copyright (C) 2002-2010, International Business Machines
+* Copyright (C) 2002-2011, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: ucnv_u7.c
#include "unicode/ucnv.h"
#include "ucnv_bld.h"
#include "ucnv_cnv.h"
+#include "uassert.h"
/* UTF-7 -------------------------------------------------------------------- */
break;
} else {
/* previous UChar was complete */
- if (base64Value==-3) {
+ if(base64Value==-3) {
/* current character is illegal, deal with it here */
*pErrorCode=U_ILLEGAL_CHAR_FOUND;
break;
inDirectMode=(UBool)((status>>24)&1);
base64Counter=(int8_t)(status>>16);
bits=(uint8_t)status;
+ U_ASSERT(bits<=sizeof(toBase64)/sizeof(toBase64[0]));
}
/* UTF-7 always encodes UTF-16 code units, therefore we need only a simple sourceIndex */
if(pArgs->flush && source>=sourceLimit) {
/* flush remaining bits to the target */
- if(!inDirectMode && base64Counter!=0) {
+ if(!inDirectMode) {
+ if (base64Counter!=0) {
+ if(target<targetLimit) {
+ *target++=toBase64[bits];
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex-1;
+ }
+ } else {
+ cnv->charErrorBuffer[cnv->charErrorBufferLength++]=toBase64[bits];
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+ /* Add final MINUS to terminate unicodeMode */
if(target<targetLimit) {
- *target++=toBase64[bits];
+ *target++=MINUS;
if(offsets!=NULL) {
*offsets++=sourceIndex-1;
}
} else {
- cnv->charErrorBuffer[cnv->charErrorBufferLength++]=toBase64[bits];
+ cnv->charErrorBuffer[cnv->charErrorBufferLength++]=MINUS;
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
}
}