| 56 | } |
| 57 | |
| 58 | static FloatVector* floatvector_input(const char* s, int32 atttypmod) |
| 59 | { |
| 60 | char *lit = pstrdup(s); |
| 61 | char *str = lit; |
| 62 | while (floatvector_isspace(*str)) { |
| 63 | ++str; |
| 64 | } |
| 65 | |
| 66 | if (*str != '[') { |
| 67 | ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 68 | errmsg("malformed floatvector literal: \"%s\"", s), |
| 69 | errdetail("FloatVector contents must start with \"[\"."))); |
| 70 | } |
| 71 | |
| 72 | ++str; |
| 73 | float x[FLOATVECTOR_MAX_DIM]; |
| 74 | char *psave = NULL; |
| 75 | char *pt = strtok_r(str, ",", &psave); |
| 76 | char *stringEnd = pt; |
| 77 | int dim = 0; |
| 78 | while (pt != NULL && *stringEnd != ']') { |
| 79 | if (dim == FLOATVECTOR_MAX_DIM) { |
| 80 | ereport(ERROR, |
| 81 | (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), |
| 82 | errmsg("floatvector cannot have more than %d dimensions", FLOATVECTOR_MAX_DIM))); |
| 83 | } |
| 84 | |
| 85 | while (floatvector_isspace(*pt)) { |
| 86 | ++pt; |
| 87 | } |
| 88 | |
| 89 | /* Check for empty string like float4in */ |
| 90 | if (*pt == '\0') { |
| 91 | ereport(ERROR, |
| 92 | (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 93 | errmsg("invalid input syntax for type floatvector: \"%s\"", s))); |
| 94 | } |
| 95 | |
| 96 | /* Use strtof like float4in to avoid a double-rounding problem */ |
| 97 | x[dim] = strtof(pt, &stringEnd); |
| 98 | CheckElement(x[dim]); |
| 99 | ++dim; |
| 100 | |
| 101 | if (stringEnd == pt) { |
| 102 | ereport(ERROR, |
| 103 | (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 104 | errmsg("invalid input syntax for type floatvector: \"%s\"", s))); |
| 105 | } |
| 106 | |
| 107 | while (floatvector_isspace(*stringEnd)) { |
| 108 | ++stringEnd; |
| 109 | } |
| 110 | |
| 111 | if (*stringEnd != '\0' && *stringEnd != ']') { |
| 112 | ereport(ERROR, |
| 113 | (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 114 | errmsg("invalid input syntax for type floatvector: \"%s\"", s))); |
| 115 | } |
no test coverage detected