LCOV - code coverage report
Current view: top level - libreoffice/workdir/unxlngi6.pro/UnpackedTarball/cdr/src/lib - libcdr_utils.cpp (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 156 0.0 %
Date: 2012-12-17 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* libcdr
       3             :  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
      17             :  *
      18             :  *
      19             :  * All Rights Reserved.
      20             :  *
      21             :  * For minor contributions see the git repository.
      22             :  *
      23             :  * Alternatively, the contents of this file may be used under the terms of
      24             :  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
      25             :  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
      26             :  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
      27             :  * instead of those above.
      28             :  */
      29             : 
      30             : #include "libcdr_utils.h"
      31             : 
      32             : #define CDR_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
      33             : 
      34             : #define SURROGATE_VALUE(h,l) (((h) - 0xd800) * 0x400 + (l) - 0xdc00 + 0x10000)
      35             : 
      36             : namespace
      37             : {
      38             : 
      39           0 : static void _appendUCS4(WPXString &text, unsigned ucs4Character)
      40             : {
      41             :   unsigned char first;
      42             :   int len;
      43           0 :   if (ucs4Character < 0x80)
      44             :   {
      45           0 :     first = 0;
      46           0 :     len = 1;
      47             :   }
      48           0 :   else if (ucs4Character < 0x800)
      49             :   {
      50           0 :     first = 0xc0;
      51           0 :     len = 2;
      52             :   }
      53           0 :   else if (ucs4Character < 0x10000)
      54             :   {
      55           0 :     first = 0xe0;
      56           0 :     len = 3;
      57             :   }
      58           0 :   else if (ucs4Character < 0x200000)
      59             :   {
      60           0 :     first = 0xf0;
      61           0 :     len = 4;
      62             :   }
      63           0 :   else if (ucs4Character < 0x4000000)
      64             :   {
      65           0 :     first = 0xf8;
      66           0 :     len = 5;
      67             :   }
      68             :   else
      69             :   {
      70           0 :     first = 0xfc;
      71           0 :     len = 6;
      72             :   }
      73             : 
      74           0 :   unsigned char outbuf[6] = { 0, 0, 0, 0, 0, 0 };
      75             :   int i;
      76           0 :   for (i = len - 1; i > 0; --i)
      77             :   {
      78           0 :     outbuf[i] = (ucs4Character & 0x3f) | 0x80;
      79           0 :     ucs4Character >>= 6;
      80             :   }
      81           0 :   outbuf[0] = (ucs4Character & 0xff) | first;
      82             : 
      83           0 :   for (i = 0; i < len; i++)
      84           0 :     text.append(outbuf[i]);
      85           0 : }
      86             : 
      87             : } // anonymous namespace
      88             : 
      89           0 : uint8_t libcdr::readU8(WPXInputStream *input, bool /* bigEndian */)
      90             : {
      91           0 :   if (!input || input->atEOS())
      92             :   {
      93             :     CDR_DEBUG_MSG(("Throwing EndOfStreamException\n"));
      94           0 :     throw EndOfStreamException();
      95             :   }
      96             :   unsigned long numBytesRead;
      97           0 :   uint8_t const *p = input->read(sizeof(uint8_t), numBytesRead);
      98             : 
      99           0 :   if (p && numBytesRead == sizeof(uint8_t))
     100           0 :     return *(uint8_t const *)(p);
     101             :   CDR_DEBUG_MSG(("Throwing EndOfStreamException\n"));
     102           0 :   throw EndOfStreamException();
     103             : }
     104             : 
     105           0 : uint16_t libcdr::readU16(WPXInputStream *input, bool bigEndian)
     106             : {
     107           0 :   if (!input || input->atEOS())
     108             :   {
     109             :     CDR_DEBUG_MSG(("Throwing EndOfStreamException\n"));
     110           0 :     throw EndOfStreamException();
     111             :   }
     112             :   unsigned long numBytesRead;
     113           0 :   uint8_t const *p = input->read(sizeof(uint16_t), numBytesRead);
     114             : 
     115           0 :   if (p && numBytesRead == sizeof(uint16_t))
     116             :   {
     117           0 :     if (bigEndian)
     118           0 :       return (uint16_t)p[1]|((uint16_t)p[0]<<8);
     119           0 :     return (uint16_t)p[0]|((uint16_t)p[1]<<8);
     120             :   }
     121             :   CDR_DEBUG_MSG(("Throwing EndOfStreamException\n"));
     122           0 :   throw EndOfStreamException();
     123             : }
     124             : 
     125           0 : int16_t libcdr::readS16(WPXInputStream *input, bool bigEndian)
     126             : {
     127           0 :   return (int16_t)readU16(input, bigEndian);
     128             : }
     129             : 
     130           0 : uint32_t libcdr::readU32(WPXInputStream *input, bool bigEndian)
     131             : {
     132           0 :   if (!input || input->atEOS())
     133             :   {
     134             :     CDR_DEBUG_MSG(("Throwing EndOfStreamException\n"));
     135           0 :     throw EndOfStreamException();
     136             :   }
     137             :   unsigned long numBytesRead;
     138           0 :   uint8_t const *p = input->read(sizeof(uint32_t), numBytesRead);
     139             : 
     140           0 :   if (p && numBytesRead == sizeof(uint32_t))
     141             :   {
     142           0 :     if (bigEndian)
     143           0 :       return (uint32_t)p[3]|((uint32_t)p[2]<<8)|((uint32_t)p[1]<<16)|((uint32_t)p[0]<<24);
     144           0 :     return (uint32_t)p[0]|((uint32_t)p[1]<<8)|((uint32_t)p[2]<<16)|((uint32_t)p[3]<<24);
     145             :   }
     146             :   CDR_DEBUG_MSG(("Throwing EndOfStreamException\n"));
     147           0 :   throw EndOfStreamException();
     148             : }
     149             : 
     150           0 : int32_t libcdr::readS32(WPXInputStream *input, bool bigEndian)
     151             : {
     152           0 :   return (int32_t)readU32(input, bigEndian);
     153             : }
     154             : 
     155           0 : uint64_t libcdr::readU64(WPXInputStream *input, bool bigEndian)
     156             : {
     157           0 :   if (!input || input->atEOS())
     158             :   {
     159             :     CDR_DEBUG_MSG(("Throwing EndOfStreamException\n"));
     160           0 :     throw EndOfStreamException();
     161             :   }
     162             :   unsigned long numBytesRead;
     163           0 :   uint8_t const *p = input->read(sizeof(uint64_t), numBytesRead);
     164             : 
     165           0 :   if (p && numBytesRead == sizeof(uint64_t))
     166             :   {
     167           0 :     if (bigEndian)
     168           0 :       return (uint64_t)p[7]|((uint64_t)p[6]<<8)|((uint64_t)p[5]<<16)|((uint64_t)p[4]<<24)|((uint64_t)p[3]<<32)|((uint64_t)p[2]<<40)|((uint64_t)p[1]<<48)|((uint64_t)p[0]<<56);
     169           0 :     return (uint64_t)p[0]|((uint64_t)p[1]<<8)|((uint64_t)p[2]<<16)|((uint64_t)p[3]<<24)|((uint64_t)p[4]<<32)|((uint64_t)p[5]<<40)|((uint64_t)p[6]<<48)|((uint64_t)p[7]<<56);
     170             :   }
     171             :   CDR_DEBUG_MSG(("Throwing EndOfStreamException\n"));
     172           0 :   throw EndOfStreamException();
     173             : }
     174             : 
     175           0 : double libcdr::readDouble(WPXInputStream *input, bool bigEndian)
     176             : {
     177             :   union
     178             :   {
     179             :     uint64_t u;
     180             :     double d;
     181             :   } tmpUnion;
     182             : 
     183           0 :   tmpUnion.u = readU64(input, bigEndian);
     184             : 
     185           0 :   return tmpUnion.d;
     186             : }
     187             : 
     188           0 : double libcdr::readFixedPoint(WPXInputStream *input, bool bigEndian)
     189             : {
     190           0 :   unsigned fixedPointNumber = readU32(input, bigEndian);
     191           0 :   short fixedPointNumberIntegerPart = (short)((fixedPointNumber & 0xFFFF0000) >> 16);
     192           0 :   double fixedPointNumberFractionalPart = (double)((double)(fixedPointNumber & 0x0000FFFF)/(double)0xFFFF);
     193           0 :   return ((double)fixedPointNumberIntegerPart + fixedPointNumberFractionalPart);
     194             : }
     195             : 
     196           0 : int libcdr::cdr_round(double d)
     197             : {
     198           0 :   return (d>0) ? int(d+0.5) : int(d-0.5);
     199             : }
     200             : 
     201           0 : void libcdr::writeU16(WPXBinaryData &buffer, const int value)
     202             : {
     203           0 :   buffer.append((unsigned char)(value & 0xFF));
     204           0 :   buffer.append((unsigned char)((value >> 8) & 0xFF));
     205           0 : }
     206             : 
     207           0 : void libcdr::writeU32(WPXBinaryData &buffer, const int value)
     208             : {
     209           0 :   buffer.append((unsigned char)(value & 0xFF));
     210           0 :   buffer.append((unsigned char)((value >> 8) & 0xFF));
     211           0 :   buffer.append((unsigned char)((value >> 16) & 0xFF));
     212           0 :   buffer.append((unsigned char)((value >> 24) & 0xFF));
     213           0 : }
     214             : 
     215           0 : void libcdr::writeU8(WPXBinaryData &buffer, const int value)
     216             : {
     217           0 :   buffer.append((unsigned char)(value & 0xFF));
     218           0 : }
     219             : 
     220           0 : void libcdr::appendCharacters(WPXString &text, std::vector<unsigned char> characters, unsigned short charset)
     221             : {
     222             :   static const unsigned short symbolmap [] =
     223             :   {
     224             :     0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220D, // 0x20 ..
     225             :     0x0028, 0x0029, 0x2217, 0x002B, 0x002C, 0x2212, 0x002E, 0x002F,
     226             :     0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
     227             :     0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
     228             :     0x2245, 0x0391, 0x0392, 0x03A7, 0x0394, 0x0395, 0x03A6, 0x0393,
     229             :     0x0397, 0x0399, 0x03D1, 0x039A, 0x039B, 0x039C, 0x039D, 0x039F,
     230             :     0x03A0, 0x0398, 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03C2, 0x03A9,
     231             :     0x039E, 0x03A8, 0x0396, 0x005B, 0x2234, 0x005D, 0x22A5, 0x005F,
     232             :     0xF8E5, 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03C6, 0x03B3,
     233             :     0x03B7, 0x03B9, 0x03D5, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF,
     234             :     0x03C0, 0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03C9,
     235             :     0x03BE, 0x03C8, 0x03B6, 0x007B, 0x007C, 0x007D, 0x223C, 0x0020, // .. 0x7F
     236             :     0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
     237             :     0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
     238             :     0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
     239             :     0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009E, 0x009f,
     240             :     0x20AC, 0x03D2, 0x2032, 0x2264, 0x2044, 0x221E, 0x0192, 0x2663, // 0xA0 ..
     241             :     0x2666, 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193,
     242             :     0x00B0, 0x00B1, 0x2033, 0x2265, 0x00D7, 0x221D, 0x2202, 0x2022,
     243             :     0x00F7, 0x2260, 0x2261, 0x2248, 0x2026, 0x23D0, 0x23AF, 0x21B5,
     244             :     0x2135, 0x2111, 0x211C, 0x2118, 0x2297, 0x2295, 0x2205, 0x2229,
     245             :     0x222A, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208, 0x2209,
     246             :     0x2220, 0x2207, 0x00AE, 0x00A9, 0x2122, 0x220F, 0x221A, 0x22C5,
     247             :     0x00AC, 0x2227, 0x2228, 0x21D4, 0x21D0, 0x21D1, 0x21D2, 0x21D3,
     248             :     0x25CA, 0x3008, 0x00AE, 0x00A9, 0x2122, 0x2211, 0x239B, 0x239C,
     249             :     0x239D, 0x23A1, 0x23A2, 0x23A3, 0x23A7, 0x23A8, 0x23A9, 0x23AA,
     250             :     0xF8FF, 0x3009, 0x222B, 0x2320, 0x23AE, 0x2321, 0x239E, 0x239F,
     251             :     0x23A0, 0x23A4, 0x23A5, 0x23A6, 0x23AB, 0x23AC, 0x23AD, 0x0020  // .. 0xFE
     252             :   };
     253             : 
     254             :   static const unsigned short cp874map[] =
     255             :   {
     256             :     0x20AC, 0x0020, 0x0020, 0x0020, 0x0020, 0x2026, 0x0020, 0x0020,
     257             :     0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
     258             :     0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     259             :     0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
     260             :     0x00A0, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07,
     261             :     0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
     262             :     0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
     263             :     0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
     264             :     0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
     265             :     0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F,
     266             :     0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37,
     267             :     0x0E38, 0x0E39, 0x0E3A, 0x0020, 0x0020, 0x0020, 0x0020, 0x0E3F,
     268             :     0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47,
     269             :     0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F,
     270             :     0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57,
     271             :     0x0E58, 0x0E59, 0x0E5A, 0x0E5B, 0x0020, 0x0020, 0x0020, 0x0020
     272             :   };
     273             : 
     274             :   static const unsigned short cp1250map[] =
     275             :   {
     276             :     0x20AC, 0x0020, 0x201A, 0x0020, 0x201E, 0x2026, 0x2020, 0x2021,
     277             :     0x0020, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
     278             :     0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     279             :     0x0020, 0x2122, 0x0161, 0x203A, 0x015B, 0x0165, 0x017E, 0x017A,
     280             :     0x00A0, 0x02C7, 0x02D8, 0x0141, 0x00A4, 0x0104, 0x00A6, 0x00A7,
     281             :     0x00A8, 0x00A9, 0x015E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x017B,
     282             :     0x00B0, 0x00B1, 0x02DB, 0x0142, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
     283             :     0x00B8, 0x0105, 0x015F, 0x00BB, 0x013D, 0x02DD, 0x013E, 0x017C,
     284             :     0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
     285             :     0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
     286             :     0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
     287             :     0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
     288             :     0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
     289             :     0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
     290             :     0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
     291             :     0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
     292             :   };
     293             : 
     294             :   static const unsigned short cp1251map[] =
     295             :   {
     296             :     0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
     297             :     0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
     298             :     0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     299             :     0x0020, 0x2122, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F,
     300             :     0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7,
     301             :     0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407,
     302             :     0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7,
     303             :     0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457,
     304             :     0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
     305             :     0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
     306             :     0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
     307             :     0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
     308             :     0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
     309             :     0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
     310             :     0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
     311             :     0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F
     312             :   };
     313             : 
     314             :   static const unsigned short cp1252map[] =
     315             :   {
     316             :     0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
     317             :     0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0020, 0x017D, 0x0020,
     318             :     0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     319             :     0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0020, 0x017E, 0x0178,
     320             :     0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
     321             :     0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
     322             :     0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
     323             :     0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
     324             :     0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
     325             :     0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
     326             :     0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
     327             :     0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
     328             :     0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
     329             :     0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
     330             :     0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
     331             :     0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
     332             :   };
     333             : 
     334             :   static const unsigned short cp1253map[] =
     335             :   {
     336             :     0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
     337             :     0x0020, 0x2030, 0x0020, 0x2039, 0x0020, 0x0020, 0x0020, 0x0020,
     338             :     0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     339             :     0x0020, 0x2122, 0x0020, 0x203A, 0x0020, 0x0020, 0x0020, 0x0020,
     340             :     0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
     341             :     0x00A8, 0x00A9, 0x0020, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015,
     342             :     0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7,
     343             :     0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
     344             :     0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
     345             :     0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
     346             :     0x03A0, 0x03A1, 0x0020, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
     347             :     0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
     348             :     0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
     349             :     0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
     350             :     0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
     351             :     0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x0020
     352             :   };
     353             : 
     354             :   static const unsigned short cp1254map[] =
     355             :   {
     356             :     0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
     357             :     0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0020, 0x0020, 0x0020,
     358             :     0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     359             :     0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0020, 0x0020, 0x0178,
     360             :     0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
     361             :     0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
     362             :     0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
     363             :     0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
     364             :     0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
     365             :     0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
     366             :     0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
     367             :     0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x0130, 0x015E, 0x00DF,
     368             :     0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
     369             :     0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
     370             :     0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
     371             :     0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF
     372             :   };
     373             : 
     374             :   static const unsigned short cp1255map[] =
     375             :   {
     376             :     0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
     377             :     0x02C6, 0x2030, 0x0020, 0x2039, 0x0020, 0x0020, 0x0020, 0x0020,
     378             :     0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     379             :     0x02DC, 0x2122, 0x0020, 0x203A, 0x0020, 0x0020, 0x0020, 0x0020,
     380             :     0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AA, 0x00A5, 0x00A6, 0x00A7,
     381             :     0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
     382             :     0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
     383             :     0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
     384             :     0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7,
     385             :     0x05B8, 0x05B9, 0x0020, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF,
     386             :     0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3,
     387             :     0x05F4, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
     388             :     0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
     389             :     0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
     390             :     0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
     391             :     0x05E8, 0x05E9, 0x05EA, 0x0020, 0x0020, 0x200E, 0x200F, 0x0020
     392             :   };
     393             : 
     394             :   static const unsigned short cp1256map[] =
     395             :   {
     396             :     0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
     397             :     0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
     398             :     0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     399             :     0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA,
     400             :     0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
     401             :     0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
     402             :     0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
     403             :     0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F,
     404             :     0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
     405             :     0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
     406             :     0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7,
     407             :     0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0641, 0x0642, 0x0643,
     408             :     0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7,
     409             :     0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,
     410             :     0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,
     411             :     0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2
     412             :   };
     413             : 
     414             :   static const unsigned short cp1257map[] =
     415             :   {
     416             :     0x20AC, 0x0020, 0x201A, 0x0020, 0x201E, 0x2026, 0x2020, 0x2021,
     417             :     0x0020, 0x2030, 0x0020, 0x2039, 0x0020, 0x00A8, 0x02C7, 0x00B8,
     418             :     0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     419             :     0x0020, 0x2122, 0x0020, 0x203A, 0x0020, 0x00AF, 0x02DB, 0x0020,
     420             :     0x00A0, 0x0020, 0x00A2, 0x00A3, 0x00A4, 0x0020, 0x00A6, 0x00A7,
     421             :     0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00C6,
     422             :     0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
     423             :     0x00F8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
     424             :     0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
     425             :     0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
     426             :     0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
     427             :     0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
     428             :     0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
     429             :     0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
     430             :     0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
     431             :     0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9
     432             :   };
     433             : 
     434             :   static const unsigned short cp1258map[] =
     435             :   {
     436             :     0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
     437             :     0x02C6, 0x2030, 0x0020, 0x2039, 0x0152, 0x0020, 0x0020, 0x0020,
     438             :     0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     439             :     0x02DC, 0x2122, 0x0020, 0x203A, 0x0153, 0x0020, 0x0020, 0x0178,
     440             :     0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
     441             :     0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
     442             :     0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
     443             :     0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
     444             :     0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
     445             :     0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x0300, 0x00CD, 0x00CE, 0x00CF,
     446             :     0x0110, 0x00D1, 0x0309, 0x00D3, 0x00D4, 0x01A0, 0x00D6, 0x00D7,
     447             :     0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x01AF, 0x0303, 0x00DF,
     448             :     0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
     449             :     0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0301, 0x00ED, 0x00EE, 0x00EF,
     450             :     0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7,
     451             :     0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF
     452             :   };
     453           0 :   for (std::vector<unsigned char>::const_iterator iter = characters.begin();
     454           0 :        iter != characters.end(); ++iter)
     455             :   {
     456           0 :     uint32_t ucs4Character = 0;
     457           0 :     if (*iter < 0x20)
     458           0 :       ucs4Character = 0x20;
     459           0 :     else if (*iter >= 0x20 && *iter < 0x7f)
     460             :     {
     461           0 :       if (charset == 2) // SYMBOL
     462           0 :         ucs4Character = symbolmap[*iter - 0x20];
     463             :       else
     464           0 :         ucs4Character = *iter;
     465             :     }
     466           0 :     else if (*iter == 0x7f)
     467           0 :       ucs4Character = 0x20;
     468             :     else
     469             :     {
     470           0 :       switch (charset)
     471             :       {
     472             :       case 0: // ANSI
     473           0 :         ucs4Character = cp1252map[*iter - 0x80];
     474           0 :         break;
     475             :       case 2: // SYMBOL
     476           0 :         ucs4Character = symbolmap[*iter - 0x20];
     477           0 :         break;
     478             :       case 0xa1: // GREEEK
     479           0 :         ucs4Character = cp1253map[*iter - 0x80];
     480           0 :         break;
     481             :       case 0xa2: // TURKISH
     482           0 :         ucs4Character = cp1254map[*iter - 0x80];
     483           0 :         break;
     484             :       case 0xa3: // VIETNAMESE
     485           0 :         ucs4Character = cp1258map[*iter - 0x80];
     486           0 :         break;
     487             :       case 0xb1: // HEBREW
     488           0 :         ucs4Character = cp1255map[*iter - 0x80];
     489           0 :         break;
     490             :       case 0xb2: // ARABIC
     491           0 :         ucs4Character = cp1256map[*iter - 0x80];
     492           0 :         break;
     493             :       case 0xba: // BALTIC
     494           0 :         ucs4Character = cp1257map[*iter - 0x80];
     495           0 :         break;
     496             :       case 0xcc: // RUSSIAN
     497           0 :         ucs4Character = cp1251map[*iter - 0x80];
     498           0 :         break;
     499             :       case 0xde: // THAI
     500           0 :         ucs4Character = cp874map[*iter - 0x80];
     501           0 :         break;
     502             :       case 0xee: // CENTRAL EUROPE
     503           0 :         ucs4Character = cp1250map[*iter - 0x80];
     504           0 :         break;
     505             :       default:
     506           0 :         ucs4Character = *iter;
     507           0 :         break;
     508             :       }
     509             :     }
     510           0 :     _appendUCS4(text, ucs4Character);
     511             :   }
     512           0 : }
     513             : 
     514           0 : void libcdr::appendCharacters(WPXString &text, std::vector<unsigned char> characters)
     515             : {
     516           0 :   for (std::vector<unsigned char>::const_iterator iter = characters.begin();
     517           0 :        iter != characters.end();)
     518             :   {
     519           0 :     uint16_t high_surrogate = 0;
     520           0 :     bool fail = false;
     521           0 :     uint32_t ucs4Character = 0;
     522           0 :     while (true)
     523             :     {
     524           0 :       if (iter == characters.end())
     525             :       {
     526           0 :         fail = true;
     527           0 :         break;
     528             :       }
     529           0 :       uint16_t character = *iter++;
     530           0 :       character |= (uint16_t)(*iter++) << 8;
     531           0 :       if (character >= 0xdc00 && character < 0xe000) /* low surrogate */
     532             :       {
     533           0 :         if (high_surrogate)
     534             :         {
     535           0 :           ucs4Character = SURROGATE_VALUE(high_surrogate, character);
     536           0 :           high_surrogate = 0;
     537           0 :           break;
     538             :         }
     539             :         else
     540             :         {
     541           0 :           fail = true;
     542           0 :           break;
     543             :         }
     544             :       }
     545             :       else
     546             :       {
     547           0 :         if (high_surrogate)
     548             :         {
     549           0 :           fail = true;
     550           0 :           break;
     551             :         }
     552           0 :         if (character >= 0xd800 && character < 0xdc00) /* high surrogate */
     553           0 :           high_surrogate = character;
     554             :         else
     555             :         {
     556           0 :           ucs4Character = character;
     557           0 :           break;
     558             :         }
     559             :       }
     560             :     }
     561           0 :     if (fail)
     562           0 :       throw libcdr::GenericException();
     563             : 
     564           0 :     _appendUCS4(text, ucs4Character);
     565             :   }
     566           0 : }
     567             : 
     568             : #ifdef DEBUG
     569             : const char *libcdr::toFourCC(unsigned value, bool bigEndian)
     570             : {
     571             :   static char sValue[5] = { 0, 0, 0, 0, 0 };
     572             :   if (bigEndian)
     573             :   {
     574             :     sValue[3] = value & 0xff;
     575             :     sValue[2] = (value & 0xff00) >> 8;
     576             :     sValue[1] = (value & 0xff0000) >> 16;
     577             :     sValue[0] = (value & 0xff000000) >> 24;
     578             :   }
     579             :   else
     580             :   {
     581             :     sValue[0] = value & 0xff;
     582             :     sValue[1] = (value & 0xff00) >> 8;
     583             :     sValue[2] = (value & 0xff0000) >> 16;
     584             :     sValue[3] = (value & 0xff000000) >> 24;
     585             :   }
     586             :   return sValue;
     587             : }
     588             : #endif
     589             : 
     590             : /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated by: LCOV version 1.10