LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sal/textenc - tcvtutf7.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 202 13.4 %
Date: 2013-07-09 Functions: 1 8 12.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "sal/config.h"
      21             : 
      22             : #include "rtl/textcvt.h"
      23             : 
      24             : #include "tenchelp.hxx"
      25             : #include "unichars.hxx"
      26             : 
      27             : /* ======================================================================= */
      28             : 
      29             : static sal_uChar const aImplBase64Tab[64] =
      30             : {
      31             :     /* A-Z */
      32             :           0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
      33             :     0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
      34             :     0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
      35             :     0x58, 0x59, 0x5A,
      36             :     /* a-z */
      37             :           0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
      38             :     0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
      39             :     0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
      40             :     0x78, 0x79, 0x7A,
      41             :     /* 0-9,+,/ */
      42             :     0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
      43             :     0x38, 0x39, 0x2B, 0x2F
      44             : };
      45             : 
      46             : /* Index in Base64Tab or 0xFF, when is a invalid character */
      47             : static sal_uChar const aImplBase64IndexTab[128] =
      48             : {
      49             :     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,     /* 0x00-0x07 */
      50             :     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,     /* 0x08-0x0F */
      51             :     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,     /* 0x10-0x17 */
      52             :     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,     /* 0x18-0x1F */
      53             :     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,     /* 0x20-0x27  !"#$%&' */
      54             :     0xFF, 0xFF, 0xFF,   62, 0xFF, 0xFF, 0xFF,   63,     /* 0x28-0x2F ()*+,-./ */
      55             :       52,   53,   54,   55,   56,   57,   58,   59,     /* 0x30-0x37 01234567 */
      56             :       60,   61, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,     /* 0x38-0x3F 89:;<=>? */
      57             :     0xFF,    0,    1,    2,    3,    4,    5,    6,     /* 0x40-0x47 @ABCDEFG */
      58             :        7,    8,    9,   10,   11,   12,   13,   14,     /* 0x48-0x4F HIJKLMNO */
      59             :       15,   16,   17,   18,   19,   20,   21,   22,     /* 0x50-0x57 PQRSTUVW */
      60             :       23,   24,   25, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,     /* 0x58-0x5F XYZ[\]^_ */
      61             :     0xFF,   26,   27,   28,   29,   30,   31,   32,     /* 0x60-0x67 `abcdefg */
      62             :       33,   34,   35,   36,   37,   38,   39,   40,     /* 0x68-0x6F hijklmno */
      63             :       41,   42,   43,   44,   45,   46,   47,   48,     /* 0x70-0x77 pqrstuvw */
      64             :       49,   50,   51, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF      /* 0x78-0x7F xyz{|}~ */
      65             : };
      66             : 
      67             : static sal_uChar const aImplMustShiftTab[128] =
      68             : {
      69             :     1, 1, 1, 1, 1, 1, 1, 1,     /* 0x00-0x07 */
      70             :     1, 0, 0, 1, 0, 1, 1, 1,     /* 0x08-0x0F 0x09 == HTAB, 0x0A == LF 0x0C == CR */
      71             :     1, 1, 1, 1, 1, 1, 1, 1,     /* 0x10-0x17 */
      72             :     1, 1, 1, 1, 1, 1, 1, 1,     /* 0x18-0x1F */
      73             :     0, 1, 1, 1, 1, 1, 1, 0,     /* 0x20-0x27  !"#$%&' */
      74             :     0, 0, 1, 1, 0, 1, 0, 0,     /* 0x28-0x2F ()*+,-./ */
      75             :     0, 0, 0, 0, 0, 0, 0, 0,     /* 0x30-0x37 01234567 */
      76             :     0, 0, 0, 1, 1, 1, 1, 0,     /* 0x38-0x3F 89:;<=>? */
      77             :     1, 0, 0, 0, 0, 0, 0, 0,     /* 0x40-0x47 @ABCDEFG */
      78             :     0, 0, 0, 0, 0, 0, 0, 0,     /* 0x48-0x4F HIJKLMNO */
      79             :     0, 0, 0, 0, 0, 0, 0, 0,     /* 0x50-0x57 PQRSTUVW */
      80             :     0, 0, 0, 1, 1, 1, 1, 1,     /* 0x58-0x5F XYZ[\]^_ */
      81             :     1, 0, 0, 0, 0, 0, 0, 0,     /* 0x60-0x67 `abcdefg */
      82             :     0, 0, 0, 0, 0, 0, 0, 0,     /* 0x68-0x6F hijklmno */
      83             :     0, 0, 0, 0, 0, 0, 0, 0,     /* 0x70-0x77 pqrstuvw */
      84             :     0, 0, 0, 1, 1, 1, 1, 1      /* 0x78-0x7F xyz{|}~ */
      85             : };
      86             : 
      87             : /* + */
      88             : #define IMPL_SHIFT_IN_CHAR      0x2B
      89             : /* - */
      90             : #define IMPL_SHIFT_OUT_CHAR     0x2D
      91             : 
      92             : /* ----------------------------------------------------------------------- */
      93             : 
      94             : struct ImplUTF7ToUCContextData
      95             : {
      96             :     int                     mbShifted;
      97             :     int                     mbFirst;
      98             :     int                     mbWroteOne;
      99             :     sal_uInt32              mnBitBuffer;
     100             :     sal_uInt32              mnBufferBits;
     101             : };
     102             : 
     103             : /* ----------------------------------------------------------------------- */
     104             : 
     105           0 : void* ImplUTF7CreateUTF7TextToUnicodeContext()
     106             : {
     107           0 :     ImplUTF7ToUCContextData* pContextData = new ImplUTF7ToUCContextData;
     108           0 :     pContextData->mbShifted         = sal_False;
     109           0 :     pContextData->mbFirst           = sal_False;
     110           0 :     pContextData->mbWroteOne        = sal_False;
     111           0 :     pContextData->mnBitBuffer       = 0;
     112           0 :     pContextData->mnBufferBits      = 0;
     113           0 :     return pContextData;
     114             : }
     115             : 
     116             : /* ----------------------------------------------------------------------- */
     117             : 
     118           0 : void ImplUTF7DestroyTextToUnicodeContext( void* pContext )
     119             : {
     120           0 :     delete static_cast< ImplUTF7ToUCContextData * >(pContext);
     121           0 : }
     122             : 
     123             : /* ----------------------------------------------------------------------- */
     124             : 
     125           0 : void ImplUTF7ResetTextToUnicodeContext( void* pContext )
     126             : {
     127           0 :     ImplUTF7ToUCContextData* pContextData = (ImplUTF7ToUCContextData*)pContext;
     128           0 :     pContextData->mbShifted         = sal_False;
     129           0 :     pContextData->mbFirst           = sal_False;
     130           0 :     pContextData->mbWroteOne        = sal_False;
     131           0 :     pContextData->mnBitBuffer       = 0;
     132           0 :     pContextData->mnBufferBits      = 0;
     133           0 : }
     134             : 
     135             : /* ----------------------------------------------------------------------- */
     136             : 
     137           0 : sal_Size ImplUTF7ToUnicode( SAL_UNUSED_PARAMETER const void*, void* pContext,
     138             :                             const char* pSrcBuf, sal_Size nSrcBytes,
     139             :                             sal_Unicode* pDestBuf, sal_Size nDestChars,
     140             :                             sal_uInt32 nFlags, sal_uInt32* pInfo,
     141             :                             sal_Size* pSrcCvtBytes )
     142             : {
     143           0 :     ImplUTF7ToUCContextData*    pContextData = (ImplUTF7ToUCContextData*)pContext;
     144           0 :     sal_uChar                   c ='\0';
     145           0 :     sal_uChar                   nBase64Value = 0;
     146           0 :     int                         bEnd = sal_False;
     147             :     int                         bShifted;
     148             :     int                         bFirst;
     149             :     int                         bWroteOne;
     150             :     int                         bBase64End;
     151             :     sal_uInt32                  nBitBuffer;
     152             :     sal_uInt32                  nBitBufferTemp;
     153             :     sal_uInt32                  nBufferBits;
     154             :     sal_Unicode*                pEndDestBuf;
     155             :     const char*             pEndSrcBuf;
     156             : 
     157             : /* !!! Implementation not finnished !!!
     158             :     if ( pContextData )
     159             :     {
     160             :         bShifted        = pContextData->mbShifted;
     161             :         bFirst          = pContextData->mbFirst;
     162             :         bWroteOne       = pContextData->mbWroteOne;
     163             :         nBitBuffer      = pContextData->mnBitBuffer;
     164             :         nBufferBits     = pContextData->mnBufferBits;
     165             :     }
     166             :     else
     167             : */
     168             :     {
     169           0 :         bShifted        = sal_False;
     170           0 :         bFirst          = sal_False;
     171           0 :         bWroteOne       = sal_False;
     172           0 :         nBitBuffer      = 0;
     173           0 :         nBufferBits     = 0;
     174             :     }
     175             : 
     176           0 :     *pInfo = 0;
     177           0 :     pEndDestBuf = pDestBuf+nDestChars;
     178           0 :     pEndSrcBuf  = pSrcBuf+nSrcBytes;
     179           0 :     do
     180             :     {
     181           0 :         if ( pSrcBuf < pEndSrcBuf )
     182             :         {
     183           0 :             c = (sal_uChar)*pSrcBuf;
     184             : 
     185             :             /* End, when not a base64 character */
     186           0 :             bBase64End = sal_False;
     187           0 :             if ( c <= 0x7F )
     188             :             {
     189           0 :                 nBase64Value = aImplBase64IndexTab[c];
     190           0 :                 if ( nBase64Value == 0xFF )
     191           0 :                     bBase64End = sal_True;
     192             :             }
     193             :         }
     194             :         else
     195             :         {
     196           0 :             bEnd = sal_True;
     197           0 :             bBase64End = sal_True;
     198             :         }
     199             : 
     200           0 :         if ( bShifted )
     201             :         {
     202           0 :             if ( bBase64End )
     203             :             {
     204           0 :                 bShifted = sal_False;
     205             : 
     206             :                 /* If the character causing us to drop out was SHIFT_IN */
     207             :                 /* or SHIFT_OUT, it may be a special escape for SHIFT_IN. */
     208             :                 /* The test for SHIFT_IN is not necessary, but allows */
     209             :                 /* an alternate form of UTF-7 where SHIFT_IN is escaped */
     210             :                 /* by SHIFT_IN. This only works for some values of */
     211             :                 /* SHIFT_IN. It is so implemented, because this comes */
     212             :                 /* from the officel unicode book (The Unicode Standard, */
     213             :                 /* Version 2.0) and so I think, that someone of the */
     214             :                 /* world has used this feature. */
     215           0 :                 if ( !bEnd )
     216             :                 {
     217           0 :                     if ( (c == IMPL_SHIFT_IN_CHAR) || (c == IMPL_SHIFT_OUT_CHAR) )
     218             :                     {
     219             :                         /* If no base64 character, and the terminating */
     220             :                         /* character of the shift sequence was the */
     221             :                         /* SHIFT_OUT_CHAR, then it't a special escape */
     222             :                         /* for SHIFT_IN_CHAR. */
     223           0 :                         if ( bFirst && (c == IMPL_SHIFT_OUT_CHAR) )
     224             :                         {
     225           0 :                             if ( pDestBuf >= pEndDestBuf )
     226             :                             {
     227           0 :                                 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
     228           0 :                                 break;
     229             :                             }
     230           0 :                             *pDestBuf = IMPL_SHIFT_IN_CHAR;
     231           0 :                             pDestBuf++;
     232           0 :                             bWroteOne = sal_True;
     233             :                         }
     234             : 
     235             :                         /* Skip character */
     236           0 :                         pSrcBuf++;
     237           0 :                         if ( pSrcBuf < pEndSrcBuf )
     238           0 :                             c = (sal_uChar)*pSrcBuf;
     239             :                         else
     240           0 :                             bEnd = sal_True;
     241             :                     }
     242             :                 }
     243             : 
     244             :                 /* Empty sequence not allowed, so when we don't write one */
     245             :                 /* valid char, then the sequence is corrupt */
     246           0 :                 if ( !bWroteOne )
     247             :                 {
     248             :                     /* When no more bytes in the source buffer, then */
     249             :                     /* this buffer may be to small */
     250           0 :                     if ( bEnd )
     251           0 :                         *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL;
     252             :                     else
     253             :                     {
     254           0 :                         *pInfo |= RTL_TEXTTOUNICODE_INFO_INVALID;
     255           0 :                         if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR )
     256             :                         {
     257           0 :                             *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
     258           0 :                             break;
     259             :                         }
     260             :                         /* We insert here no default char, because I think */
     261             :                         /* this is better to ignore this */
     262             :                     }
     263             :                 }
     264             :             }
     265             :             else
     266             :             {
     267             :                 /* Add 6 Bits from character to the bit buffer */
     268           0 :                 nBufferBits += 6;
     269           0 :                 nBitBuffer |= ((sal_uInt32)(nBase64Value & 0x3F)) << (32-nBufferBits);
     270           0 :                 bFirst = sal_False;
     271             :             }
     272             : 
     273             :             /* Extract as many full 16 bit characters as possible from the */
     274             :             /* bit buffer. */
     275           0 :             while ( (pDestBuf < pEndDestBuf) && (nBufferBits >= 16) )
     276             :             {
     277           0 :                 nBitBufferTemp = nBitBuffer >> (32-16);
     278           0 :                 *pDestBuf = (sal_Unicode)((nBitBufferTemp) & 0xFFFF);
     279           0 :                 pDestBuf++;
     280           0 :                 nBitBuffer <<= 16;
     281           0 :                 nBufferBits -= 16;
     282           0 :                 bWroteOne = sal_True;
     283             :             }
     284             : 
     285           0 :             if ( nBufferBits >= 16 )
     286             :             {
     287           0 :                 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
     288           0 :                 break;
     289             :             }
     290             : 
     291           0 :             if ( bBase64End )
     292             :             {
     293             :                 /* Sequence ended and we have some bits, then the */
     294             :                 /* sequence is corrupted */
     295           0 :                 if ( nBufferBits && nBitBuffer )
     296             :                 {
     297             :                     /* When no more bytes in the source buffer, then */
     298             :                     /* this buffer may be to small */
     299           0 :                     if ( bEnd )
     300           0 :                         *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL;
     301             :                     else
     302             :                     {
     303           0 :                         *pInfo |= RTL_TEXTTOUNICODE_INFO_INVALID;
     304           0 :                         if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR )
     305             :                         {
     306           0 :                             *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
     307           0 :                             break;
     308             :                         }
     309           0 :                         else if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) != RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE )
     310             :                         {
     311           0 :                             if ( pDestBuf >= pEndDestBuf )
     312             :                             {
     313           0 :                                 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
     314           0 :                                 break;
     315             :                             }
     316             :                             *pDestBuf++
     317           0 :                                 = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
     318             :                         }
     319             :                     }
     320             : 
     321             :                 }
     322             : 
     323           0 :                 nBitBuffer = 0;
     324           0 :                 nBufferBits = 0;
     325             :             }
     326             :         }
     327             : 
     328           0 :         if ( !bEnd )
     329             :         {
     330           0 :             if ( !bShifted )
     331             :             {
     332           0 :                 if ( c == IMPL_SHIFT_IN_CHAR )
     333             :                 {
     334           0 :                     bShifted    = sal_True;
     335           0 :                     bFirst      = sal_True;
     336           0 :                     bWroteOne   = sal_False;
     337             :                 }
     338             :                 else
     339             :                 {
     340             :                     /* No direct encoded charcater, then the buffer is */
     341             :                     /* corrupt */
     342           0 :                     if ( c > 0x7F )
     343             :                     {
     344           0 :                         *pInfo |= RTL_TEXTTOUNICODE_INFO_INVALID;
     345           0 :                         if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR )
     346             :                         {
     347           0 :                             *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
     348           0 :                             break;
     349             :                         }
     350           0 :                         else if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) != RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE )
     351             :                         {
     352           0 :                             if ( pDestBuf >= pEndDestBuf )
     353             :                             {
     354           0 :                                 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
     355           0 :                                 break;
     356             :                             }
     357             :                             *pDestBuf++
     358           0 :                                 = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
     359             :                         }
     360             :                     }
     361             : 
     362             :                     /* Write char to unicode buffer */
     363           0 :                     if ( pDestBuf >= pEndDestBuf )
     364             :                     {
     365           0 :                         *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
     366           0 :                         break;
     367             :                     }
     368           0 :                     *pDestBuf = c;
     369           0 :                     pDestBuf++;
     370             :                 }
     371             :             }
     372             : 
     373           0 :             pSrcBuf++;
     374             :         }
     375             :     }
     376             :     while ( !bEnd );
     377             : 
     378           0 :     if ( pContextData )
     379             :     {
     380           0 :         pContextData->mbShifted         = bShifted;
     381           0 :         pContextData->mbFirst           = bFirst;
     382           0 :         pContextData->mbWroteOne        = bWroteOne;
     383           0 :         pContextData->mnBitBuffer       = nBitBuffer;
     384           0 :         pContextData->mnBufferBits      = nBufferBits;
     385             :     }
     386             : 
     387           0 :     *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
     388           0 :     return (nDestChars - (pEndDestBuf-pDestBuf));
     389             : }
     390             : 
     391             : /* ======================================================================= */
     392             : 
     393             : struct ImplUTF7FromUCContextData
     394             : {
     395             :     int                     mbShifted;
     396             :     sal_uInt32              mnBitBuffer;
     397             :     sal_uInt32              mnBufferBits;
     398             : };
     399             : 
     400             : /* ----------------------------------------------------------------------- */
     401             : 
     402           0 : void* ImplUTF7CreateUnicodeToTextContext()
     403             : {
     404           0 :     ImplUTF7FromUCContextData* pContextData = new ImplUTF7FromUCContextData;
     405           0 :     pContextData->mbShifted         = sal_False;
     406           0 :     pContextData->mnBitBuffer       = 0;
     407           0 :     pContextData->mnBufferBits      = 0;
     408           0 :     return pContextData;
     409             : }
     410             : 
     411             : /* ----------------------------------------------------------------------- */
     412             : 
     413           0 : void ImplUTF7DestroyUnicodeToTextContext( void* pContext )
     414             : {
     415           0 :     delete static_cast< ImplUTF7FromUCContextData * >(pContext);
     416           0 : }
     417             : 
     418             : /* ----------------------------------------------------------------------- */
     419             : 
     420           0 : void ImplUTF7ResetUnicodeToTextContext( void* pContext )
     421             : {
     422           0 :     ImplUTF7FromUCContextData* pContextData = (ImplUTF7FromUCContextData*)pContext;
     423           0 :     pContextData->mbShifted         = sal_False;
     424           0 :     pContextData->mnBitBuffer       = 0;
     425           0 :     pContextData->mnBufferBits      = 0;
     426           0 : }
     427             : 
     428             : /* ----------------------------------------------------------------------- */
     429             : 
     430          15 : sal_Size ImplUnicodeToUTF7( SAL_UNUSED_PARAMETER const void*, void* pContext,
     431             :                             const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
     432             :                             char* pDestBuf, sal_Size nDestBytes,
     433             :                             SAL_UNUSED_PARAMETER sal_uInt32, sal_uInt32* pInfo,
     434             :                             sal_Size* pSrcCvtChars )
     435             : {
     436          15 :     ImplUTF7FromUCContextData*  pContextData = (ImplUTF7FromUCContextData*)pContext;
     437          15 :     sal_Unicode                 c = '\0';
     438          15 :     int                         bEnd = sal_False;
     439             :     int                         bShifted;
     440             :     int                         bNeedShift;
     441             :     sal_uInt32                  nBitBuffer;
     442             :     sal_uInt32                  nBitBufferTemp;
     443             :     sal_uInt32                  nBufferBits;
     444             :     char*                   pEndDestBuf;
     445             :     const sal_Unicode*          pEndSrcBuf;
     446             : 
     447             : /* !!! Implementation not finnished !!!
     448             :     if ( pContextData )
     449             :     {
     450             :         bShifted        = pContextData->mbShifted;
     451             :         nBitBuffer      = pContextData->mnBitBuffer;
     452             :         nBufferBits     = pContextData->mnBufferBits;
     453             :     }
     454             :     else
     455             : */
     456             :     {
     457          15 :         bShifted        = sal_False;
     458          15 :         nBitBuffer      = 0;
     459          15 :         nBufferBits     = 0;
     460             :     }
     461             : 
     462          15 :     *pInfo = 0;
     463          15 :     pEndDestBuf = pDestBuf+nDestBytes;
     464          15 :     pEndSrcBuf  = pSrcBuf+nSrcChars;
     465         233 :     do
     466             :     {
     467         233 :         if ( pSrcBuf < pEndSrcBuf )
     468             :         {
     469         218 :             c = *pSrcBuf;
     470             : 
     471         218 :             bNeedShift = (c > 0x7F) || aImplMustShiftTab[c];
     472         218 :             if ( bNeedShift && !bShifted )
     473             :             {
     474           0 :                 if ( pDestBuf >= pEndDestBuf )
     475             :                 {
     476           0 :                     *pInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
     477           0 :                     break;
     478             :                 }
     479           0 :                 *pDestBuf = IMPL_SHIFT_IN_CHAR;
     480           0 :                 pDestBuf++;
     481             :                 /* Special case handling for SHIFT_IN_CHAR */
     482           0 :                 if ( c == IMPL_SHIFT_IN_CHAR )
     483             :                 {
     484           0 :                     if ( pDestBuf >= pEndDestBuf )
     485             :                     {
     486           0 :                         *pInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
     487           0 :                         break;
     488             :                     }
     489           0 :                     *pDestBuf = IMPL_SHIFT_OUT_CHAR;
     490           0 :                     pDestBuf++;
     491             :                 }
     492             :                 else
     493           0 :                     bShifted = sal_True;
     494             :             }
     495             :         }
     496             :         else
     497             :         {
     498          15 :             bEnd = sal_True;
     499          15 :             bNeedShift = sal_False;
     500             :         }
     501             : 
     502         233 :         if ( bShifted )
     503             :         {
     504             :             /* Write the character to the bit buffer, or pad the bit */
     505             :             /* buffer out to a full base64 character */
     506           0 :             if ( bNeedShift )
     507             :             {
     508           0 :                 nBufferBits += 16;
     509           0 :                 nBitBuffer |= ((sal_uInt32)c) << (32-nBufferBits);
     510             :             }
     511             :             else
     512           0 :                 nBufferBits += (6-(nBufferBits%6))%6;
     513             : 
     514             :             /* Flush out as many full base64 characters as possible */
     515           0 :             while ( (pDestBuf < pEndDestBuf) && (nBufferBits >= 6) )
     516             :             {
     517           0 :                 nBitBufferTemp = nBitBuffer >> (32-6);
     518           0 :                 *pDestBuf = aImplBase64Tab[nBitBufferTemp];
     519           0 :                 pDestBuf++;
     520           0 :                 nBitBuffer <<= 6;
     521           0 :                 nBufferBits -= 6;
     522             :             }
     523             : 
     524           0 :             if ( nBufferBits >= 6 )
     525             :             {
     526           0 :                 *pInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
     527           0 :                 break;
     528             :             }
     529             : 
     530             :             /* Write SHIFT_OUT_CHAR, when needed */
     531           0 :             if ( !bNeedShift )
     532             :             {
     533           0 :                 if ( pDestBuf >= pEndDestBuf )
     534             :                 {
     535           0 :                     *pInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
     536           0 :                     break;
     537             :                 }
     538           0 :                 *pDestBuf = IMPL_SHIFT_OUT_CHAR;
     539           0 :                 pDestBuf++;
     540           0 :                 bShifted = sal_False;
     541             :             }
     542             :         }
     543             : 
     544         233 :         if ( !bEnd )
     545             :         {
     546             :             /* Character can be directly endcoded */
     547         218 :             if ( !bNeedShift )
     548             :             {
     549         218 :                 if ( pDestBuf >= pEndDestBuf )
     550             :                 {
     551           0 :                     *pInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
     552           0 :                     break;
     553             :                 }
     554         218 :                 *pDestBuf = static_cast< char >(static_cast< unsigned char >(c));
     555         218 :                 pDestBuf++;
     556             :             }
     557             : 
     558         218 :             pSrcBuf++;
     559             :         }
     560             :     }
     561             :     while ( !bEnd );
     562             : 
     563          15 :     if ( pContextData )
     564             :     {
     565           0 :         pContextData->mbShifted     = bShifted;
     566           0 :         pContextData->mnBitBuffer   = nBitBuffer;
     567           0 :         pContextData->mnBufferBits  = nBufferBits;
     568             :     }
     569             : 
     570          15 :     *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
     571          15 :     return (nDestBytes - (pEndDestBuf-pDestBuf));
     572             : }
     573             : 
     574             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10