PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ geometry_type_from_string()

int geometry_type_from_string ( const char *  str,
uint8_t *  type,
int *  z,
int *  m 
)

Calculate type integer and dimensional flags from string input.

Utility function to get type number from string.

Case insensitive, and insensitive to spaces at front and back. Type == 0 in the case of the string "GEOMETRY" or "GEOGRAPHY". Return LW_SUCCESS for success.

Definition at line 495 of file lwutil.c.

496{
497 char *tmpstr;
498 size_t tmpstartpos, tmpendpos;
499 size_t i;
500
501 assert(str);
502 assert(type);
503 assert(z);
504 assert(m);
505
506 /* Initialize. */
507 *type = 0;
508 *z = 0;
509 *m = 0;
510
511 /* Locate any leading/trailing spaces */
512 tmpstartpos = 0;
513 for (i = 0; i < strlen(str); i++)
514 {
515 if (str[i] != ' ')
516 {
517 tmpstartpos = i;
518 break;
519 }
520 }
521
522 tmpendpos = strlen(str) - 1;
523 for (i = strlen(str) - 1; i != 0; i--)
524 {
525 if (str[i] != ' ')
526 {
527 tmpendpos = i;
528 break;
529 }
530 }
531
532 /* Copy and convert to upper case for comparison */
533 tmpstr = lwalloc(tmpendpos - tmpstartpos + 2);
534 for (i = tmpstartpos; i <= tmpendpos; i++)
535 tmpstr[i - tmpstartpos] = dumb_toupper(str[i]);
536
537 /* Add NULL to terminate */
538 tmpstr[i - tmpstartpos] = '\0';
539
540 /* Now check for the type */
541 for (i = 0; i < GEOMTYPE_STRUCT_ARRAY_LEN; i++)
542 {
543 if (!strcmp(tmpstr, geomtype_struct_array[i].typename))
544 {
546 *z = geomtype_struct_array[i].z;
547 *m = geomtype_struct_array[i].m;
548
549 lwfree(tmpstr);
550
551 return LW_SUCCESS;
552 }
553
554 }
555
556 lwfree(tmpstr);
557
558 return LW_FAILURE;
559}
#define LW_FAILURE
Definition liblwgeom.h:96
#define LW_SUCCESS
Definition liblwgeom.h:97
#define str(s)
static char dumb_toupper(int in)
Definition lwutil.c:470
void * lwalloc(size_t size)
Definition lwutil.c:227
void lwfree(void *mem)
Definition lwutil.c:248
#define GEOMTYPE_STRUCT_ARRAY_LEN
Definition lwutil.c:459
struct geomtype_struct geomtype_struct_array[]
Definition lwutil.c:376

References dumb_toupper(), geomtype_struct_array, GEOMTYPE_STRUCT_ARRAY_LEN, LW_FAILURE, LW_SUCCESS, lwalloc(), lwfree(), geomtype_struct::m, str, geomtype_struct::type, and geomtype_struct::z.

Referenced by getTableInfo(), gserialized_typmod_in(), and test_geometry_type_from_string().

Here is the call graph for this function:
Here is the caller graph for this function: