MCPcopy Create free account
hub / github.com/avast/retdec / isNiceString

Function isNiceString

src/utils/string.cpp:1007–1016  ·  view source on GitHub ↗

* @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. */

Source from the content-addressed store, hash-verified

1005* Empty string is never nice.
1006*/
1007bool 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.

Callers 4

getConstantMethod · 0.85
TEST_FFunction · 0.85

Calls 5

emptyMethod · 0.45
backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.68