Skip to content

Instantly share code, notes, and snippets.

@wiiaboo
Last active August 29, 2015 14:00
Show Gist options
  • Save wiiaboo/11323026 to your computer and use it in GitHub Desktop.
Save wiiaboo/11323026 to your computer and use it in GitHub Desktop.
diff --git a/src/base/string.cpp b/src/base/string.cpp
index 37ca780..fcbce24 100644
--- a/src/base/string.cpp
+++ b/src/base/string.cpp
@@ -772,9 +772,11 @@ int GetCommonCharIndex(wchar_t c) {
return -1;
}
-wchar_t GetMostCommonCharacter(const wstring& str) {
+wchar_t GetMostCommonCharacter(const wstring& str2) {
vector<std::pair<wchar_t, int>> char_map;
int char_index = -1;
+ std::wstring str = str2;
+ Trim(str);
for (size_t i = 0; i < str.length(); i++) {
if (!IsAlphanumeric(str[i])) {
@@ -798,8 +800,7 @@ wchar_t GetMostCommonCharacter(const wstring& str) {
char_index = 0;
for (auto it = char_map.begin(); it != char_map.end(); ++it) {
- if (it->second * 1.8f >= char_map.at(char_index).second &&
- GetCommonCharIndex(it->first) < GetCommonCharIndex(char_map.at(char_index).first)) {
+ if (it->second >= char_map.at(char_index).second) {
char_index = it - char_map.begin();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment