Ticket #257: 00-70-utf8-common.patch

File 00-70-utf8-common.patch, 1.2 KB (added by egmont, 15 years ago)

Common base for the subsequent patches

  • src/util.c

    Some common stuff used by other UTF-8 patches.
    
    diff -Naurdp mc-4.6.1.orig/src/util.c mc-4.6.1/src/util.c
    old new mbstrlen (const char *str) 
    113113        return strlen (str); 
    114114} 
    115115 
     116int 
     117columns_to_bytes (const char *str, int col) 
     118{ 
     119    int bytes = 0; 
     120    int columns = 0; 
     121    int i; 
     122#ifdef UTF8 
     123    if (SLsmg_Is_Unicode) { 
     124        static mbstate_t s; 
     125        while (columns < col) { 
     126            memset (&s, 0, sizeof (s)); 
     127            i = mbrlen (str + bytes, -1, &s); 
     128            if (i <= 0) { 
     129                return col + bytes - columns; 
     130            } 
     131            bytes += i; 
     132            columns ++; 
     133        } 
     134        return col + bytes - columns; 
     135    } else 
     136#endif 
     137        return col; 
     138} 
     139 
    116140#ifdef UTF8 
    117141 
    118142void  
  • src/util.h

    diff -Naurdp mc-4.6.1.orig/src/util.h mc-4.6.1/src/util.h
    old new char *get_owner (int); 
    9595 
    9696void fix_utf8(char *str); 
    9797size_t mbstrlen (const char *); 
     98int columns_to_bytes (const char *, int); 
    9899wchar_t *mbstr_to_wchar (const char *); 
    99100char *wchar_to_mbstr (const wchar_t *); 
    100101char *utf8_to_local(char *str);