// ----------------------------------------------------------------------- // string_related.cc: General utility functions for manipulating strings // and input flags/parameters // ----------------------------------------------------------------------- // Copyright (C) 2006, Matthew Whiting, ATNF // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your // option) any later version. // // Duchamp is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License // along with Duchamp; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA // // Correspondence concerning Duchamp may be directed to: // Internet email: Matthew.Whiting [at] atnf.csiro.au // Postal address: Dr. Matthew Whiting // Australia Telescope National Facility, CSIRO // PO Box 76 // Epping NSW 1710 // AUSTRALIA // ----------------------------------------------------------------------- #include #include #include #include #include #include std::string makelower( std::string s ) { // "borrowed" from Matt Howlett's 'fred' std::string out = ""; for( size_t i=0; i> val; return val; } std::string readFilename(std::stringstream& ss) { std::string val; getline(ss,val); return removeLeadingBlanks(val); } bool readFlag(std::stringstream& ss) { std::string val; ss >> val; return boolify(val); } float readFval(std::stringstream& ss) { float val; ss >> val; return val; } int readIval(std::stringstream& ss) { int val; ss >> val; return val; } std::string removeLeadingBlanks(std::string s) { /** * All blank spaces from the start of the string to the first * non-blank-space character are deleted. */ int i=0; while(isspace(s[i])){ i++; } std::string newstring=""; for(unsigned int j=i;j(&size), sizeof size); outfile.write(str.c_str(), sizeof(char) * size); } std::string readStringFromBinaryFile(std::ifstream &infile) { size_t size; infile.read(reinterpret_cast(&size), sizeof size); char *cstr = new char[size]; infile.read(cstr, sizeof(char) * size); std::string str(cstr); str = str.substr(0,size); // don't know why this is necessary - if left out, sometimes get a string returned that is too long... delete cstr; return str; }