]> git.donarmstrong.com Git - mothur.git/blobdiff - utilities.hpp
Added get.line command.
[mothur.git] / utilities.hpp
index bf7df2d6a96d5c294ef662ae2f1bd19bc11ff9b5..8f5009ffc4f0306a5da950e75a541aaa56cfb572 100644 (file)
@@ -33,6 +33,19 @@ inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
        if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
                throw BadConversion(s);
 }
+//**********************************************************************************************************************
+
+template<typename T>
+inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
+       istringstream i(s);
+       char c;
+       if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+       {
+               cout << "'" << s << "' is unable to be converted into an integer.\n";
+               return false;
+       } 
+       return true;
+}
 
 //**********************************************************************************************************************
 
@@ -285,8 +298,12 @@ inline void splitAtComma(string& prefix, string& suffix){
        try {
                prefix = suffix.substr(0,suffix.find_first_of(','));
                if ((suffix.find_first_of(',')+2) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
-                       suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
+                       suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
+                       string space = " ";
+                       while(suffix.at(0) == ' ')
+                               suffix = suffix.substr(1, suffix.length());
                }
+
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";