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

Transcode.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-  $Id: Transcode.cpp,v 1.1.1.1.2.1 2003/04/21 19:14:54 chad Exp $
00002 
00003 #include "ACEXML/common/Transcode.h"
00004 
00005 #if !defined (__ACEXML_INLINE__)
00006 # include "ACEXML/common/Transcode.i"
00007 #endif /* __ACEXML_INLINE__ */
00008 
00009 int
00010 ACEXML_Transcoder::utf8s2utf16s (const ACEXML_UTF8 *src,
00011                                 ACEXML_UTF16 *dst,
00012                                 size_t len)
00013 {
00014   if (src == 0 || dst == 0)
00015     return INVALID_ARGS;
00016 
00017   size_t src_len = ACE_OS::strlen (src) + 1;
00018 
00019   size_t total_len = 0;
00020   int forward;
00021   ACEXML_UCS4 temp;
00022 
00023   while (src_len > 0)
00024     {
00025       if ((forward = ACEXML_Transcoder::utf82ucs4 (src,
00026                                                    src_len,
00027                                                    temp)) <= 0)
00028         return forward;
00029 
00030       src += forward;
00031       src_len -= forward;
00032 
00033       if ((forward = ACEXML_Transcoder::ucs42utf16 (temp,
00034                                                     dst,
00035                                                     len)) <= 0)
00036         return forward;
00037 
00038       total_len += forward;
00039       dst += forward;
00040       len -= forward;
00041     }
00042 
00043   return ACE_static_cast(int, total_len);
00044 }
00045 
00046 int
00047 ACEXML_Transcoder::utf16s2utf8s (const ACEXML_UTF16 *src,
00048                                 ACEXML_UTF8 *dst,
00049                                 size_t len)
00050 {
00051   if (src == 0 || dst == 0)
00052     return INVALID_ARGS;
00053 
00054   size_t src_len = 1;
00055   for (const ACEXML_UTF16 *p = src; *p++ != 0; ++src_len)
00056     ;
00057 
00058   size_t total_len = 0;
00059   int forward;
00060   ACEXML_UCS4 temp;
00061 
00062   while (src_len > 0)
00063     {
00064       if ((forward = ACEXML_Transcoder::utf162ucs4 (src,
00065                                                     src_len,
00066                                                     temp)) <= 0)
00067         return forward;
00068 
00069       src += forward;
00070       src_len -= forward;
00071 
00072       if ((forward = ACEXML_Transcoder::ucs42utf8 (temp,
00073                                                    dst,
00074                                                    len)) <= 0)
00075         return forward;
00076 
00077       total_len += forward;
00078       dst += forward;
00079       len -= forward;
00080     }
00081 
00082   return ACE_static_cast(int, total_len);
00083 }

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