Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Encoding.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-  $Id: Encoding.cpp,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $
00002 
00003 #include "ACEXML/common/Encoding.h"
00004 
00005 const ACEXML_Char* ACEXML_Encoding::encoding_names_[8] = {
00006   ACE_TEXT ("UCS-4BE"),
00007   ACE_TEXT ("UCS-4LE"),
00008   ACE_TEXT ("UCS-4_2143"),
00009   ACE_TEXT ("UCS-4_3412"),
00010   ACE_TEXT ("UTF-16BE"),
00011   ACE_TEXT ("UTF-16LE"),
00012   ACE_TEXT ("UTF-8"),
00013   ACE_TEXT ("Unsupported Encoding")
00014 };
00015 
00016 const ACEXML_UTF8 ACEXML_Encoding::byte_order_mark_[][4] = {
00017   { '\x00', '\x00', '\xFE', '\xFF' }, // UCS-4, big-endian  (1234 order)
00018   { '\xFF', '\xFE', '\x00', '\x00' }, // UCS-4, little-endian  (4321 order)
00019   { '\x00', '\x00', '\xFF', '\xFE' }, // UCS-4, unusual octet order (2143)
00020   { '\xFE', '\xFF', '\x00', '\x00' }, // UCS-4, unusual octet order (3412)
00021   { '\xFE', '\xFF', '\xFF', '\xFF' }, // UTF-16, big-endian (3 & 4 ignored)
00022   { '\xFF', '\xFE', '\xFF', '\xFF' }, // UTF-16, little-endian ( 3 & 4 ignored)
00023   { '\xEF', '\xBB', '\xBF', '\xFF' }  // UTF-8
00024 };
00025 
00026 const ACEXML_UTF8 ACEXML_Encoding::magic_values_[][4] = {
00027   { '\x00', '\x00', '\x00', '\x3c' }, //
00028   { '\x3c', '\x00', '\x00', '\x00' }, // UCS-4 and variants
00029   { '\x00', '\x00', '\x3c', '\x00' }, //
00030   { '\x00', '\x3c', '\x00', '\x00' }, //
00031   { '\x00', '\x3c', '\x00', '\x3f' }, // UTF-16BE
00032   { '\x3c', '\x00', '\x3f', '\x00' }, // UTF-16LE
00033   { '\x3c', '\x3f', '\x78', '\x6d' }, // UTF-8
00034 };
00035 
00036 const ACEXML_Char*
00037 ACEXML_Encoding::get_encoding (const char* input)
00038 {
00039   if (ACE_OS::memcmp (&ACEXML_Encoding::byte_order_mark_[ACEXML_Encoding::UTF16BE][0], input, 2) == 0)
00040     return ACEXML_Encoding::encoding_names_[ACEXML_Encoding::UTF16BE];
00041   else if (ACE_OS::memcmp (&ACEXML_Encoding::byte_order_mark_[ACEXML_Encoding::UTF16LE][0], input, 2) == 0)
00042     return ACEXML_Encoding::encoding_names_[ACEXML_Encoding::UTF16LE];
00043   else if (ACE_OS::memcmp (&ACEXML_Encoding::byte_order_mark_[ACEXML_Encoding::UTF8][0], input, 4) == 0)
00044     return ACEXML_Encoding::encoding_names_[ACEXML_Encoding::UTF8];
00045   else if (ACE_OS::memcmp (&ACEXML_Encoding::magic_values_[ACEXML_Encoding::UTF16BE][0], input, 4) == 0)
00046     return ACEXML_Encoding::encoding_names_[ACEXML_Encoding::UTF16BE];
00047   else if (ACE_OS::memcmp (&ACEXML_Encoding::magic_values_[ACEXML_Encoding::UTF16LE][0], input, 4) == 0)
00048     return ACEXML_Encoding::encoding_names_[ACEXML_Encoding::UTF16LE];
00049   else if (ACE_OS::memcmp (&ACEXML_Encoding::magic_values_[ACEXML_Encoding::UTF8][0], input, 4) == 0)
00050     return ACEXML_Encoding::encoding_names_[ACEXML_Encoding::UTF8];
00051   else
00052     return ACEXML_Encoding::encoding_names_[ACEXML_Encoding::OTHER];
00053 }

Generated on Mon Jun 16 13:23:21 2003 for ACEXML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002