* xmlSchemaValidateDates: * @type: the expected type or XML_SCHEMAS_UNKNOWN * @dateTime: string to analyze * @val: the return computed value * * Check that @dateTime conforms to the lexical space of one of the date types. * if true a value is computed and returned in @val. * * Returns 0 if this validates, a positive error code number otherwise * and -1 in case of internal or API
| 1776 | * and -1 in case of internal or API error. |
| 1777 | */ |
| 1778 | static int |
| 1779 | xmlSchemaValidateDates (xmlSchemaValType type, |
| 1780 | const xmlChar *dateTime, xmlSchemaValPtr *val, |
| 1781 | int collapse) { |
| 1782 | xmlSchemaValPtr dt; |
| 1783 | int ret; |
| 1784 | const xmlChar *cur = dateTime; |
| 1785 | |
| 1786 | #define RETURN_TYPE_IF_VALID(t) \ |
| 1787 | if (IS_TZO_CHAR(*cur)) { \ |
| 1788 | ret = _xmlSchemaParseTimeZone(&(dt->value.date), &cur); \ |
| 1789 | if (ret == 0) { \ |
| 1790 | if (*cur != 0) \ |
| 1791 | goto error; \ |
| 1792 | dt->type = t; \ |
| 1793 | goto done; \ |
| 1794 | } \ |
| 1795 | } |
| 1796 | |
| 1797 | if (dateTime == NULL) |
| 1798 | return -1; |
| 1799 | |
| 1800 | if (collapse) |
| 1801 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 1802 | |
| 1803 | if ((*cur != '-') && (*cur < '0') && (*cur > '9')) |
| 1804 | return 1; |
| 1805 | |
| 1806 | dt = xmlSchemaNewValue(XML_SCHEMAS_UNKNOWN); |
| 1807 | if (dt == NULL) |
| 1808 | return -1; |
| 1809 | |
| 1810 | if ((cur[0] == '-') && (cur[1] == '-')) { |
| 1811 | /* |
| 1812 | * It's an incomplete date (xs:gMonthDay, xs:gMonth or |
| 1813 | * xs:gDay) |
| 1814 | */ |
| 1815 | cur += 2; |
| 1816 | |
| 1817 | /* is it an xs:gDay? */ |
| 1818 | if (*cur == '-') { |
| 1819 | if (type == XML_SCHEMAS_GMONTH) |
| 1820 | goto error; |
| 1821 | ++cur; |
| 1822 | ret = _xmlSchemaParseGDay(&(dt->value.date), &cur); |
| 1823 | if (ret != 0) |
| 1824 | goto error; |
| 1825 | |
| 1826 | RETURN_TYPE_IF_VALID(XML_SCHEMAS_GDAY); |
| 1827 | |
| 1828 | goto error; |
| 1829 | } |
| 1830 | |
| 1831 | /* |
| 1832 | * it should be an xs:gMonthDay or xs:gMonth |
| 1833 | */ |
| 1834 | ret = _xmlSchemaParseGMonth(&(dt->value.date), &cur); |
| 1835 | if (ret != 0) |
no test coverage detected