PostGIS  2.2.7dev-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 639 of file lwgeom_api.c.

Referenced by rt_raster_from_hexwkb().

640 {
641  /* do this a little brute force to make it faster */
642 
643  uint8_t result_high = 0;
644  uint8_t result_low = 0;
645 
646  switch (str[0])
647  {
648  case '0' :
649  result_high = 0;
650  break;
651  case '1' :
652  result_high = 1;
653  break;
654  case '2' :
655  result_high = 2;
656  break;
657  case '3' :
658  result_high = 3;
659  break;
660  case '4' :
661  result_high = 4;
662  break;
663  case '5' :
664  result_high = 5;
665  break;
666  case '6' :
667  result_high = 6;
668  break;
669  case '7' :
670  result_high = 7;
671  break;
672  case '8' :
673  result_high = 8;
674  break;
675  case '9' :
676  result_high = 9;
677  break;
678  case 'A' :
679  case 'a' :
680  result_high = 10;
681  break;
682  case 'B' :
683  case 'b' :
684  result_high = 11;
685  break;
686  case 'C' :
687  case 'c' :
688  result_high = 12;
689  break;
690  case 'D' :
691  case 'd' :
692  result_high = 13;
693  break;
694  case 'E' :
695  case 'e' :
696  result_high = 14;
697  break;
698  case 'F' :
699  case 'f' :
700  result_high = 15;
701  break;
702  }
703  switch (str[1])
704  {
705  case '0' :
706  result_low = 0;
707  break;
708  case '1' :
709  result_low = 1;
710  break;
711  case '2' :
712  result_low = 2;
713  break;
714  case '3' :
715  result_low = 3;
716  break;
717  case '4' :
718  result_low = 4;
719  break;
720  case '5' :
721  result_low = 5;
722  break;
723  case '6' :
724  result_low = 6;
725  break;
726  case '7' :
727  result_low = 7;
728  break;
729  case '8' :
730  result_low = 8;
731  break;
732  case '9' :
733  result_low = 9;
734  break;
735  case 'A' :
736  case 'a' :
737  result_low = 10;
738  break;
739  case 'B' :
740  case 'b' :
741  result_low = 11;
742  break;
743  case 'C' :
744  case 'c' :
745  result_low = 12;
746  break;
747  case 'D' :
748  case 'd' :
749  result_low = 13;
750  break;
751  case 'E' :
752  case 'e' :
753  result_low = 14;
754  break;
755  case 'F' :
756  case 'f' :
757  result_low = 15;
758  break;
759  }
760  return (uint8_t) ((result_high<<4) + result_low);
761 }

Here is the caller graph for this function: