]> granicus.if.org Git - icinga2/commitdiff
Update use of String::Trim()
authorJean Flach <jean-marcel.flach@netways.de>
Thu, 27 Aug 2015 16:06:20 +0000 (18:06 +0200)
committerJean Flach <jean-marcel.flach@netways.de>
Thu, 27 Aug 2015 16:06:20 +0000 (18:06 +0200)
fixes #9704

lib/base/application.cpp
lib/cli/nodeutility.cpp
lib/cli/nodewizardcommand.cpp
lib/icinga/legacytimeperiod.cpp
lib/livestatus/livestatuslogutility.cpp
lib/livestatus/livestatusquery.cpp
lib/methods/pluginchecktask.cpp
lib/remote/configmoduleutility.cpp
lib/remote/httprequest.cpp
test/base-string.cpp

index 1363410b0bba3a9745498273d09f789f92e6e4c8..ec62ad083ebfd09d47838475ecdf78f63bba3afe 100644 (file)
@@ -502,9 +502,8 @@ static String UnameHelper(char type)
        pclose(fp);
 
        String result = msgbuf.str();
-       result.Trim();
 
-       return result;
+       return result.Trim();
 }
 
 int ReleaseHelper(std::string &result)
index 1cf3ce087a5ccf9681abce5a854c3169d2e391f9..b526bf717ad51dce820aa350c379010f582b500c 100644 (file)
@@ -271,23 +271,20 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoi
                Dictionary::Ptr my_master_endpoint = new Dictionary();
 
                if (tokens.size() > 1) {
-                       String host = tokens[1];
-                       host.Trim();
+                       String host = tokens[1].Trim();
 
                        if (!host.IsEmpty())
                                my_master_endpoint->Set("host", host);
                }
 
                if (tokens.size() > 2) {
-                       String port = tokens[2];
-                       port.Trim();
+                       String port = tokens[2].Trim();
 
                        if (!port.IsEmpty())
                                my_master_endpoint->Set("port", port);
                }
 
-               String cn = tokens[0];
-               cn.Trim();
+               String cn = tokens[0].Trim();
                my_master_endpoint->Set("__name", cn);
                my_master_endpoint->Set("__type", "Endpoint");
 
index 917d885761e3fb7b2408cab6f0c9af84952b9521..1a523b0cb02355b09886d898ddab2fec42cc0c11 100644 (file)
@@ -126,7 +126,7 @@ int NodeWizardCommand::Run(const boost::program_options::variables_map& vm, cons
                        answer = Utility::GetFQDN();
 
                String cn = answer;
-               cn.Trim();
+               cn = cn.Trim();
 
                std::cout << ConsoleColorTag(Console_Bold) << "Please specifiy the local zone name" << ConsoleColorTag(Console_Normal) << " [" << cn << "]: ";
 
@@ -137,7 +137,7 @@ int NodeWizardCommand::Run(const boost::program_options::variables_map& vm, cons
                        answer = cn;
 
                String local_zone = answer;
-               local_zone.Trim();
+               local_zone = local_zone.Trim();
 
                std::vector<std::string> endpoints;
 
@@ -159,7 +159,7 @@ wizard_endpoint_loop_start:
                }
 
                endpoint_buffer = answer;
-               endpoint_buffer.Trim();
+               endpoint_buffer = endpoint_buffer.Trim();
 
                std::cout << "Do you want to establish a connection to the master " << ConsoleColorTag(Console_Bold) << "from this node?" << ConsoleColorTag(Console_Normal) << " [Y/n]: ";
 
@@ -183,7 +183,8 @@ wizard_endpoint_loop_start:
                        }
 
                        String tmp = answer;
-                       tmp.Trim();
+                       tmp = tmp.Trim();
+
                        endpoint_buffer += "," + tmp;
                        master_endpoint_name = tmp; //store the endpoint name for later
 
@@ -197,8 +198,7 @@ wizard_endpoint_loop_start:
                        else
                                tmp = "5665";
 
-                       tmp.Trim();
-                       endpoint_buffer += "," + tmp;
+                       endpoint_buffer += "," + tmp.Trim();
                }
 
                endpoints.push_back(endpoint_buffer);
@@ -228,7 +228,7 @@ wizard_master_host:
                        goto wizard_master_host;
 
                String master_host = answer;
-               master_host.Trim();
+               master_host = master_host.Trim();
 
                std::cout << ConsoleColorTag(Console_Bold) << "Port" << ConsoleColorTag(Console_Normal) << " [5665]: ";
 
@@ -239,7 +239,7 @@ wizard_master_host:
                        answer = "5665";
 
                String master_port = answer;
-               master_port.Trim();
+               master_port = master_port.Trim();
 
                /* workaround for fetching the master cert */
                String pki_path = PkiUtility::GetPkiPath();
@@ -306,7 +306,7 @@ wizard_ticket:
                        goto wizard_ticket;
 
                String ticket = answer;
-               ticket.Trim();
+               ticket = ticket.Trim();
 
                Log(LogInformation, "cli")
                    << "Processing self-signed certificate request. Ticket '" << ticket << "'.\n";
@@ -339,7 +339,7 @@ wizard_ticket:
                boost::algorithm::to_lower(answer);
 
                String bind_host = answer;
-               bind_host.Trim();
+               bind_host = bind_host.Trim();
 
                std::cout << "Bind Port []: ";
 
@@ -347,7 +347,7 @@ wizard_ticket:
                boost::algorithm::to_lower(answer);
 
                String bind_port = answer;
-               bind_port.Trim();
+               bind_port = bind_port.Trim();
 
                std::cout << ConsoleColorTag(Console_Bold) << "Accept config from master?" << ConsoleColorTag(Console_Normal) << " [y/N]: ";
                std::getline(std::cin, answer);
@@ -449,7 +449,7 @@ wizard_ticket:
                        answer = Utility::GetFQDN();
 
                String cn = answer;
-               cn.Trim();
+               cn = cn.Trim();
 
                /* check whether the user wants to generate a new certificate or not */
                String existing_path = PkiUtility::GetPkiPath() + "/" + cn + ".crt";
@@ -481,7 +481,7 @@ wizard_ticket:
                boost::algorithm::to_lower(answer);
 
                String bind_host = answer;
-               bind_host.Trim();
+               bind_host = bind_host.Trim();
 
                std::cout << ConsoleColorTag(Console_Bold) << "Bind Port" << ConsoleColorTag(Console_Normal) << " []: ";
 
@@ -489,7 +489,7 @@ wizard_ticket:
                boost::algorithm::to_lower(answer);
 
                String bind_port = answer;
-               bind_port.Trim();
+               bind_port = bind_port.Trim();
 
                /* api feature is always enabled, check above */
                String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
index 5c7d64b5f4cd277e9caacf79369ca8ac372d0df1..aadcd7033fe297dc9318af722e26011b7a1af960 100644 (file)
@@ -269,8 +269,7 @@ void LegacyTimePeriod::ParseTimeRange(const String& timerange, tm *begin, tm *en
        size_t pos = def.FindFirstOf('/');
 
        if (pos != String::NPos) {
-               String strStride = def.SubStr(pos + 1);
-               strStride.Trim();
+               String strStride = def.SubStr(pos + 1).Trim();
                *stride = Convert::ToLong(strStride);
 
                /* Remove the stride parameter from the definition. */
@@ -283,11 +282,9 @@ void LegacyTimePeriod::ParseTimeRange(const String& timerange, tm *begin, tm *en
        pos = def.Find("- ");
 
        if (pos != String::NPos) {
-               String first = def.SubStr(0, pos);
-               first.Trim();
+               String first = def.SubStr(0, pos).Trim();
 
-               String second = def.SubStr(pos + 1);
-               second.Trim();
+               String second = def.SubStr(pos + 1).Trim();
 
                ParseTimeSpec(first, begin, NULL, reference);
 
index de70a2be7d3fa2f73a29f84c7f37061b540de1bc..f41a4404c8f3d0c81e241e157a3fc1742a3b9147 100644 (file)
@@ -136,11 +136,8 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
        size_t colon = text.FindFirstOf(':');
        size_t colon_offset = colon - 13;
 
-       String type = String(text.SubStr(13, colon_offset));
-       String options = String(text.SubStr(colon + 1));
-
-       type.Trim();
-       options.Trim();
+       String type = String(text.SubStr(13, colon_offset)).Trim();
+       String options = String(text.SubStr(colon + 1)).Trim();
 
        bag->Set("type", type);
        bag->Set("options", options);
index 863e18f932683c93ace6c59421045fd45cc202af..804261f1d198a93724bb3a1322a9b31ac2960119 100644 (file)
@@ -154,9 +154,7 @@ LivestatusQuery::LivestatusQuery(const std::vector<String>& lines, const String&
 
                //OutputFormat:json or OutputFormat: json
                if (line.GetLength() > col_index + 1)
-                       params = line.SubStr(col_index + 1);
-
-               params.Trim();
+                       params = line.SubStr(col_index + 1).Trim();
 
                if (header == "ResponseHeader")
                        m_ResponseHeader = params;
index ed39ed6c97d67e45b58258f808904856be397ba6..b63ff9ca32c1625c618eb0a6d6184daa76697dbb 100644 (file)
@@ -67,8 +67,8 @@ void PluginCheckTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, co
                    << pr.ExitStatus << ", output: " << pr.Output;
        }
 
-       String output = pr.Output;
-       output.Trim();
+       String output = pr.Output.Trim();
+
        std::pair<String, String> co = PluginUtility::ParseCheckOutput(output);
        cr->SetCommand(commandLine);
        cr->SetOutput(co.first);
index 15b1571285542b70489d9bbde44fb0c1b0bd23cb..964519ba08843a66bfb3f7e5f8f12f0786a79431 100644 (file)
@@ -243,14 +243,13 @@ String ConfigModuleUtility::GetActiveStage(const String& moduleName)
 
        String stage;
        std::getline(fp, stage.GetData());
-       stage.Trim();
 
        fp.close();
 
        if (fp.fail())
                return "";
 
-       return stage;
+       return stage.Trim();
 }
 
 
index 49bee4af5dd7706f14595f2a13cf805e5b8853cc..951169e9d8de3b34af332fb8197037c206064145 100644 (file)
@@ -82,11 +82,9 @@ bool HttpRequest::Parse(const Stream::Ptr& stream, StreamReadContext& src, bool
                                String::SizeType pos = line.FindFirstOf(":");
                                if (pos == String::NPos)
                                        BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid HTTP request"));
-                               String key = line.SubStr(0, pos);
-                               boost::algorithm::to_lower(key);
-                               key.Trim();
-                               String value = line.SubStr(pos + 1);
-                               value.Trim();
+                               String key = line.SubStr(0, pos).ToLower().Trim();
+
+                               String value = line.SubStr(pos + 1).Trim();
                                Headers->Set(key, value);
 
                                if (key == "x-http-method-override")
index ea70326c5201e1d5d79a611056015350e1a59a0a..2c87c21f8ede39d7d83be1055f34e6062e5a3dbb 100644 (file)
@@ -63,20 +63,16 @@ BOOST_AUTO_TEST_CASE(append)
 BOOST_AUTO_TEST_CASE(trim)
 {
        String s1 = "hello";
-       s1.Trim();
-       BOOST_CHECK(s1 == "hello");
+       BOOST_CHECK(s1.Trim() == "hello");
 
        String s2 = "  hello";
-       s2.Trim();
-       BOOST_CHECK(s2 == "hello");
+       BOOST_CHECK(s2.Trim() == "hello");
 
        String s3 = "hello ";
-       s3.Trim();
-       BOOST_CHECK(s3 == "hello");
+       BOOST_CHECK(s3.Trim() == "hello");
 
        String s4 = " hello ";
-       s4.Trim();
-       BOOST_CHECK(s4 == "hello");
+       BOOST_CHECK(s4.Trim() == "hello");
 }
 
 BOOST_AUTO_TEST_CASE(contains)