PostGIS  2.1.10dev-r@@SVN_REVISION@@
uint8_t parse_hex ( char *  str)

Given a string with at least 2 chars in it, convert them to a byte value.

Convert a single hex digit into the corresponding char.

No error checking done!

Definition at line 604 of file lwgeom_api.c.

Referenced by rt_raster_from_hexwkb().

605 {
606  /* do this a little brute force to make it faster */
607 
608  uint8_t result_high = 0;
609  uint8_t result_low = 0;
610 
611  switch (str[0])
612  {
613  case '0' :
614  result_high = 0;
615  break;
616  case '1' :
617  result_high = 1;
618  break;
619  case '2' :
620  result_high = 2;
621  break;
622  case '3' :
623  result_high = 3;
624  break;
625  case '4' :
626  result_high = 4;
627  break;
628  case '5' :
629  result_high = 5;
630  break;
631  case '6' :
632  result_high = 6;
633  break;
634  case '7' :
635  result_high = 7;
636  break;
637  case '8' :
638  result_high = 8;
639  break;
640  case '9' :
641  result_high = 9;
642  break;
643  case 'A' :
644  case 'a' :
645  result_high = 10;
646  break;
647  case 'B' :
648  case 'b' :
649  result_high = 11;
650  break;
651  case 'C' :
652  case 'c' :
653  result_high = 12;
654  break;
655  case 'D' :
656  case 'd' :
657  result_high = 13;
658  break;
659  case 'E' :
660  case 'e' :
661  result_high = 14;
662  break;
663  case 'F' :
664  case 'f' :
665  result_high = 15;
666  break;
667  }
668  switch (str[1])
669  {
670  case '0' :
671  result_low = 0;
672  break;
673  case '1' :
674  result_low = 1;
675  break;
676  case '2' :
677  result_low = 2;
678  break;
679  case '3' :
680  result_low = 3;
681  break;
682  case '4' :
683  result_low = 4;
684  break;
685  case '5' :
686  result_low = 5;
687  break;
688  case '6' :
689  result_low = 6;
690  break;
691  case '7' :
692  result_low = 7;
693  break;
694  case '8' :
695  result_low = 8;
696  break;
697  case '9' :
698  result_low = 9;
699  break;
700  case 'A' :
701  case 'a' :
702  result_low = 10;
703  break;
704  case 'B' :
705  case 'b' :
706  result_low = 11;
707  break;
708  case 'C' :
709  case 'c' :
710  result_low = 12;
711  break;
712  case 'D' :
713  case 'd' :
714  result_low = 13;
715  break;
716  case 'E' :
717  case 'e' :
718  result_low = 14;
719  break;
720  case 'F' :
721  case 'f' :
722  result_low = 15;
723  break;
724  }
725  return (uint8_t) ((result_high<<4) + result_low);
726 }

Here is the caller graph for this function: