/* * PROGRAM: * Command-line pastebin * * AUTHOR: * Théophile BASTIAN (a.k.a. Tobast) * * CONTACT & WEBSITE: * http://tobast.fr/ (contact feature included) * error-report@tobast.fr (error reporting only) * * SHORT DESCRIPTION: * See first license line. * * LICENSE: * "Command-line pastebin" is a software designed to submit a "paste" on http://pastebin.com/ using a command-line tool * Copyright (C) 2011 Théophile BASTIAN * * 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 3 of the License, or * (at your option) any later version. * * This program 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 this program. If not, see http://www.gnu.org/licenses/gpl.txt. */ #include "ParameterRead.h" ParameterRead::ParameterRead(int i_argc, char** i_argv) : argc(i_argc), argv(i_argv) {} void ParameterRead::addValueParam(std::string i_valueparam) { /// adds a parameter name that requires a following value. valueparam.push_back(i_valueparam); } void ParameterRead::execute() { /// Processes the parameters rawcount=0; for(int i=1;i=rawcount) throw -1; std::ostringstream oss; oss << count; std::string label=PARAMETER_RAWBEGIN; label+=oss.str(); label+=PARAMETER_RAWEND; return paramMap[label]; } std::string ParameterRead::rawparam(std::string in) { /// returns the "raw" parameter, eg. "input" instead of "--input=file/path.txt" or "la" instead of "-la" size_t found=0; switch(getParamType(in)) { case SHORT_PARAM: in.erase(0,1); // erases the - break; case LONG_PARAM: in.erase(0,2); // erases the -- found=in.find('='); if(found!=std::string::npos) in.erase(in.begin()+found, in.end()); break; default: break; } return in; } ParameterRead::ParameterType ParameterRead::getParamType(std::string in) { /// Checks the parameter type (long parameter, eg "--param", short, eg. "-i", or other) if(in.size()>0 && in[0]=='-') { if(in.size()>1 && in[1]=='-') return LONG_PARAM; return SHORT_PARAM; } return OTHER_PARAM; } std::string ParameterRead::getParamValue(std::string in) { /// returns the value for a parameter of type LONG_PARAM, eg. "value" for "--parameter=value". if(getParamType(in)==LONG_PARAM) { size_t found=in.find("="); if(found!=std::string::npos) { in.erase(in.begin(), in.begin()+found+1); return in; } } return ""; } std::string ParameterRead::rawdatastr() { /// returns the "raw data string", which means the string line __RAWDATAx__ where x stands for "rawcount" std::ostringstream oss; oss << rawcount; return std::string(PARAMETER_RAWBEGIN)+oss.str()+PARAMETER_RAWEND; } std::string ParameterRead::charToString(char c) { /// string::string() does not accept "char". So, let's convert a char to a std::string ! std::string o=""; o+=c; return o; }