On 03/16/2010 03:05 PM, Denys Vlasenko wrote:
+static vector_string_t split(const std::string&s, char delim) +{
- std::stringstream ss(s);
- std::string item;
- std::vectorstd::string elems;
- while (std::getline(ss, item, delim))
- elems.push_back(item);
- return elems;
+}
Use of C++ streams usually adds on the order of 10k of code. We need to talk later whether we want to go entirely C. For now, personally I try to minimize usage of C++ constructs. Here, looks like you can as easily perform splitting using, say, loop with strchr('\n') inside.
Agreed. I rewrote this routine to use strtok_r.
- /* Get the analyzer from the crash. */
- map_crash_data_t::const_iterator analyzerit = crash_data.find(FILENAME_ANALYZER);
- if (analyzerit == crash_data.end())
- return result; /* No analyzer found in the crash data. */
- std::string analyzer = analyzerit->second[CD_CONTENT];
there is a helper for this which also would make sure [CD_CONTENT] index is not out of range (i.e. it won't SEGV if it is not there, unlike code above):
const char *analyser = get_crash_data_item_content_or_NULL(crash_data, FILENAME_ANALYZER); if (!analyzer) return result;
The code has been modified to take advantage of this function.