strformat.h

Go to the documentation of this file.
00001 // strformat.h
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 //this file is upcase.h 
00013 //namespace KZUtility {
00014 // causing too much trouble
00015 
00016 using namespace std;
00018 int wc(const string &str);  // word cound
00019 bool isnumber(const string &str); // all digits
00020 // whether is it a number with other chars
00021 // such as 1.2, 1,000, -1
00022 bool isnumber(const string &str, const string dc);
00023 // all of the char is in upper case
00024 bool isupper(const string &str);
00025 
00026 /*** Case transformation function 
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 /****** Modification  *****
00041  * replace, deletion
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[]); //deltes the last character
00061 void rmtsp(char a[]); //remove trailing white characters such as space and \n
00062 void rmsp(char a[]);
00063 //removes extra white-char (space, \t, and \n) from the string, so 
00064 //that only one space is left to separate words
00065 void singleSpace(string &str);
00067 void rmsp(const char a[], char b[]);
00068 //overloaded version.   input string a, output string b
00069 void rmdquote(char a[]); //removes double quote
00070 void rpldquote(char a[], const char r); //replace double quote with r
00071 
00074 void newline(istream &ins); //removes remaining character from input stream
00075 
00077 
00080 int getNumber(char *&ptr);  
00082 int getInt(const string &str);
00084 vector<int> getAllInt(const string &str);
00085 
00086 
00087 //get number from a pointer that is on the first digit of a string.  
00088 //The pointer will be advanced to the first non-digit character
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 // if taild with digit, then all will be added
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 //carefull, these are managed by new allocation
00151 //incr is the size increment, should be larger than strlen(tail)
00152 //if not the function will increase it automatically
00153 void append(char *&head, const char *tail, int &len, int &maxlen);
00155 
00156 /******** Digestion ***********/
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 //vector<string> split(const string &str); //default separator ( \t,.;)
00182 
00183 // will split the string use any one char in delims
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 //write sequence to ous line by line; seq is a long string
00205 void writeSequence(const string &seq, ostream &ous, const int width=70);
00206 
00207 int isName(char *n);
00208 //return 1 if the string is a scientific organism name such as Homo sapiens
00209 
00210 //}
00211 
00213 bool codonIsStop(const string &codon);
00214 //{ return codon == "TAA" || codon == "TAG" || codon == "TGA"; }
00215 //bool codonIsStop(char codon[3]) { return !strcmp(codon, "TAA") || !strcmp(codon, "TAG") || !strcmp(codon, "TGA"); }
00219 bool subseqIsStop(const string &seq, int i);
00220 //{ return seq.substr(i,3) == "TAA" || seq.substr(i,3) == "TAG" || seq.substr(i,3) == "TGA"; }
00221 
00222 #endif

Generated on Wed Aug 10 11:56:51 2011 for Softwares from Orpara by  doxygen 1.5.6