Mercurial > hg > orthanc
comparison OrthancFramework/Sources/Toolbox.cpp @ 5373:123a94dd57df
Toolbox::SplitString
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 17 Aug 2023 17:25:08 +0200 |
parents | 7cb1b851f5c8 |
children | daf4807631c5 |
comparison
equal
deleted
inserted
replaced
5372:94a52168480b | 5373:123a94dd57df |
---|---|
1033 boost::replace_all(result, "*", ".*"); | 1033 boost::replace_all(result, "*", ".*"); |
1034 | 1034 |
1035 return result; | 1035 return result; |
1036 } | 1036 } |
1037 | 1037 |
1038 static void TokenizeStringInternal(std::vector<std::string>& result, | |
1039 const std::string& value, | |
1040 char separator, | |
1041 bool includeEmptyStrings) | |
1042 { | |
1043 size_t countSeparators = 0; | |
1044 | |
1045 for (size_t i = 0; i < value.size(); i++) | |
1046 { | |
1047 if (value[i] == separator) | |
1048 { | |
1049 countSeparators++; | |
1050 } | |
1051 } | |
1052 | |
1053 result.clear(); | |
1054 result.reserve(countSeparators + 1); | |
1055 | |
1056 std::string currentItem; | |
1057 | |
1058 for (size_t i = 0; i < value.size(); i++) | |
1059 { | |
1060 if (value[i] == separator) | |
1061 { | |
1062 result.push_back(currentItem); | |
1063 currentItem.clear(); | |
1064 } | |
1065 else | |
1066 { | |
1067 currentItem.push_back(value[i]); | |
1068 } | |
1069 } | |
1070 | |
1071 if (includeEmptyStrings || !currentItem.empty()) | |
1072 { | |
1073 result.push_back(currentItem); | |
1074 } | |
1075 } | |
1076 | |
1038 | 1077 |
1039 void Toolbox::TokenizeString(std::vector<std::string>& result, | 1078 void Toolbox::TokenizeString(std::vector<std::string>& result, |
1040 const std::string& value, | 1079 const std::string& value, |
1041 char separator) | 1080 char separator) |
1042 { | 1081 { |
1043 size_t countSeparators = 0; | 1082 TokenizeStringInternal(result, value, separator, true); |
1044 | 1083 } |
1045 for (size_t i = 0; i < value.size(); i++) | 1084 |
1046 { | 1085 |
1047 if (value[i] == separator) | 1086 void Toolbox::SplitString(std::set<std::string>& result, |
1048 { | 1087 const std::string& value, |
1049 countSeparators++; | 1088 char separator) |
1050 } | 1089 { |
1051 } | |
1052 | |
1053 result.clear(); | 1090 result.clear(); |
1054 result.reserve(countSeparators + 1); | 1091 |
1055 | 1092 std::vector<std::string> temp; |
1056 std::string currentItem; | 1093 TokenizeStringInternal(temp, value, separator, false); |
1057 | 1094 for (size_t i = 0; i < temp.size(); ++i) |
1058 for (size_t i = 0; i < value.size(); i++) | 1095 { |
1059 { | 1096 result.insert(temp[i]); |
1060 if (value[i] == separator) | 1097 } |
1061 { | 1098 } |
1062 result.push_back(currentItem); | 1099 |
1063 currentItem.clear(); | 1100 |
1064 } | 1101 void Toolbox::SplitString(std::vector<std::string>& result, |
1065 else | 1102 const std::string& value, |
1066 { | 1103 char separator) |
1067 currentItem.push_back(value[i]); | 1104 { |
1068 } | 1105 TokenizeStringInternal(result, value, separator, false); |
1069 } | |
1070 | |
1071 result.push_back(currentItem); | |
1072 } | 1106 } |
1073 | 1107 |
1074 | 1108 |
1075 void Toolbox::JoinStrings(std::string& result, | 1109 void Toolbox::JoinStrings(std::string& result, |
1076 const std::set<std::string>& source, | 1110 const std::set<std::string>& source, |