* @brief Does the provided string seem nice, i.e ratio of printable characters * and escape sequences in the string is at least @p minRatio. * * @param str String to check. * @param minRatio Minimum ratio of printable characters. * * @return @c True if the string seems nice, @c false otherwise. * * Empty string is never nice. */
| 1005 | * Empty string is never nice. |
| 1006 | */ |
| 1007 | bool isNiceString(const std::string &str, double minRatio) { |
| 1008 | assert(0.0 <= minRatio && minRatio <= 1.0); |
| 1009 | |
| 1010 | std::string s = str; |
| 1011 | if (!s.empty() && s.back() == '\00') |
| 1012 | s.pop_back(); |
| 1013 | |
| 1014 | auto niceCharCount = std::count_if(s.begin(), s.end(), isNiceCharacter); |
| 1015 | return !s.empty() && (niceCharCount) >= (s.size() * minRatio); |
| 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * @return @c True if character @a c is a nice ASCII wide character. |