From a71a69a619b16d2354b3109c0929facba39d02b3 Mon Sep 17 00:00:00 2001 From: Dario Date: Tue, 21 Jul 2020 11:16:21 +0200 Subject: [PATCH] change sorting mnemonic words for print out into case-insensitive --- src/cpp/Crypto/mnemonic.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cpp/Crypto/mnemonic.cpp b/src/cpp/Crypto/mnemonic.cpp index 6daff181d..a3b40d77d 100644 --- a/src/cpp/Crypto/mnemonic.cpp +++ b/src/cpp/Crypto/mnemonic.cpp @@ -270,6 +270,19 @@ std::string Mnemonic::getCompleteWordList() return result; } +// comparison, not case sensitive. +bool compare_nocase(const std::string& first, const std::string& second) +{ + unsigned int i = 0; + while ((i < first.length()) && (i < second.length())) + { + if (tolower(first[i]) < tolower(second[i])) return true; + else if (tolower(first[i]) > tolower(second[i])) return false; + ++i; + } + return (first.length() < second.length()); +} + std::string Mnemonic::getCompleteWordListSorted() { std::shared_lock _lock(mWorkingMutex); @@ -284,7 +297,7 @@ std::string Mnemonic::getCompleteWordListSorted() printf("missing word on %d\n", i); } } - words.sort(); + words.sort(compare_nocase); //std::string toReplaced[] = { "auml", "ouml", "uuml", "Auml", "Ouml", "Uuml", "szlig" }; Poco::RegularExpression toReplaced[] = { "ä", "ö", "ü", "Ä", "Ö", "Ü", "ß" };