diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/ChangeLog | 7 | ||||
-rw-r--r-- | util/strgutil.c | 22 |
2 files changed, 27 insertions, 2 deletions
diff --git a/util/ChangeLog b/util/ChangeLog index 1530f07b3..63d932d77 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,10 @@ +2001-04-20 Werner Koch <[email protected]> + + * strgutil.c (set_native_charset): Allow utf-8 by introducing the + new no_translation variable. + (native_to_utf8): Handle no_translation. + (utf8_to_native): Ditto. + 2001-04-19 Werner Koch <[email protected]> * miscutil.c (asctimestamp): Handle negative times. We must do diff --git a/util/strgutil.c b/util/strgutil.c index f65a16167..c1531bbe3 100644 --- a/util/strgutil.c +++ b/util/strgutil.c @@ -67,7 +67,7 @@ static ushort latin2_unicode[128] = { static const char *active_charset_name = "iso-8859-1"; static ushort *active_charset = NULL; - +static int no_translation = 0; void free_strlist( STRLIST sl ) @@ -327,16 +327,24 @@ set_native_charset( const char *newset ) { if( !stricmp( newset, "iso-8859-1" ) ) { active_charset_name = "iso-8859-1"; + no_translation = 0; active_charset = NULL; } else if( !stricmp( newset, "iso-8859-2" ) ) { active_charset_name = "iso-8859-2"; + no_translation = 0; active_charset = latin2_unicode; } else if( !stricmp( newset, "koi8-r" ) ) { active_charset_name = "koi8-r"; + no_translation = 0; active_charset = koi8_unicode; } + else if( !stricmp (newset, "utf8" ) || !stricmp(newset, "utf-8") ) { + active_charset_name = "utf-8"; + no_translation = 1; + active_charset = NULL; + } else return G10ERR_GENERAL; return 0; @@ -360,7 +368,10 @@ native_to_utf8( const char *string ) byte *p; size_t length=0; - if( active_charset ) { + if (no_translation) { + buffer = m_strdup (string); + } + else if( active_charset ) { for(s=string; *s; s++ ) { length++; if( *s & 0x80 ) @@ -424,6 +435,13 @@ utf8_to_native( const char *string, size_t length ) size_t slen; int resync = 0; + if (no_translation) { + buffer = m_alloc (length+1); + memcpy (buffer, string, length); + buffer[length] = 0; /* make sure it is a string */ + return buffer; + } + /* 1. pass (p==NULL): count the extended utf-8 characters */ /* 2. pass (p!=NULL): create string */ for( ;; ) { |