| 72 | #endif |
| 73 | |
| 74 | inline size_t get_sequence_length(const std::string &text, const std::string &locale, |
| 75 | bool is_multi_byte_character_support_enabled) { |
| 76 | if (!is_multi_byte_character_support_enabled) |
| 77 | return text.length(); |
| 78 | |
| 79 | #if defined(_WIN32) || defined(_WIN64) |
| 80 | (void)locale; // unused parameter |
| 81 | return (text.length() - std::count_if(text.begin(), text.end(), |
| 82 | [](char c) -> bool { return (c & 0xC0) == 0x80; })); |
| 83 | #elif defined(__unix__) || defined(__unix) || defined(__APPLE__) |
| 84 | auto result = get_wcswidth(text, locale, text.size()); |
| 85 | if (result >= 0) |
| 86 | return result; |
| 87 | else |
| 88 | return (text.length() - std::count_if(text.begin(), text.end(), |
| 89 | [](char c) -> bool { return (c & 0xC0) == 0x80; })); |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | } // namespace tabulate |
no test coverage detected