MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / get_num_bytes

Function get_num_bytes

example/cacheHierarchy/fkYAML/node.hpp:1842–1862  ·  view source on GitHub ↗

@brief Query the number of UTF-8 character bytes with the first byte. @param first_byte The first byte of a UTF-8 character. @return The number of UTF-8 character bytes.

Source from the content-addressed store, hash-verified

1840/// @param first_byte The first byte of a UTF-8 character.
1841/// @return The number of UTF-8 character bytes.
1842inline uint32_t get_num_bytes(uint8_t first_byte) {
1843 // The first byte starts with 0b0XXX'XXXX -> 1-byte character
1844 if FK_YAML_LIKELY (first_byte < 0x80) {
1845 return 1;
1846 }
1847 // The first byte starts with 0b110X'XXXX -> 2-byte character
1848 if ((first_byte & 0xE0) == 0xC0) {
1849 return 2;
1850 }
1851 // The first byte starts with 0b1110'XXXX -> 3-byte character
1852 if ((first_byte & 0xF0) == 0xE0) {
1853 return 3;
1854 }
1855 // The first byte starts with 0b1111'0XXX -> 4-byte character
1856 if ((first_byte & 0xF8) == 0xF0) {
1857 return 4;
1858 }
1859
1860 // The first byte starts with 0b10XX'XXXX or 0b1111'1XXX -> invalid
1861 throw fkyaml::invalid_encoding("Invalid UTF-8 encoding.", {first_byte});
1862}
1863
1864/// @brief Checks if `byte` is a valid 1-byte UTF-8 character.
1865/// @param[in] byte The byte value.

Callers 5

check_scalar_contentMethod · 0.85
get_buffer_view_utf8Method · 0.85
get_buffer_viewMethod · 0.85
get_buffer_view_utf8Method · 0.85
get_buffer_view_utf8Method · 0.85

Calls 1

invalid_encodingClass · 0.85

Tested by

no test coverage detected