| 1 |
# utf8_checker requirements |
| 2 |
|
| 3 |
## Overview |
| 4 |
|
| 5 |
utf8_checker is module that provides basic validation whether a string is a UTF-8 string. |
| 6 |
|
| 7 |
## References |
| 8 |
|
| 9 |
[Unicode spec chapter 3.9](http://www.unicode.org/versions/Unicode9.0.0/ch03.pdf#G7404) |
| 10 |
|
| 11 |
## Exposed API |
| 12 |
|
| 13 |
```c |
| 14 |
MOCKABLE_FUNCTION(, bool, utf8_checker_is_valid_utf8, const unsigned char*, utf8_str, size_t, length); |
| 15 |
``` |
| 16 |
|
| 17 |
### utf8_checker_is_valid_utf8 |
| 18 |
|
| 19 |
```c |
| 20 |
extern bool utf8_checker_is_valid_utf8(const unsigned char* utf8_str, size_t length); |
| 21 |
``` |
| 22 |
|
| 23 |
**SRS_UTF8_CHECKER_01_001: [** `utf8_checker_is_valid_utf8` shall verify that the sequence of chars pointed to by `utf8_str` represent UTF-8 encoded codepoints. **]** |
| 24 |
|
| 25 |
**SRS_UTF8_CHECKER_01_005: [** On success it shall return true. **]** |
| 26 |
|
| 27 |
**SRS_UTF8_CHECKER_01_002: [** If `utf8_checker_is_valid_utf8` is called with NULL `utf8_str` it shall return false. **]** |
| 28 |
|
| 29 |
**SRS_UTF8_CHECKER_01_003: [** If `length` is 0, `utf8_checker_is_valid_utf8` shall consider `utf8_str` to be valid UTF-8 and return true. **]** |
| 30 |
|
| 31 |
### Relevant Unicode spec table |
| 32 |
|
| 33 |
Scalar Value First Byte Second Byte Third Byte Fourth Byte |
| 34 |
**SRS_UTF8_CHECKER_01_006: [** 00000000 0xxxxxxx 0xxxxxxx **]** |
| 35 |
|
| 36 |
**SRS_UTF8_CHECKER_01_007: [** 00000yyy yyxxxxxx 110yyyyy 10xxxxxx **]** |
| 37 |
|
| 38 |
**SRS_UTF8_CHECKER_01_008: [** zzzzyyyy yyxxxxxx 1110zzzz 10yyyyyy 10xxxxxx **]** |
| 39 |
|
| 40 |
**SRS_UTF8_CHECKER_01_009: [** 000uuuuu zzzzyyyy yyxxxxxx 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx **]** |