MCPcopy Create free account
hub / github.com/build2/build2 / reverse

Method reverse

libbuild2/variable.cxx:1829–1931  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1827 }
1828
1829 name value_traits<json_value>::
1830 reverse (const json_value& v)
1831 {
1832 switch (v.type)
1833 {
1834 case json_type::null:
1835 {
1836 // Note that here we cannot return empty (e.g., to be consistent with
1837 // other places) because we treat empty name (as opposed to empty
1838 // names) as string, not null (see to_json_value() above).
1839 //
1840 // Thankfully this version of reverse() is only used when json_value
1841 // representation is needed as part of a container. Which means in
1842 // "consumption" contexts (e.g., result of subscript) null will still
1843 // decay to empty.
1844 //
1845#if 1
1846 return name ("null");
1847#else
1848 return name ();
1849#endif
1850 }
1851 case json_type::boolean:
1852 {
1853 return name (v.boolean ? "true" : "false");
1854 }
1855 case json_type::signed_number:
1856 {
1857 return value_traits<int64_t>::reverse (v.signed_number);
1858 }
1859 case json_type::hexadecimal_signed_number:
1860 {
1861 return name (to_string (v.signed_number, 16));
1862 }
1863 case json_type::unsigned_number:
1864 {
1865 return value_traits<uint64_t>::reverse (v.unsigned_number);
1866 }
1867 case json_type::hexadecimal_unsigned_number:
1868 {
1869 return name (to_string (v.unsigned_number, 16));
1870 }
1871 case json_type::string:
1872 //
1873 // @@ Hm, it would be nice if this somehow got mapped to unquoted
1874 // string but still be round-trippable to JSON value. Perhaps via
1875 // the type hint idea? This is pretty bad. See also subscript we
1876 // hacked around this somewhat.
1877 //
1878 // Note that it may be tempting to fix this by only quoting strings
1879 // that would otherwise be mis-interpreted (null, true, all digits,
1880 // etc). But that would be worse: things would seem to work but
1881 // fall apart in the perhaps unlikely event of encountering one of
1882 // the problematic values. It is better to produce a consistent
1883 // result.
1884 //
1885 case json_type::array:
1886 case json_type::object:

Callers

nothing calls this directly

Calls 1

to_stringFunction · 0.70

Tested by

no test coverage detected