You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tubemq.apache.org by go...@apache.org on 2020/10/12 10:58:35 UTC
[incubator-tubemq] branch master updated: [TUBEMQ-373]Reduce the
redundant code of Utils::Split functions (#284)
This is an automated email from the ASF dual-hosted git repository.
gosonzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git
The following commit(s) were added to refs/heads/master by this push:
new 47e15cf [TUBEMQ-373]Reduce the redundant code of Utils::Split functions (#284)
47e15cf is described below
commit 47e15cf92b5f35fca534df58b28cb58a9cbd1387
Author: gosonzhang <46...@qq.com>
AuthorDate: Mon Oct 12 18:58:19 2020 +0800
[TUBEMQ-373]Reduce the redundant code of Utils::Split functions (#284)
Co-authored-by: gosonzhang <go...@tencent.com>
---
tubemq-client-twins/tubemq-client-cpp/src/utils.cc | 54 ++++------------------
1 file changed, 9 insertions(+), 45 deletions(-)
diff --git a/tubemq-client-twins/tubemq-client-cpp/src/utils.cc b/tubemq-client-twins/tubemq-client-cpp/src/utils.cc
index 81ef56e..69dfb6f 100644
--- a/tubemq-client-twins/tubemq-client-cpp/src/utils.cc
+++ b/tubemq-client-twins/tubemq-client-cpp/src/utils.cc
@@ -144,51 +144,15 @@ void Utils::Split(const string& source, vector<string>& result, const string& de
}
}
-void Utils::Split(const string& source, map<string, int32_t>& result, const string& delimiter_step1,
- const string& delimiter_step2) {
- string item_str;
- string key_str;
- string val_str;
- string::size_type pos1 = 0;
- string::size_type pos2 = 0;
- string::size_type pos3 = 0;
- if (!source.empty()) {
- pos1 = 0;
- pos2 = source.find(delimiter_step1);
- while (string::npos != pos2) {
- item_str = source.substr(pos1, pos2 - pos1);
- item_str = Utils::Trim(item_str);
- pos1 = pos2 + delimiter_step1.length();
- pos2 = source.find(delimiter_step1, pos1);
- if (item_str.empty()) {
- continue;
- }
- pos3 = item_str.find(delimiter_step2);
- if (string::npos == pos3) {
- continue;
- }
- key_str = item_str.substr(0, pos3);
- val_str = item_str.substr(pos3 + delimiter_step2.length());
- key_str = Utils::Trim(key_str);
- val_str = Utils::Trim(val_str);
- if (key_str.empty()) {
- continue;
- }
- result[key_str] = atoi(val_str.c_str());
- }
- if (pos1 != source.length()) {
- item_str = source.substr(pos1);
- item_str = Utils::Trim(item_str);
- pos3 = item_str.find(delimiter_step2);
- if (string::npos != pos3) {
- key_str = item_str.substr(0, pos3);
- val_str = item_str.substr(pos3 + delimiter_step2.length());
- key_str = Utils::Trim(key_str);
- val_str = Utils::Trim(val_str);
- if (!key_str.empty()) {
- result[key_str] = atoi(val_str.c_str());
- }
- }
+void Utils::Split(const string& source, map<string, int32_t>& result,
+ const string& delimiter_step1, const string& delimiter_step2) {
+ map<string, string> tmp_result;
+ map<string, string>::iterator it;
+ result.clear();
+ Split(source, tmp_result, delimiter_step1, delimiter_step2);
+ if (!tmp_result.empty()) {
+ for (it = tmp_result.begin(); it != tmp_result.end(); ++it) {
+ result[it->first] = atoi(it->second.c_str());
}
}
}