mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Add UTF-8 charset
This commit is contained in:
parent
397a73b685
commit
7c67adea66
8 changed files with 59 additions and 8 deletions
|
@ -1,3 +1,10 @@
|
|||
2001-04-20 Werner Koch <wk@gnupg.org>
|
||||
|
||||
* 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 <wk@gnupg.org>
|
||||
|
||||
* miscutil.c (asctimestamp): Handle negative times. We must do
|
||||
|
|
|
@ -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( ;; ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue