Read "confidence": out of an edge property blob. Absent/unparseable * reads as -1 so any edge that carries a confidence outranks one that does * not. */
| 1765 | * reads as -1 so any edge that carries a confidence outranks one that does |
| 1766 | * not. */ |
| 1767 | static double edge_props_confidence(const char *props_json) { |
| 1768 | if (!props_json) { |
| 1769 | return CBM_EDGE_CONF_ABSENT; |
| 1770 | } |
| 1771 | static const char conf_key[] = "\"confidence\":"; |
| 1772 | const char *p = strstr(props_json, conf_key); |
| 1773 | if (!p) { |
| 1774 | return CBM_EDGE_CONF_ABSENT; |
| 1775 | } |
| 1776 | /* strtod answers 0.0 for text it cannot read, and 0.0 is a real |
| 1777 | * confidence that beats CBM_EDGE_CONF_ABSENT. So a blob carrying |
| 1778 | * "confidence":null used to outrank a clean blob that carries no |
| 1779 | * confidence at all, and displace it. Ask strtod where it stopped: an |
| 1780 | * end pointer that never moved means it read nothing. */ |
| 1781 | const char *value = p + sizeof(conf_key) - SKIP_ONE; |
| 1782 | char *end = NULL; |
| 1783 | double conf = strtod(value, &end); |
| 1784 | if (end == value) { |
| 1785 | return CBM_EDGE_CONF_ABSENT; |
| 1786 | } |
| 1787 | return conf; |
| 1788 | } |
| 1789 | |
| 1790 | /* Decide whether an incoming property blob replaces the stored one on a |
| 1791 | * duplicate edge key. |
no outgoing calls
no test coverage detected