llvm.org GIT mirror llvm / fb2674d
coding style cleanup git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82346 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 12 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
292292 /// ParseCStringVector - Break INPUT up wherever one or more
293293 /// whitespace characters are found, and store the resulting tokens in
294294 /// OUTPUT. The tokens stored in OUTPUT are dynamically allocated
295 /// using strdup (), so it is the caller's responsibility to free ()
295 /// using strdup(), so it is the caller's responsibility to free()
296296 /// them later.
297297 ///
298298 static void ParseCStringVector(std::vector &output,
300300 // Characters which will be treated as token separators:
301301 static const char *const delims = " \v\f\t\r\n";
302302
303 std::string work (input);
303 std::string work(input);
304304 // Skip past any delims at head of input string.
305 size_t pos = work.find_first_not_of (delims);
305 size_t pos = work.find_first_not_of(delims);
306306 // If the string consists entirely of delims, then exit early.
307307 if (pos == std::string::npos) return;
308308 // Otherwise, jump forward to beginning of first word.
309 work = work.substr (pos);
309 work = work.substr(pos);
310310 // Find position of first delimiter.
311 pos = work.find_first_of (delims);
311 pos = work.find_first_of(delims);
312312
313313 while (!work.empty() && pos != std::string::npos) {
314314 // Everything from 0 to POS is the next word to copy.
315 output.push_back (strdup (work.substr (0,pos).c_str ()));
315 output.push_back(strdup(work.substr(0,pos).c_str()));
316316 // Is there another word in the string?
317 size_t nextpos = work.find_first_not_of (delims, pos + 1);
317 size_t nextpos = work.find_first_not_of(delims, pos + 1);
318318 if (nextpos != std::string::npos) {
319319 // Yes? Then remove delims from beginning ...
320 work = work.substr (work.find_first_not_of (delims, pos + 1));
320 work = work.substr(work.find_first_not_of(delims, pos + 1));
321321 // and find the end of the word.
322 pos = work.find_first_of (delims);
322 pos = work.find_first_of(delims);
323323 } else {
324324 // No? (Remainder of string is delims.) End the loop.
325325 work = "";
329329
330330 // If `input' ended with non-delim char, then we'll get here with
331331 // the last word of `input' in `work'; copy it now.
332 if (!work.empty ()) {
333 output.push_back (strdup (work.c_str ()));
334 }
332 if (!work.empty())
333 output.push_back(strdup(work.c_str()));
335334 }
336335
337336 /// ParseEnvironmentOptions - An alternative entry point to the
364363 // Free all the strdup()ed strings.
365364 for (std::vector::iterator i = newArgv.begin(), e = newArgv.end();
366365 i != e; ++i)
367 free (*i);
366 free(*i);
368367 }
369368
370369