UTF16_Encoding_Converter.inl

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 // UTF16_Encoding_Converter.inl,v 4.1 2006/01/09 15:18:53 elliott_c Exp
00003 
00004 // ======================================================================
00005 //
00006 // The actual conversion methods are covered by the copyright information
00007 // below.
00008 // Chad Elliott 4/28/2005
00009 //
00010 // Copyright 2001-2004 Unicode, Inc.
00011 //
00012 // Limitations on Rights to Redistribute This Code
00013 //
00014 // Unicode, Inc. hereby grants the right to freely use the information
00015 // supplied in this file in the creation of products supporting the
00016 // Unicode Standard, and to make copies of this file in any form
00017 // for internal or external distribution as long as this notice
00018 // remains attached.
00019 //
00020 // ======================================================================
00021 
00022 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 ACE_INLINE bool
00025 ACE_UTF16_Encoding_Converter::is_legal_utf8 (const ACE_Byte* source,
00026                                              size_t length) const
00027 {
00028   ACE_Byte a;
00029   const ACE_Byte* srcptr = source + length;
00030 
00031   switch (length)
00032     {
00033     default:
00034       return false;
00035 
00036     // Everything else falls through when "true"...
00037     case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
00038     case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
00039     case 2: if ((a = (*--srcptr)) > 0xBF) return false;
00040 
00041     switch (*source)
00042       {
00043       // no fall-through in this inner switch
00044       case 0xE0:
00045         if (a < 0xA0)
00046           return false;
00047         break;
00048       case 0xED:
00049         if (a > 0x9F)
00050           return false;
00051         break;
00052       case 0xF0:
00053         if (a < 0x90)
00054           return false;
00055         break;
00056       case 0xF4:
00057         if (a > 0x8F)
00058           return false;
00059         break;
00060       default:
00061         if (a < 0x80)
00062           return false;
00063     }
00064 
00065     case 1:
00066       if (*source >= 0x80 && *source < 0xC2)
00067         return false;
00068     }
00069 
00070   if (*source > 0xF4)
00071     return false;
00072 
00073   return true;
00074 }
00075 
00076 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:42:09 2006 for ACE by doxygen 1.3.6