diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-06-08 01:22:43 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-06-08 01:22:43 +0300 |
commit | 34a83475636164cf43551d9ec83ec30da5a7e7f2 (patch) | |
tree | c6b3e22f789422e06a96c2ca87dd94fc61eb1dd1 /src/utils | |
parent | af4fcff19a986990d58c50c62bc498690c8293b8 (diff) | |
download | mv-34a83475636164cf43551d9ec83ec30da5a7e7f2.tar.gz mv-34a83475636164cf43551d9ec83ec30da5a7e7f2.tar.bz2 mv-34a83475636164cf43551d9ec83ec30da5a7e7f2.tar.xz mv-34a83475636164cf43551d9ec83ec30da5a7e7f2.zip |
Replace size() to empty() where is possible
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/chatutils_unittest.cc | 2 | ||||
-rw-r--r-- | src/utils/parameters_unittest.cc | 10 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 1 | ||||
-rw-r--r-- | src/utils/stringutils_unittest.cc | 92 | ||||
-rw-r--r-- | src/utils/translation/poparser_unittest.cc | 2 | ||||
-rw-r--r-- | src/utils/xml_unittest.cc | 2 |
6 files changed, 54 insertions, 55 deletions
diff --git a/src/utils/chatutils_unittest.cc b/src/utils/chatutils_unittest.cc index bc2013e82..f6e608556 100644 --- a/src/utils/chatutils_unittest.cc +++ b/src/utils/chatutils_unittest.cc @@ -103,7 +103,7 @@ TEST_CASE("chatutils replaceVars", "") SECTION("empty") { replaceVars(str); - REQUIRE(str == ""); + REQUIRE(str.empty()); str = "test line"; replaceVars(str); diff --git a/src/utils/parameters_unittest.cc b/src/utils/parameters_unittest.cc index 192249a12..7739b62bd 100644 --- a/src/utils/parameters_unittest.cc +++ b/src/utils/parameters_unittest.cc @@ -28,7 +28,7 @@ TEST_CASE("parameters basic 1", "") { StringVect pars; REQUIRE(splitParameters(pars, "", ",", '\"') == true); - REQUIRE(pars.size() == 0); + REQUIRE(pars.empty()); } TEST_CASE("parameters basic 2", "") @@ -45,7 +45,7 @@ TEST_CASE("parameters basic 3", "") { StringVect pars; REQUIRE(splitParameters(pars, ", ,,,", ",", '\"') == true); - REQUIRE(pars.size() == 0); + REQUIRE(pars.empty()); } TEST_CASE("parameters basic 4", "") @@ -99,7 +99,7 @@ TEST_CASE("parameters quote 2", "") StringVect pars; REQUIRE(splitParameters(pars, "\"\",,two, tree", ",", '\"') == true); REQUIRE(pars.size() == 3); - REQUIRE(pars[0] == ""); + REQUIRE(pars[0].empty()); REQUIRE(pars[1] == "two"); REQUIRE(pars[2] == "tree"); } @@ -315,7 +315,7 @@ TEST_CASE("parameters broken 2", "") { StringVect pars; REQUIRE(splitParameters(pars, ",", ",", '\"') == true); - REQUIRE(pars.size() == 0); + REQUIRE(pars.empty()); } TEST_CASE("parameters broken 3", "") @@ -323,5 +323,5 @@ TEST_CASE("parameters broken 3", "") StringVect pars; REQUIRE(splitParameters(pars, ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", ",", '\"') == true); - REQUIRE(pars.size() == 0); + REQUIRE(pars.empty()); } diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 0dfd3b597..d21702ed1 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -336,7 +336,6 @@ void getSafeUtf8String(std::string text, char *const buf) memcpy(buf, text.c_str(), sz); memset(buf + sz, 0, UTF8_MAX_SIZE); } - return; } std::string getFileName(const std::string &path) diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc index 57d4336e0..a6c187ac5 100644 --- a/src/utils/stringutils_unittest.cc +++ b/src/utils/stringutils_unittest.cc @@ -53,7 +53,7 @@ TEST_CASE("stringuntils trim 1", "") trim(str)); str = ""; - REQUIRE("" == trim(str)); + REQUIRE(trim(str).empty()); } TEST_CASE("stringuntils toLower 1", "") @@ -71,7 +71,7 @@ TEST_CASE("stringuntils toLower 1", "") toLower(str)); str = ""; - REQUIRE("" == toLower(str)); + REQUIRE(toLower(str).empty()); } TEST_CASE("stringuntils toUpper 1", "") @@ -89,7 +89,7 @@ TEST_CASE("stringuntils toUpper 1", "") toUpper(str)); str = ""; - REQUIRE("" == toUpper(str)); + REQUIRE(toUpper(str).empty()); } TEST_CASE("stringuntils atox 1", "") @@ -226,12 +226,12 @@ TEST_CASE("stringuntils removeToken 1", "") { std::string str = ""; - REQUIRE(removeToken(str, " ") == ""); - REQUIRE(str == ""); + REQUIRE(removeToken(str, " ").empty()); + REQUIRE(str.empty()); str = "test"; - REQUIRE(removeToken(str, " ") == ""); - REQUIRE(str == ""); + REQUIRE(removeToken(str, " ").empty()); + REQUIRE(str.empty()); str = "test line"; REQUIRE(removeToken(str, " ") == "line"); @@ -242,12 +242,12 @@ TEST_CASE("stringuntils removeToken 1", "") REQUIRE(str == "line"); str = "test line"; - REQUIRE(removeToken(str, ",") == ""); - REQUIRE(str == ""); + REQUIRE(removeToken(str, ",").empty()); + REQUIRE(str.empty()); str = ",line"; - REQUIRE(removeToken(str, ",") == ""); - REQUIRE(str == ""); + REQUIRE(removeToken(str, ",").empty()); + REQUIRE(str.empty()); } TEST_CASE("stringuntils strprintf 1", "") @@ -278,10 +278,10 @@ TEST_CASE("stringuntils toString 2", "") TEST_CASE("stringuntils removeColors 1", "") { - REQUIRE("" == removeColors("")); + REQUIRE(removeColors("").empty()); REQUIRE("#" == removeColors("#")); REQUIRE("##" == removeColors("##")); - REQUIRE("" == removeColors("##1")); + REQUIRE(removeColors("##1").empty()); REQUIRE("2" == removeColors("##12")); REQUIRE("1##" == removeColors("1##")); REQUIRE("1" == removeColors("1##2")); @@ -329,7 +329,7 @@ TEST_CASE("stringuntils findSameSubstring", "") std::string str1 = ""; std::string str2 = ""; - REQUIRE("" == findSameSubstring("", "")); + REQUIRE(findSameSubstring("", "").empty()); str1 = "test line"; str2 = "test line"; @@ -341,7 +341,7 @@ TEST_CASE("stringuntils findSameSubstring", "") str1 = "test li"; str2 = "est li"; - REQUIRE("" == findSameSubstring(str1, str2)); + REQUIRE(findSameSubstring(str1, str2).empty()); } TEST_CASE("stringuntils findSameSubstringI", "") @@ -349,7 +349,7 @@ TEST_CASE("stringuntils findSameSubstringI", "") std::string str1 = ""; std::string str2 = ""; - REQUIRE("" == findSameSubstringI("", "")); + REQUIRE(findSameSubstringI("", "").empty()); str1 = "tEst line"; str2 = "tesT line"; @@ -365,7 +365,7 @@ TEST_CASE("stringuntils findSameSubstringI", "") str1 = "teSt li"; str2 = "est li"; - REQUIRE("" == findSameSubstringI(str1, str2)); + REQUIRE(findSameSubstringI(str1, str2).empty()); } TEST_CASE("stringuntils findI 1", "") @@ -396,7 +396,7 @@ TEST_CASE("stringuntils encodeStr 1", "") std::string str = encodeStr(10, 1); REQUIRE(10 == decodeStr(str)); - str = ""; + str.clear(); REQUIRE(0 == decodeStr(str)); str = encodeStr(10, 2); @@ -411,7 +411,7 @@ TEST_CASE("stringuntils encodeStr 1", "") TEST_CASE("stringuntils extractNameFromSprite 1", "") { - REQUIRE("" == extractNameFromSprite("")); + REQUIRE(extractNameFromSprite("").empty()); REQUIRE("test" == extractNameFromSprite("test")); REQUIRE("test" == extractNameFromSprite("test.qwe")); REQUIRE("line" == extractNameFromSprite("test/line.zzz")); @@ -422,7 +422,7 @@ TEST_CASE("stringuntils extractNameFromSprite 1", "") TEST_CASE("stringuntils removeSpriteIndex 1", "") { - REQUIRE("" == removeSpriteIndex("")); + REQUIRE(removeSpriteIndex("").empty()); REQUIRE("test" == removeSpriteIndex("test")); REQUIRE("test" == removeSpriteIndex("test[1]")); REQUIRE("line" == removeSpriteIndex("test/line[12]")); @@ -504,22 +504,22 @@ TEST_CASE("stringutils getSafeUtf8String 2", "") TEST_CASE("stringuntils getFileName 1", "") { - REQUIRE("" == getFileName("")); + REQUIRE(getFileName("").empty()); REQUIRE("file" == getFileName("file")); REQUIRE("file" == getFileName("test/file1\\file")); REQUIRE("file" == getFileName("test\\file1/file")); - REQUIRE("" == getFileName("file/")); + REQUIRE(getFileName("file/").empty()); REQUIRE("file" == getFileName("/file")); } TEST_CASE("stringuntils getFileDir 1", "") { - REQUIRE("" == getFileDir("")); + REQUIRE(getFileDir("").empty()); REQUIRE("file" == getFileDir("file")); REQUIRE("test/file1" == getFileDir("test/file1\\file")); REQUIRE("test\\file1" == getFileDir("test\\file1/file")); REQUIRE("file" == getFileDir("file/")); - REQUIRE("" == getFileDir("/file")); + REQUIRE(getFileDir("/file").empty()); } TEST_CASE("stringuntils replaceAll 1", "") @@ -528,7 +528,7 @@ TEST_CASE("stringuntils replaceAll 1", "") std::string str2 = ""; std::string str3 = ""; - REQUIRE("" == replaceAll(str1, str2, str3)); + REQUIRE(replaceAll(str1, str2, str3).empty()); str1 = "this is test line"; str2 = ""; @@ -551,7 +551,7 @@ TEST_CASE("stringuntils replaceRecursiveAll 1", "") std::string str; str = ""; replaceRecursiveAll(str, "line", '.'); - REQUIRE(str == ""); + REQUIRE(str.empty()); str = "test line"; replaceRecursiveAll(str, "line", '.'); REQUIRE(str == "test ."); @@ -891,7 +891,7 @@ TEST_CASE("stringuntils replaceSpecialChars 1", "") str = ""; replaceSpecialChars(str); - REQUIRE("" == str); + REQUIRE(str.empty()); str = "test"; replaceSpecialChars(str); @@ -936,7 +936,7 @@ TEST_CASE("stringuntils replaceSpecialChars 1", "") TEST_CASE("stringuntils normalize 1", "") { - REQUIRE(normalize("") == ""); + REQUIRE(normalize("").empty()); REQUIRE(normalize("test") == "test"); REQUIRE(normalize("Test") == "test"); REQUIRE(normalize(" test line") == "test line"); @@ -947,7 +947,7 @@ TEST_CASE("stringuntils normalize 1", "") TEST_CASE("stringuntils combineDye 1", "") { - REQUIRE("" == combineDye("", "")); + REQUIRE(combineDye("", "").empty()); REQUIRE("test" == combineDye("test", "")); REQUIRE("|line" == combineDye("", "line")); REQUIRE("test|line" == combineDye("test", "line")); @@ -958,10 +958,10 @@ TEST_CASE("stringuntils combineDye 1", "") TEST_CASE("stringuntils combineDye 2", "") { - REQUIRE("" == combineDye2("", "")); + REQUIRE(combineDye2("", "").empty()); REQUIRE("test" == combineDye2("test", "")); REQUIRE("test" == combineDye2("test", "W")); - REQUIRE("" == combineDye2("", "line")); + REQUIRE(combineDye2("", "line").empty()); REQUIRE("test.xml" == combineDye2("test.xml", "123")); REQUIRE("test.xml|#43413d,59544f,7a706c" == combineDye2("test.xml|#43413d,59544f,7a706c", "")); @@ -973,9 +973,9 @@ TEST_CASE("stringuntils combineDye 2", "") TEST_CASE("stringuntils combineDye 3", "") { - REQUIRE("" == combineDye3("", "")); + REQUIRE(combineDye3("", "").empty()); REQUIRE("test" == combineDye3("test", "")); - REQUIRE("" == combineDye3("", "line")); + REQUIRE(combineDye3("", "line").empty()); REQUIRE("test.xml|123" == combineDye3("test.xml", "123")); REQUIRE("test.xml|#43413d,59544f,7a706c" == combineDye3("test.xml|#43413d,59544f,7a706c", "")); @@ -988,9 +988,9 @@ TEST_CASE("stringuntils combineDye 3", "") TEST_CASE("stringuntils packList 1", "") { std::list <std::string> list; - REQUIRE("" == packList(list)); + REQUIRE(packList(list).empty()); - list.push_back(""); + list.push_back(std::string()); REQUIRE("|" == packList(list)); list.clear(); @@ -1014,7 +1014,7 @@ TEST_CASE("stringuntils stringToHexPath 1", "") std::string str; str = ""; - REQUIRE("" == stringToHexPath(str)); + REQUIRE(stringToHexPath(str).empty()); str = "a"; REQUIRE("%61/" == stringToHexPath(str)); @@ -1036,7 +1036,7 @@ TEST_CASE("stringuntils deleteCharLeft 1", "") str = ""; deleteCharLeft(str, nullptr); - REQUIRE("" == str); + REQUIRE(str.empty()); str = "test line"; pos = 4; @@ -1091,7 +1091,7 @@ TEST_CASE("stringuntils findCutLast 1", "") str = ""; REQUIRE(findCutLast(str, "")); - REQUIRE("" == str); + REQUIRE(str.empty()); str = "test line"; REQUIRE(findCutLast(str, "line")); @@ -1112,7 +1112,7 @@ TEST_CASE("stringuntils CutLast 1", "") str = ""; cutLast(str, ""); - REQUIRE("" == str); + REQUIRE(str.empty()); str = "test line"; cutLast(str, "line"); @@ -1133,7 +1133,7 @@ TEST_CASE("stringuntils findCutFirst 1", "") str = ""; REQUIRE(findCutFirst(str, "")); - REQUIRE("" == str); + REQUIRE(str.empty()); str = "test line"; REQUIRE(findCutFirst(str, "test")); @@ -1154,7 +1154,7 @@ TEST_CASE("stringuntils cutFirst 1", "") str = ""; cutFirst(str, ""); - REQUIRE("" == str); + REQUIRE(str.empty()); str = "test line"; cutFirst(str, "test"); @@ -1174,10 +1174,10 @@ TEST_CASE("stringuntils removeProtocol 1", "") std::string str; str = ""; - REQUIRE("" == removeProtocol(str)); + REQUIRE(removeProtocol(str).empty()); str = "http://"; - REQUIRE("" == removeProtocol(str)); + REQUIRE(removeProtocol(str).empty()); str = "http://test"; REQUIRE("test" == removeProtocol(str)); @@ -1260,7 +1260,7 @@ TEST_CASE("stringuntils sanitizePath", "") const std::string sep = dirSeparator; path = ""; sanitizePath(path); - REQUIRE(path == ""); + REQUIRE(path.empty()); path = "/"; sanitizePath(path); REQUIRE(path == dirSeparator); @@ -1437,7 +1437,7 @@ TEST_CASE("stringuntils secureChatCommand", "") { std::string str; secureChatCommand(str); - REQUIRE(str == ""); + REQUIRE(str.empty()); str = "test"; secureChatCommand(str); REQUIRE(str == "test"); @@ -1522,7 +1522,7 @@ TEST_CASE("stringuntils replaceItemLinks", "") str = ""; replaceItemLinks(str); - REQUIRE(str == ""); + REQUIRE(str.empty()); str = "[]"; replaceItemLinks(str); diff --git a/src/utils/translation/poparser_unittest.cc b/src/utils/translation/poparser_unittest.cc index 82418e09d..54dccb85b 100644 --- a/src/utils/translation/poparser_unittest.cc +++ b/src/utils/translation/poparser_unittest.cc @@ -98,7 +98,7 @@ TEST_CASE("PoParser tests", "PoParser") REQUIRE(dict != nullptr); REQUIRE(dict->getMap() != nullptr); - REQUIRE(dict->getMap()->size() == 0); + REQUIRE(dict->getMap()->empty()); delete parser; delete dict; diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc index 00ec2b5ff..1d4aa52cc 100644 --- a/src/utils/xml_unittest.cc +++ b/src/utils/xml_unittest.cc @@ -228,7 +228,7 @@ TEST_CASE("xml doc", "") REQUIRE(XmlHasProp(node, "option123") == false); REQUIRE(XML::getProperty(node, "name", "") == "padding"); REQUIRE(XML::langProperty(node, "name", "") == "padding"); - REQUIRE(XML::langProperty(node, "name123", "") == ""); + REQUIRE(XML::langProperty(node, "name123", "").empty()); REQUIRE(XML::getProperty(node, "value", 0) == 1); REQUIRE(XML::getProperty(node, "value123", -1) == -1); REQUIRE(XML::getBoolProperty(node, "value", true) == true); |