PDFdev is a service provided by PDFzone.com | http://www.pdfzone.com _____________________________________________________________


On 8 Jan 2004, at 20:02, Harvey, Rebecca wrote:


// parses four characters into one wchar unicode character
wchar_t ParseHex()
{
   char *digits = "0123456789ABCDEF";
   char input[4] = "9DDF";

   /* Read 4 characters of hex encoded unicode and convert them to
uppercase. */

if (islower(input[0]))
   input[0] = toupper(input[0]);
if (islower(input[1]))
   input[1] = toupper(input[1]);
if (islower(input[2]))
   input[2] = toupper(input[2]);
if (islower(input[3]))
   input[3] = toupper(input[3]);

you're wasting CPU cycles here -- as you are accessing the memory twice


   /* Convert from hex to wchar_t */
   return (4096 * (strchr(digits, input[0]) - strchr(digits, '0'))
        + 256 * strchr(digits, input[1]) - strchr(digits, '0'))
      + 16 * strchr(digits, input[2]) - strchr(digits, '0'))
      + strchr(digits, input[2]) - strchr(digits, '0'))

This should be input[3] I think :)


    );
}

IT should however work.


An alternative would be to use something like this

wchar_t ParseHex(char *input)
{
   char *digits = "0123456789ABCDEF";
   //char input[5] = "9DDF";
  char *p = input;
 wchar_t ch = 0;

ch = (strchr(digits, toupper(*p)) - digits); // Don't need to call strchr twice -- digits points to 0 already
ch = ch << 4 | (strchr(digits, toupper(*p) - digits);
ch = ch << 4 | (strchr(digits, toupper(*p) - digits);
ch = ch << 4 | (strchr(digits, toupper(*p) - digits);


 return ch;
}

You might find C++ moans about the conversion from a char* to wchar_t -- in which case you can just cast it to a wchar_t

Steven


To change your subscription: http://www.pdfzone.com/discussions/lists-pdfdev.html



Reply via email to