⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mstring.h

📁 一个SIP协议栈
💻 H
字号:
#ifndef __MSTRING_H__#define __MSTRING_H__/********************************************************************* $Id: mstring.h,v 1.2 1999/08/31 02:22:05 cullen Exp $ *********************************************************************  This library is free software; you can redistribute it and/or modify  it under the terms of the GNU Lesser General Public License as  published by the Free Software Foundation; either version 2 of the  License, or (at your option) any later version.  In addition to the  terms and conditions set forth in the GNU Lesser General Public  License, as a condition of using this library you are required to  grant to all users of this library or any implementation utilizing  or derived from this library a reciprocal, no cost, worldwide,  perpetual, non-exclusive, non-transferable, unrestricted license to  your claims of all patents and patent applications throughout the  world that are infringed by the library or any implementation  utilizing or derived from this library.  In the event you  redistribute this library or any implementation utilizing or derived  from this library, you must prominently display the foregoing terms  and conditions with the library or the implementation utilizing or  derived from this library.   In the event of a conflict of terms between the foregoing license  grant and the terms set forth in the GNU Lesser General Public  License, the foregoing terms and conditions shall be deemed to  govern.   This library 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  Lesser General Public License for more details.   You should have received a copy of the GNU Lesser General Public  License along with this library; if not; write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.   Copyright 1999 Vovida Networks, Inc.  All Rights Reserved. ********************************************************************* $Log: mstring.h,v $ Revision 1.2  1999/08/31 02:22:05  cullen updated header * mstring class - auxilliary string functions * Implemented by Maxim A.Shemanaryov **********************************************************************/#include <string>#include <vector>#include <stdlib.h>namespace std{    class mstring;    ///mstr_vector definition typedef vector<mstring> mstr_vector    typedef std::vector<mstring> mstr_vector;                                               /**mstring class provides basic parser methods as geting tokens,      *splitting, brackets processing an so on. */    class mstring : public string    {    public:        /** Separator flag sep_single or sep_multiple.         *         *  sep_single - Single mode - each symbol is a single separator          *                            (1,2,,,3,4 will be "1"  "2"  ""  ""  "3"  "4")         *  sep_multiple - Multiple mode - all symbols are one separator          *                            (1,,2,,3,,4 will be "1"  "2"  "3"  "4")          *  sep_whole_str - Whole string is a single separator         *                            (1,,2,3,,4 will be "1"  "2,3"  "4")          */        enum sep_flag        {            sep_single,            sep_multiple,            sep_whole_str        };	///Default Constructor        mstring() : string() {}	///Constructor from char*        mstring(const char *str) : string(str) {}	///Copy Constructor        mstring(const string &str) : string(str) {}        ///Assignment from int        mstring & assigni(int val, const char *format);        ///Assignment from double        mstring & assignd(double val, const char *format);        ///Assignment from int        mstring & operator = (int val) { return assigni(val, "%d"); }//        ///Assignment from double//        mstring & operator = (double val) { return assignd(val, "%.1f"); }        ///Conversion to int        operator int() const { return atoi(c_str()); }        ///Conversion to double        operator double() const { return atof(c_str()); }	///Trim left all the characters in s        mstring & ltrims(const string &s);	///Trim right all the characters in s        mstring & rtrims(const string &s);	///Trim left and right all the characters in s        mstring & atrims(const string &s)  { ltrims(s); return rtrims(s); }	///Trim left the character c        mstring & ltrimc(char c) { char s[2] = {c, 0}; return ltrims(s); }	///Trim right the character c        mstring & rtrimc(char c) { char s[2] = {c, 0}; return rtrims(s); }	///Trim left and right the character c        mstring & atrimc(char c) { char s[2] = {c, 0}; return atrims(s); }	///Trim left whitespaces        mstring & ltrim() { return ltrims("\t "); }	///Trim right whitespaces        mstring & rtrim() { return rtrims("\t "); }	///Trim left and right whitespaces        mstring & atrim() { return atrims("\t "); }        ///Left align to 'newlen' with filler 'fill'        mstring & toleft(unsigned newlen, char fill=' ', bool cut=false);        ///Right align to 'newlen' with filler 'fill'        mstring & toright(unsigned newlen, char fill=' ', bool cut=false);        ///Find and replace all the 'find_str' to 'repl_str'        unsigned  replace_all(const string &find_str, const string &repl_str);                /// Convert all tabs to spaces        mstring & tab2sp(unsigned tab_size=8);         ///Compare two strings. The function is provided just for convinience and uniformity        int compare(const string &str, size_type len=npos) const;        ///Compare two strings ignoring case. The function is provided just for convinience and uniformity        int comparei(const string &str, size_type len=npos) const;        ///Compare two strings. The function is provided just for convinience and uniformity        friend int compare(const mstring &str1, const mstring &str2, size_type len=npos)          { return str1.compare(str2, len); }        ///Compare two strings ignoring case. The function is provided just for convinience and uniformity        friend int comparei(const mstring &str1, const mstring &str2, size_type len=npos)         { return str1.comparei(str2, len); }        ///Insert pair-symb into the string        mstring & ins_pair(const string &chrset, char pair_symb);        ///Delete pair-symb from the string        mstring & del_pair(char pair_symb);        ///Insert escaped symbols into the string        mstring & ins_escaped(const string &chrset, char escaped_symb);        ///Delete escaped symbols from the string        mstring & del_escaped(char escaped_symb);        ///Add quote symbols into the string        mstring & quote(const string &q_start, const string &q_end);        //see mstring.cxx        size_type next_token(size_type start, const string &sep,                              const string &quote, char pair_chr=0,                              sep_flag flag=sep_multiple) const;        //see mstring.cxx        size_type token(string *dst, size_type start, const string &sep,                         const string &quote, char pair_chr=0,                         sep_flag flag=sep_multiple) const;        //see mstring.cxx        unsigned  split(mstr_vector *vec, const string &sep, const string &quote,                         char pair_chr=0, sep_flag flag=sep_multiple) const;        //see mstring.cxx        size_type brtok(string *dst, size_type *start, int *balance,                         char br_open, char br_close,                         const string &quote, char pair_chr=0) const;        //see mstring.cxx        bool      chkquote(const string &quote, char pair_chr=0) const;    };}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -