PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ parse_hex()

uint8_t parse_hex ( char *  str)

Convert a single hex digit into the corresponding char.

Convert a single hex digit into the corresponding char.

No error checking done!

Definition at line 547 of file lwgeom_api.c.

548 {
549  /* do this a little brute force to make it faster */
550 
551  uint8_t result_high = 0;
552  uint8_t result_low = 0;
553 
554  switch (str[0])
555  {
556  case '0' :
557  result_high = 0;
558  break;
559  case '1' :
560  result_high = 1;
561  break;
562  case '2' :
563  result_high = 2;
564  break;
565  case '3' :
566  result_high = 3;
567  break;
568  case '4' :
569  result_high = 4;
570  break;
571  case '5' :
572  result_high = 5;
573  break;
574  case '6' :
575  result_high = 6;
576  break;
577  case '7' :
578  result_high = 7;
579  break;
580  case '8' :
581  result_high = 8;
582  break;
583  case '9' :
584  result_high = 9;
585  break;
586  case 'A' :
587  case 'a' :
588  result_high = 10;
589  break;
590  case 'B' :
591  case 'b' :
592  result_high = 11;
593  break;
594  case 'C' :
595  case 'c' :
596  result_high = 12;
597  break;
598  case 'D' :
599  case 'd' :
600  result_high = 13;
601  break;
602  case 'E' :
603  case 'e' :
604  result_high = 14;
605  break;
606  case 'F' :
607  case 'f' :
608  result_high = 15;
609  break;
610  }
611  switch (str[1])
612  {
613  case '0' :
614  result_low = 0;
615  break;
616  case '1' :
617  result_low = 1;
618  break;
619  case '2' :
620  result_low = 2;
621  break;
622  case '3' :
623  result_low = 3;
624  break;
625  case '4' :
626  result_low = 4;
627  break;
628  case '5' :
629  result_low = 5;
630  break;
631  case '6' :
632  result_low = 6;
633  break;
634  case '7' :
635  result_low = 7;
636  break;
637  case '8' :
638  result_low = 8;
639  break;
640  case '9' :
641  result_low = 9;
642  break;
643  case 'A' :
644  case 'a' :
645  result_low = 10;
646  break;
647  case 'B' :
648  case 'b' :
649  result_low = 11;
650  break;
651  case 'C' :
652  case 'c' :
653  result_low = 12;
654  break;
655  case 'D' :
656  case 'd' :
657  result_low = 13;
658  break;
659  case 'E' :
660  case 'e' :
661  result_low = 14;
662  break;
663  case 'F' :
664  case 'f' :
665  result_low = 15;
666  break;
667  }
668  return (uint8_t) ((result_high<<4) + result_low);
669 }
unsigned char uint8_t
Definition: uthash.h:79

Referenced by rt_raster_from_hexwkb().

Here is the caller graph for this function: