lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lynx-dev Tweaking HTML.c to insert characters (was: UTF-8 display qu


From: Klaus Weide
Subject: Re: lynx-dev Tweaking HTML.c to insert characters (was: UTF-8 display questions)
Date: Thu, 8 Jun 2000 11:29:50 -0500 (CDT)

I have to correct my previous message.

On Thu, 8 Jun 2000, Klaus Weide wrote:

>    {
>      char replace_buf[8];     /* or bigger */
>      if (
>        UCTransUniCharStr(replace_buf, sizeof(replace_buf),
>                          0x2018,      /* whatever Unicode character */
>                          current_char_set, /* display character set */
>                          1) >= 0
>        ) {
>        HTML_put_string(me, replace_buf);
>      } else {
>        /* UCTransUniCharStr shouldn't fail, but just in case, some
>         fallback: */
>               HTML_put_character(me, '`');
>      }
>    }
> 
> UCTransUniCharStr will just UTF-8-encode the Unicode value if
> current_char_set says UTF-8, 

Err, wouldn't it be nice, but it doesn't.

I offer two alternatives instead; the first has the UTF-8 hardwired,
in the interest of avoiding unnecessary calls.

   {
     UCode_t code = 0x2018;     /* hardwired Unicode character */
     char replace_buf[8] = "\342\200\230";      /* hardwired UTF-8 for it */ */
     int outlen = 3;    /*  */
     if (LYCharSet_UC[current_char_set].enc != UCT_ENC_UTF8) {
       outlen = UCTransUniCharStr(replace_buf, sizeof(replace_buf),
                           code,        /* whatever Unicode character */
                           current_char_set, /* display character set */
                           1);
       }
     if (outlen >= 0) {
       HTML_put_string(me, replace_buf);
     } else {
       /* UCTransUniCharStr shouldn't fail, but just in case, some
          fallback: */
        HTML_put_character(me, '`');
     }
   }


   {
     UCode_t code = 0x2018;     /* hardwired Unicode character */
     char replace_buf[8];
     BOOLEAN ok;
     if (LYCharSet_UC[current_char_set].enc == UCT_ENC_UTF8) {
       ok = UCConvertUniToUtf8(code, replace_buf);
     } else {
       ok = (UCTransUniCharStr(replace_buf, sizeof(replace_buf),
                               code,    /* whatever Unicode character */
                               current_char_set, /* display character set */
                               1) >= 0);
       }
     if (ok) {
       HTML_put_string(me, replace_buf);
     } else {
       /* UCConvert / UCTransUniCharStr shouldn't fail, but just in case,
          some fallback: */
        HTML_put_character(me, '`');
     }
   }


> This is completely untested; if you use it, let us know how it goes.

Still true.

  Klaus


; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]