This will resize intArray to the size of lineParts. Returns true if all lineParts have been recognized as int. Content of intArray will be unknown if function returns false.
| 647 | // Returns true if all lineParts have been recognized as int. |
| 648 | // Content of intArray will be unknown if function returns false. |
| 649 | bool StringVecToIntVec(std::vector<int> &intArray, const StringUtils::StringVec &lineParts) |
| 650 | { |
| 651 | intArray.resize(lineParts.size()); |
| 652 | |
| 653 | for(unsigned int i=0; i<lineParts.size(); i++) |
| 654 | { |
| 655 | int x; |
| 656 | // When reading a vector of string as int, ints that |
| 657 | // are followed by other characters (ex. "3d") are |
| 658 | // not considered as int. |
| 659 | if ( !StringToInt(&x, lineParts[i].c_str(), true) ) |
| 660 | { |
| 661 | return false; |
| 662 | } |
| 663 | intArray[i] = x; |
| 664 | } |
| 665 | |
| 666 | return true; |
| 667 | } |
| 668 | |
| 669 | //////////////////////////////////////////////////////////////////////////// |
| 670 |