/[winpt]/trunk/Src/wptUTF8.cpp
ViewVC logotype

Diff of /trunk/Src/wptUTF8.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 48 by werner, Mon Oct 31 21:14:11 2005 UTC revision 181 by twoaday, Tue Mar 14 11:01:22 2006 UTC
# Line 1  Line 1 
1  /* wptUTF8.cpp - UTF8 conversation  /* wptUTF8.cpp - UTF8 conversation
2   *      Copyright (C) 1994, 1998-2001 Free Software Foundation, Inc.   *      Copyright (C) 1994, 1998-2001 Free Software Foundation, Inc.
3   *      Copyright (C) 2002, 2004 Timo Schulz   *      Copyright (C) 2002, 2004, 2005 Timo Schulz
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
6   *   *
# Line 32  Line 32 
32  #include "wptTypes.h"  #include "wptTypes.h"
33  #include "wptErrors.h"  #include "wptErrors.h"
34    
 static u16 koi8_unicode[128] = {  
     0x2500,0x2502,0x250c,0x2510,0x2514,0x2518,0x251c,0x2524,  
     0x252c,0x2534,0x253c,0x2580,0x2584,0x2588,0x258c,0x2590,  
     0x2591,0x2592,0x2593,0x2320,0x25a0,0x2219,0x221a,0x2248,  
     0x2264,0x2265,0x00a0,0x2321,0x00b0,0x00b2,0x00b7,0x00f7,  
     0x2550,0x2551,0x2552,0x0451,0x2553,0x2554,0x2555,0x2556,  
     0x2557,0x2558,0x2559,0x255a,0x255b,0x255c,0x255d,0x255e,  
     0x255f,0x2560,0x2561,0x0401,0x2562,0x2563,0x2564,0x2565,  
     0x2566,0x2567,0x2568,0x2569,0x256a,0x256b,0x256c,0x00a9,  
     0x044e,0x0430,0x0431,0x0446,0x0434,0x0435,0x0444,0x0433,  
     0x0445,0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,  
     0x043f,0x044f,0x0440,0x0441,0x0442,0x0443,0x0436,0x0432,  
     0x044c,0x044b,0x0437,0x0448,0x044d,0x0449,0x0447,0x044a,  
     0x042e,0x0410,0x0411,0x0426,0x0414,0x0415,0x0424,0x0413,  
     0x0425,0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,  
     0x041f,0x042f,0x0420,0x0421,0x0422,0x0423,0x0416,0x0412,  
     0x042c,0x042b,0x0417,0x0428,0x042d,0x0429,0x0427,0x042a  
 };  
35    
36  static u16 latin2_unicode[128] = {  static WORD latin2_unicode[128] = {
37      0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,      0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,
38      0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,      0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,
39      0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,      0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,
# Line 72  static u16 latin2_unicode[128] = { Line 54  static u16 latin2_unicode[128] = {
54    
55    
56  static const char *active_charset_name = "iso-8859-1";  static const char *active_charset_name = "iso-8859-1";
57  static u16 *active_charset = NULL;  static WORD *active_charset = NULL;
58  static int no_translation = 0;  static int no_translation = 0;
59    
60    
61  static int  static int
62  ascii_strcasecmp( const char *a, const char *b )  ascii_strcasecmp( const char *a, const char *b )
63  {  {
# Line 87  ascii_strcasecmp( const char *a, const c Line 70  ascii_strcasecmp( const char *a, const c
70      }      }
71            
72      return *a == *b? 0 : (toupper (*a) - toupper (*b));      return *a == *b? 0 : (toupper (*a) - toupper (*b));
73  } /* ascii_strcasecmp */  }
74    
75  int  int
76  set_native_charset( const char *newset )  set_native_charset( const char *newset )
# Line 101  set_native_charset( const char *newset ) Line 84  set_native_charset( const char *newset )
84        active_charset_name = "iso-8859-2";        active_charset_name = "iso-8859-2";
85        no_translation = 0;        no_translation = 0;
86        active_charset = latin2_unicode;        active_charset = latin2_unicode;
     }  
   else if( !ascii_strcasecmp( newset, "koi8-r" ) ) {  
       active_charset_name = "koi8-r";  
       no_translation = 0;  
       active_charset = koi8_unicode;  
87    }    }
88    else if( !ascii_strcasecmp (newset, "utf8" )    else if( !ascii_strcasecmp (newset, "utf8" )
89             || !ascii_strcasecmp(newset, "utf-8") ) {             || !ascii_strcasecmp(newset, "utf-8") ) {
# Line 117  set_native_charset( const char *newset ) Line 95  set_native_charset( const char *newset )
95        return WPTERR_GENERAL;        return WPTERR_GENERAL;
96    
97    return 0;    return 0;
98  } /* set_native_charset */  }
99    
100  const char*  const char*
101  get_native_charset( void )  get_native_charset( void )
102  {        {      
103      return active_charset_name;      return active_charset_name;
104  } /* get_native_charset */  }
105    
106    
107  /****************  /****************
108   * Convert string, which is in native encoding to UTF8 and return the   * Convert string, which is in native encoding to UTF8 and return the
# Line 148  native_to_utf8( const char *string ) Line 127  native_to_utf8( const char *string )
127        buffer = (char *)malloc( length + 1 );        buffer = (char *)malloc( length + 1 );
128        for(p=(byte *)buffer, s=(byte *)string; *s; s++ ) {        for(p=(byte *)buffer, s=(byte *)string; *s; s++ ) {
129            if( *s & 0x80 ) {                        if( *s & 0x80 ) {            
130                u16 val = active_charset[ *s & 0x7f ];                WORD val = active_charset[ *s & 0x7f ];
131                if( val < 0x0800 ) {                                if( val < 0x0800 ) {                
132                    *p++ = 0xc0 | ( (val >> 6) & 0x1f );                    *p++ = 0xc0 | ( (val >> 6) & 0x1f );
133                    *p++ = 0x80 | (  val & 0x3f );                    *p++ = 0x80 | (  val & 0x3f );
# Line 579  conv_charset (byte *string, size_t size, Line 558  conv_charset (byte *string, size_t size,
558  } /* conv_charset */  } /* conv_charset */
559    
560    
561  char *  /* XXX: the conv_charset() call fails when the user-id was created
562            with iso-8859-1 but it is assumed that CP850 (gpg console) is used. */
563    
564    char*
565  utf8_to_wincp (const char * s, size_t len)  utf8_to_wincp (const char * s, size_t len)
566  {  {
567      char * decs;      char *decs;
568      decs = utf8_to_native (s, len, 0);      decs = utf8_to_native (s, len, 0);
569      conv_charset ((byte *)decs, strlen (decs), 1);      conv_charset ((byte *)decs, strlen (decs), 1);
570      return decs;      return decs;
571  }  }
572    
573    
574  char *  char*
575  wincp_to_utf8 (const char * s, size_t len)  wincp_to_utf8 (const char * s, size_t len)
576  {  {
577      char * encs;      char * encs;
# Line 609  is_8bit_string (const char * str) Line 591  is_8bit_string (const char * str)
591              return -1;              return -1;
592      }      }
593      return 0;      return 0;
594  } /* is_8bit_string */  }

Legend:
Removed from v.48  
changed lines
  Added in v.181

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26