1 | #include "duckdb/common/types/string_type.hpp" |
2 | #include "duckdb/common/types/value.hpp" |
3 | #include "utf8proc_wrapper.hpp" |
4 | |
5 | namespace duckdb { |
6 | |
7 | void string_t::Verify() { |
8 | auto dataptr = GetData(); |
9 | (void)dataptr; |
10 | assert(dataptr); |
11 | |
12 | #ifdef DEBUG |
13 | auto utf_type = Utf8Proc::Analyze(dataptr, length); |
14 | assert(utf_type != UnicodeType::INVALID); |
15 | if (utf_type == UnicodeType::UNICODE) { |
16 | // check that the data is a valid NFC UTF8 string |
17 | auto normalized = Utf8Proc::Normalize(dataptr); |
18 | assert(strcmp(dataptr, normalized) == 0); |
19 | free(normalized); |
20 | } |
21 | #endif |
22 | |
23 | // verify that the string is null-terminated and that the length is correct |
24 | assert(strlen(dataptr) == length); |
25 | // verify that the prefix contains the first four characters of the string |
26 | for (idx_t i = 0; i < std::min((uint32_t)PREFIX_LENGTH, length); i++) { |
27 | assert(prefix[i] == dataptr[i]); |
28 | } |
29 | // verify that for strings with length < PREFIX_LENGTH, the rest of the prefix is zero |
30 | for (idx_t i = length; i < PREFIX_LENGTH; i++) { |
31 | assert(prefix[i] == '\0'); |
32 | } |
33 | } |
34 | |
35 | } // namespace duckdb |
36 | |