Changeset a252c1a for util.c


Ignore:
Timestamp:
2005-12-31T20:29:15Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
39cc341
Parents:
c88999c
Message:

Removed useless UTF8-related functions (iconv works a lot better).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • util.c

    rc88999c ra252c1a  
    3838#include <glib.h>
    3939#include <time.h>
    40 
    41 char *utf8_to_str(const char *in)
    42 {
    43         int n = 0, i = 0;
    44         int inlen;
    45         char *result;
    46 
    47         if (!in)
    48                 return NULL;
    49 
    50         inlen = strlen(in);
    51 
    52         result = g_malloc(inlen + 1);
    53 
    54         while (n <= inlen - 1) {
    55                 long c = (long)in[n];
    56                 if (c < 0x80)
    57                         result[i++] = (char)c;
    58                 else {
    59                         if ((c & 0xC0) == 0xC0)
    60                                 result[i++] =
    61                                     (char)(((c & 0x03) << 6) | (((unsigned char)in[++n]) & 0x3F));
    62                         else if ((c & 0xE0) == 0xE0) {
    63                                 if (n + 2 <= inlen) {
    64                                         result[i] =
    65                                             (char)(((c & 0xF) << 4) | (((unsigned char)in[++n]) & 0x3F));
    66                                         result[i] =
    67                                             (char)(((unsigned char)result[i]) |
    68                                                    (((unsigned char)in[++n]) & 0x3F));
    69                                         i++;
    70                                 } else
    71                                         n += 2;
    72                         } else if ((c & 0xF0) == 0xF0)
    73                                 n += 3;
    74                         else if ((c & 0xF8) == 0xF8)
    75                                 n += 4;
    76                         else if ((c & 0xFC) == 0xFC)
    77                                 n += 5;
    78                 }
    79                 n++;
    80         }
    81         result[i] = '\0';
    82 
    83         return result;
    84 }
    85 
    86 char *str_to_utf8(const char *in)
    87 {
    88         int n = 0, i = 0;
    89         int inlen;
    90         char *result = NULL;
    91 
    92         if (!in)
    93                 return NULL;
    94 
    95         inlen = strlen(in);
    96 
    97         result = g_malloc(inlen * 2 + 1);
    98 
    99         while (n < inlen) {
    100                 long c = (long)in[n];
    101                 if (c == 27) {
    102                         n += 2;
    103                         if (in[n] == 'x')
    104                                 n++;
    105                         if (in[n] == '3')
    106                                 n++;
    107                         n += 2;
    108                         continue;
    109                 }
    110                 /* why are we removing newlines and carriage returns?
    111                 if ((c == 0x0D) || (c == 0x0A)) {
    112                         n++;
    113                         continue;
    114                 }
    115                 */
    116                 if (c < 128)
    117                         result[i++] = (char)c;
    118                 else {
    119                         result[i++] = (char)((c >> 6) | 192);
    120                         result[i++] = (char)((c & 63) | 128);
    121                 }
    122                 n++;
    123         }
    124         result[i] = '\0';
    125 
    126         return result;
    127 }
    12840
    12941void strip_linefeed(gchar *text)
Note: See TracChangeset for help on using the changeset viewer.