00001
00002 #ifndef STRFORMAT_H
00003 #define STRFORMAT_H
00004 #include <iostream>
00005 #include <string>
00006 #include <vector>
00007 #include <algorithm>
00008 #include <sstream>
00009 #include <set>
00010 #include <cstring>
00011
00012
00013
00014
00015
00016 using namespace std;
00018 int wc(const string &str);
00019 bool isnumber(const string &str);
00020
00021
00022 bool isnumber(const string &str, const string dc);
00023
00024 bool isupper(const string &str);
00025
00026
00027
00028 void upper(const char lo[], char *up);
00029 string getLower(const string &str);
00030 void strTolower(string &str);
00031 void strTolower(const string &str1, string &str2);
00032 void strToupper(string &str);
00033 string str2upper(const string &str);
00034 string lc(const string &str);
00035
00037 int cmp_nocase(const string &s1, const string &s2);
00038 bool intersect(vector<string> &s1, vector<string> &s2);
00039
00040
00041
00042
00046 string delall(const string& str, const char c);
00048 string delall(const string& str, const string& c);
00050 string deleteChr(const string &str, char c);
00051
00053 string tr(const string& str, char i, char o);
00055 void trim(string &str);
00057 void trimLeadingSpace(string &str);
00058
00060 void dlc(char a[]);
00061 void rmtsp(char a[]);
00062 void rmsp(char a[]);
00063
00064
00065 void singleSpace(string &str);
00067 void rmsp(const char a[], char b[]);
00068
00069 void rmdquote(char a[]);
00070 void rpldquote(char a[], const char r);
00071
00074 void newline(istream &ins);
00075
00077
00080 int getNumber(char *&ptr);
00082 int getInt(const string &str);
00084 vector<int> getAllInt(const string &str);
00085
00086
00087
00088
00092 int itoa(unsigned int n, char a[]);
00096 string itos(int n);
00100 template<class T> string toString(const T &val) {
00101 ostringstream ous;
00102 ous << val;
00103 return ous.str();
00104 }
00105
00110 template<class T> string anyToString(const T &val) {
00111 ostringstream ous;
00112 ous << val;
00113 return ous.str();
00114 }
00115 vector<int> extractInt(const string &str);
00116
00118
00128 int substr(const char ln[], int s, char sub[]);
00129
00134 int substr(const char ln[], int s, int f, char sub[]);
00135
00136 void firstwd(const char ln[], char sub[], char term=' ');
00137 string firstword(const string &str, const string &delim=" ,.()");
00138 void lastwd(const char ln[], char wd[], char sep = ' ');
00139 string lastword(const string &str, const string &delim=" ,.()");
00140
00143 string acronym(const string&str, int n=1);
00144 string acronymWithDigit(const string&str, int n=1);
00145
00146 string acronymWithTag(const string&str, int n=1);
00147
00148 void append(char *&head, const char *tail, int &len, int &maxlen,
00149 int incr);
00150
00151
00152
00153 void append(char *&head, const char *tail, int &len, int &maxlen);
00155
00156
00157
00163 vector<string> split(const string &str, const char sep='\t');
00164
00173 vector<string> split(const string &str, const char sep[]);
00174
00181
00182
00183
00184 vector<string> splitOneOf(const string &str, const string &delims = ",. \t");
00185
00192 vector<string> dissect(const string &str, const string &delims = ",. \t");
00193 set<string> digest2set(const string &str, const string &delims=",. \t");
00194
00200 pair<string,string> breakString(const string &str, const string &sep);
00201
00203
00204
00205 void writeSequence(const string &seq, ostream &ous, const int width=70);
00206
00207 int isName(char *n);
00208
00209
00210
00211
00213 bool codonIsStop(const string &codon);
00214
00215
00219 bool subseqIsStop(const string &seq, int i);
00220
00221
00222 #endif