MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / joinWithoutEmptyParts

Method joinWithoutEmptyParts

Sources/Shared/Containers/StringView.cpp:1126–1158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1124 }
1125
1126 template<class T> String BasicStringView<T>::joinWithoutEmptyParts(const ArrayView<const StringView> strings) const {
1127 // Calculate size of the resulting string including delimiters
1128 const std::size_t delimiterSize = size();
1129 std::size_t totalSize = 0;
1130 for (const StringView string : strings) {
1131 if (string.empty()) continue;
1132 totalSize += string.size() + delimiterSize;
1133 }
1134 if (totalSize != 0) totalSize -= delimiterSize;
1135
1136 // Reserve memory for the resulting string
1137 String result{NoInit, totalSize};
1138
1139 // Join strings
1140 char* out = result.data();
1141 char* const end = out + totalSize;
1142 for (const StringView string : strings) {
1143 if (string.empty()) continue;
1144
1145 const std::size_t stringSize = string.size();
1146 // Apparently memcpy() can't be called with null pointers, even if size is zero. I call that bullying.
1147 if (stringSize != 0) {
1148 std::memcpy(out, string._data, stringSize);
1149 out += stringSize;
1150 }
1151 if (delimiterSize != 0 && out != end) {
1152 std::memcpy(out, _data, delimiterSize);
1153 out += delimiterSize;
1154 }
1155 }
1156
1157 return result;
1158 }
1159
1160 template<class T> String BasicStringView<T>::joinWithoutEmptyParts(const std::initializer_list<StringView> strings) const {
1161 return joinWithoutEmptyParts(arrayView(strings));

Callers

nothing calls this directly

Calls 5

sizeFunction · 0.85
arrayViewFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected