Populate the rangespec according to the objects min and max. */
| 517 | |
| 518 | /* Populate the rangespec according to the objects min and max. */ |
| 519 | static int zslParseRange(robj *min, robj *max, zrangespec *spec) { |
| 520 | char *eptr; |
| 521 | spec->minex = spec->maxex = 0; |
| 522 | |
| 523 | /* Parse the min-max interval. If one of the values is prefixed |
| 524 | * by the "(" character, it's considered "open". For instance |
| 525 | * ZRANGEBYSCORE zset (1.5 (2.5 will match min < x < max |
| 526 | * ZRANGEBYSCORE zset 1.5 2.5 will instead match min <= x <= max */ |
| 527 | if (min->encoding == OBJ_ENCODING_INT) { |
| 528 | spec->min = (long)min->m_ptr; |
| 529 | } else { |
| 530 | if (((char*)ptrFromObj(min))[0] == '(') { |
| 531 | spec->min = strtod((char*)ptrFromObj(min)+1,&eptr); |
| 532 | if (eptr[0] != '\0' || std::isnan(spec->min)) return C_ERR; |
| 533 | spec->minex = 1; |
| 534 | } else { |
| 535 | spec->min = strtod((char*)ptrFromObj(min),&eptr); |
| 536 | if (eptr[0] != '\0' || std::isnan(spec->min)) return C_ERR; |
| 537 | } |
| 538 | } |
| 539 | if (max->encoding == OBJ_ENCODING_INT) { |
| 540 | spec->max = (long)max->m_ptr; |
| 541 | } else { |
| 542 | if (((char*)ptrFromObj(max))[0] == '(') { |
| 543 | spec->max = strtod((char*)ptrFromObj(max)+1,&eptr); |
| 544 | if (eptr[0] != '\0' || std::isnan(spec->max)) return C_ERR; |
| 545 | spec->maxex = 1; |
| 546 | } else { |
| 547 | spec->max = strtod((char*)ptrFromObj(max),&eptr); |
| 548 | if (eptr[0] != '\0' || std::isnan(spec->max)) return C_ERR; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | return C_OK; |
| 553 | } |
| 554 | |
| 555 | /* ------------------------ Lexicographic ranges ---------------------------- */ |
| 556 |
no test coverage detected