Changeset 3405 for trunk/jons-gtk2-gui

Show
Ignore:
Timestamp:
03/24/03 03:59:27 (6 years ago)
Author:
bostjanlah
Message:

Add a character conversion from UTF-8 to user's encoding

Location:
trunk/jons-gtk2-gui/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/jons-gtk2-gui/src/utilities.cpp

    r3398 r3405  
    5151                return g_convert(input_text, len, "UTF-8", cs, &b_in, &b_out, NULL); 
    5252        } 
     53    } 
     54     
     55    return g_strdup(input_text); 
     56} 
     57 
     58char * 
     59convert_from_utf8(const char *input_text, const char *output_enc) 
     60{ 
     61    if (input_text == NULL) 
     62    return NULL; 
     63   
     64  if (input_text[0] == 0) 
     65    return g_strdup(input_text); 
     66     
     67  size_t len = strlen(input_text); 
     68 
     69  gsize b_in, b_out; 
     70    if (output_enc != NULL && *output_enc != 0 && 
     71            strcasecmp(output_enc, "UTF-8") != 0) 
     72        return g_convert(input_text, len,  
     73                output_enc, "UTF-8", &b_in, &b_out, NULL); 
     74    else { 
     75        const char *cs; 
     76        if (g_get_charset(&cs))  
     77      // locale is already utf8 so conversion won't help - we use  
     78      // fallback character set - iso8859-1 
     79            return g_convert(input_text, len,   
     80                    "ISO8859-1", "UTF-8", &b_in, &b_out, NULL); 
     81        else 
     82            return g_convert(input_text, len,  
     83                    cs, "UTF-8", &b_in, &b_out, NULL); 
    5384    } 
    5485     
  • trunk/jons-gtk2-gui/src/utilities.h

    r3398 r3405  
    22#define _UTILITIES_H_ 
    33 
     4#include <gtk/gtk.h> 
    45#include <string> 
    56 
    67char * 
    78convert_to_utf8(const char *input_text, const char *input_enc = NULL); 
     9char * 
     10convert_from_utf8(const char *input_text, const char *output_enc); 
    811 
    912std::string