diff options
author | David Robillard <d@drobilla.net> | 2021-03-08 23:25:35 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-09 01:43:52 -0500 |
commit | 7b954f5667e82de1b64984a9aeb26b8ebb5cab81 (patch) | |
tree | 5668f80ce2dc7a52cf66bbe2f4e4429b18f09e08 /subprojects/exess/src | |
parent | c579186c5dd4e11bffddd353cef8978a66ef9c10 (diff) | |
download | serd1-meson.tar.gz serd1-meson.tar.bz2 serd1-meson.zip |
WIP: Validationserd1-meson
Diffstat (limited to 'subprojects/exess/src')
-rw-r--r-- | subprojects/exess/src/variant.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/subprojects/exess/src/variant.c b/subprojects/exess/src/variant.c index d8977abd..b32f27d6 100644 --- a/subprojects/exess/src/variant.c +++ b/subprojects/exess/src/variant.c @@ -275,6 +275,132 @@ exess_get_date(const ExessVariant* const variant) return variant->datatype == EXESS_DATE ? &variant->value.as_date : NULL; } +// Comparison + +int +exess_compare(const ExessVariant lhs, const ExessVariant rhs) +{ + if (lhs.datatype != rhs.datatype) { + return !lhs.datatype ? -1 + : !rhs.datatype ? 1 + : strcmp(exess_datatype_uri(lhs.datatype), + exess_datatype_uri(rhs.datatype)); + } + + switch (lhs.datatype) { + case EXESS_NOTHING: + return 0; + + case EXESS_BOOLEAN: + return lhs.value.as_bool < rhs.value.as_bool ? -1 + : lhs.value.as_bool > rhs.value.as_bool ? 1 + : 0; + + case EXESS_DECIMAL: + case EXESS_DOUBLE: + return lhs.value.as_double < rhs.value.as_double ? -1 + : lhs.value.as_double > rhs.value.as_double ? 1 + : 0; + + case EXESS_FLOAT: + return lhs.value.as_float < rhs.value.as_float ? -1 + : lhs.value.as_float > rhs.value.as_float ? 1 + : 0; + + case EXESS_INTEGER: + case EXESS_NON_POSITIVE_INTEGER: + case EXESS_NEGATIVE_INTEGER: + case EXESS_LONG: + return lhs.value.as_long < rhs.value.as_long ? -1 + : lhs.value.as_long > rhs.value.as_long ? 1 + : 0; + + case EXESS_INT: + return lhs.value.as_int < rhs.value.as_int ? -1 + : lhs.value.as_int > rhs.value.as_int ? 1 + : 0; + + case EXESS_SHORT: + return lhs.value.as_short < rhs.value.as_short ? -1 + : lhs.value.as_short > rhs.value.as_short ? 1 + : 0; + + case EXESS_BYTE: + return lhs.value.as_byte < rhs.value.as_byte ? -1 + : lhs.value.as_byte > rhs.value.as_byte ? 1 + : 0; + + case EXESS_NON_NEGATIVE_INTEGER: + case EXESS_ULONG: + return lhs.value.as_ulong < rhs.value.as_ulong ? -1 + : lhs.value.as_ulong > rhs.value.as_ulong ? 1 + : 0; + + case EXESS_UINT: + return lhs.value.as_uint < rhs.value.as_uint ? -1 + : lhs.value.as_uint > rhs.value.as_uint ? 1 + : 0; + + case EXESS_USHORT: + return lhs.value.as_ushort < rhs.value.as_ushort ? -1 + : lhs.value.as_ushort > rhs.value.as_ushort ? 1 + : 0; + + case EXESS_UBYTE: + return lhs.value.as_ubyte < rhs.value.as_ubyte ? -1 + : lhs.value.as_ubyte > rhs.value.as_ubyte ? 1 + : 0; + + case EXESS_POSITIVE_INTEGER: + return lhs.value.as_ulong < rhs.value.as_ulong ? -1 + : lhs.value.as_ulong > rhs.value.as_ulong ? 1 + : 0; + + case EXESS_DURATION: + return lhs.value.as_duration.months < rhs.value.as_duration.months ? -1 + : lhs.value.as_duration.months > rhs.value.as_duration.months ? 1 + : lhs.value.as_duration.seconds < rhs.value.as_duration.seconds ? -1 + : lhs.value.as_duration.seconds > rhs.value.as_duration.seconds ? 1 + : lhs.value.as_duration.nanoseconds < + rhs.value.as_duration.nanoseconds + ? -1 + : lhs.value.as_duration.nanoseconds > + rhs.value.as_duration.nanoseconds + ? 1 + : 0; + + case EXESS_DATETIME: + + case EXESS_TIME: + case EXESS_DATE: + case EXESS_HEX: + case EXESS_BASE64: + break; + } + + /* return exess_make_nothing(EXESS_UNSUPPORTED); */ + + /* if (lhs.datatype == EXESS_BOOL) { */ + /* return lhs.value.as_long < rhs.value.as_long ? -1 */ + /* : lhs.value.as_long > rhs.value.as_long ? 1 */ + /* : 0; */ + /* } */ + + /* if (lhs.datatype == EXESS_LONG) { */ + /* return lhs.value.as_long < rhs.value.as_long ? -1 */ + /* : lhs.value.as_long > rhs.value.as_long ? 1 */ + /* : 0; */ + /* } */ + + /* if (lhs.datatype == EXESS_ULONG) { */ + /* return lhs.value.as_long < rhs.value.as_long ? -1 */ + /* : lhs.value.as_long > rhs.value.as_long ? 1 */ + /* : 0; */ + /* } */ + + return 0; +} + // Reading and Writing ExessResult |