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

📄 string.htm

📁 自编的一个String类
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<html><head><meta http-equiv="Content-Language" content="en-nz"><meta name="GENERATOR" content="Microsoft FrontPage 5.0"><meta name="ProgId" content="FrontPage.Editor.Document"><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><meta name="description" content="C++ string library"><meta name="keywords" content="string, c++, cplusplus"><title>String</title><link rel="stylesheet" type="text/css" href="rbd.css"></head><body><h1><a name="top"></a>Character string manipulation library</h1><p><i>July, 2001</i><ul>  <li><a href="#intro">Introduction</a><ul>      <li><a href="#files">Files in this package</a></li>      <li><a href="#testing">Testing and getting started</a></li>    </ul>  </li>  <li><a href="#public">The public member functions</a><ul>      <li><a href="#static">Static variable</a></li>      <li><a href="#construct">Constructors, destructor, operator=</a></li>      <li><a href="#storage">Storage control</a></li>      <li><a href="#character">Character access</a></li>      <li><a href="#editing">The <em>editing</em> functions</a></li>      <li><a href="#data">Pointer to data</a></li>      <li><a href="#find">The <em>find</em> functions</a></li>      <li><a href="#substring">The <em>substring</em> function</a></li>      <li><a href="#compare">The <em>compare</em> functions</a></li>    </ul>  </li>  <li><a href="#binary">The binary String functions</a></li>  <li><a href="#policies">The policies</a><ul>      <li><a href="#realloc">Reallocation policy</a></li>      <li><a href="#plus">Policy on operator+, operator+= and append</a></li>    </ul>  </li>  <li><a href="#functions">String functions</a></li>  <li><a href="#command">Command line class</a></li>  <li><a href="#todo">To do list</a></li>  <li><a href="#history">History</a><ul>      <li><a href="#Aug98">August, 1998 changes</a></li>      <li><a href="#Sep98">September, 1998 changes</a></li>      <li><a href="#Feb01">July, 2001 changes</a></li>    </ul>  </li>  <li><a HREF="ol_doc.htm">To online documentation page</a></li></ul><h2><a name="intro"></a>Introduction</h2><p>This is a string library that is intended to be compatible with the <em>class string</em>library in the C++ standard. My version is for strings of characters of type <em>char</em>only. </p><p>It is for people who do not have access to an official version of the string library orwish to use a version without templates. </p><p>It follows the standard class string as I understand it, except that a few functionsthat are relevant only to the template version are omitted, and all the functions involvingiterators are omitted. </p><p>I use the name <em>String</em> rather than <em>string</em> to prevent conflicts withother string libraries (as in BC 5.0). </p><p>I claim copyright for this program. The initial version was taken from Tony Hansen'sbook <em>The C++ answer book</em>, but very little of Tony's code remains. </p><p>Permission is granted to use this. If you distribute it or put it on your website please include a link to my site. I take no responsibility forerrors, omissions etc, but please tell me about them. </p><p>This library links into my exception package. You need to edit the file include.h todetermine whether to use simulated exceptions or compiler supported exceptions or simplyto disable exceptions. More information on the exception package is given in thedocumentation for my matrix library, <a href="ol_doc.htm">newmat10</a>. </p><p>The package uses a limited form of <em>copy-on-write</em> (see Tony Hansen's book formore details) and also attempts to avoid repeated reallocation of the string storageduring a multiple sum. This results in some saving in space and time for some operationsat the expense of an increase in the complexity of the program and an increase in the timeused by a few operations. As with newmat it is still an open question whether the extracomplexity is really warranted. Or under what circumstances it is really warranted. </p><p>This package includes <a href="#functions">simple functions</a> for manipulating strings and a <a href="#command">class</a> for extracting information from the command line.</p><p>It also includes  class libraries to help <a href="format.htm">format numerical output</a> and to <a href="gstring.htm">edit ASCII files</a>. They documented in separate files. </p><h3><a name="files"></a>Files in this package</h3><p>The following files are included in this package </p><div align="left"><table border="0" width="100%" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0">  <tr>    <td width="33%">str.h</td>    <td width="67%">header file for the string library</td>  </tr>  <tr>    <td width="33%">str.cpp</td>    <td width="67%">function bodies</td>  </tr>  <tr>    <td width="33%">str_fns.h</td>    <td width="67%">header file for string functions</td>  </tr>  <tr>    <td width="33%">str_fns.cpp</td>    <td width="67%">string functions bodies</td>  </tr>  <tr>    <td width="33%">commline.h</td>    <td width="67%">command line class header</td>  </tr>  <tr>    <td width="33%">commline.cpp</td>    <td width="67%">command line bodies</td>  </tr>  <tr>    <td width="33%">boolean.h</td>    <td width="67%">simulation of the standard Boolean type</td>  </tr>  <tr>    <td width="33%">myexcept.h</td>    <td width="67%">header for the exceptions simulator</td>  </tr>  <tr>    <td width="33%">myexcept.cpp</td>    <td width="67%">bodies for the exceptions simulator</td>  </tr>  <tr>    <td width="33%">include.h</td>    <td width="67%">options header file (see documentation in newmat10)</td>  </tr>  <tr>    <td width="33%">strtst.cpp</td>    <td width="67%">test program</td>  </tr>  <tr>    <td width="33%">strtst.dat</td>    <td width="67%">data file used by test program</td>  </tr>  <tr>    <td width="33%">strtst.txt</td>    <td width="67%">output from the test program</td>  </tr>  <tr>    <td width="33%">test_exs.cpp</td>    <td width="67%">test exceptions</td>  </tr>  <tr>    <td width="33%">test_exs.txt</td>    <td width="67%">output from test_exs</td>  </tr>  <tr>    <td width="33%">readme.txt</td>    <td width="67%">readme file</td>  </tr>  <tr>    <td width="33%">string.htm</td>    <td width="67%">this file</td>  </tr>  <tr>    <td width="33%">rbd.css</td>    <td width="67%">style sheet for use with htm files</td>  </tr>  <tr>    <td width="33%">st_gnu.mak</td>    <td width="67%">make file for gnu c++</td>  </tr>  <tr>    <td width="33%">st_b55.mak</td>    <td width="67%">make file for Borland C++ 5.5</td>  </tr>  <tr>    <td width="33%">str.lfl</td>    <td width="67%">library file list for make file generator</td>  </tr>  <tr>    <td width="33%">st_targ.txt</td>    <td width="67%">target file for make file generator</td>  </tr>  <tr>    <td width="33%">format.h</td>    <td width="67%">header file for format program</td>  </tr>  <tr>    <td width="33%">format.cpp</td>    <td width="67%">bodies for format program</td>  </tr>  <tr>    <td width="33%">formtest.cpp</td>    <td width="67%">test program for format program</td>  </tr>  <tr>    <td width="33%">formtest.txt</td>    <td width="67%">output from test program</td>  </tr>  <tr>    <td width="33%">format.htm</td>    <td width="67%">documentation for format program</td>  </tr>  <tr>    <td width="33%">gstring.h</td>    <td width="67%">header file for gstring ascii file editor</td>  </tr>  <tr>    <td width="33%">gstring.cpp</td>    <td width="67%">bodies for gstring program</td>  </tr>  <tr>    <td width="33%">liststr.cpp</td>    <td width="67%">bodies for gstring program</td>  </tr>  <tr>    <td width="33%">lstst.cpp</td>    <td width="67%">test program</td>  </tr>  <tr>    <td width="33%">fox.dat</td>    <td width="67%">test data file</td>  </tr>  <tr>    <td width="33%">lstst.dat</td>    <td width="67%">test data file</td>  </tr>  <tr>    <td width="33%">lstst.txt</td>    <td width="67%">output from test program</td>  </tr>  <tr>    <td width="33%">gstring.htm</td>    <td width="67%">documentation for gstring program</td>  </tr></table></div><h3><a name="testing"></a>Testing and getting started</h3><p>I have tested this program on the Borland 5.5, 5.0 (32 bit only, test program won'trun under 16 bit), MS VC++ 6, Watcom 10A, Gnu 2.95, 2.96 and Sun CC (version 6) compilers.</p><p>For compilers that don't recognise the <b>bool</b> keyword you need to edit <i>include.h</i> to enable my simulated Booleans. For the Watcom compiler, Borland 5.0, and CC (version 5 and earlier) edit <i>include.h</i> to use my simulated exceptions rather than the compiler supported exceptions. See the newmat documentation for more information about editing <i>include.h</i>.</p><p>The <a href="gstring.htm">GString</a> library which is included in this package uses nested classes and will not run under the Watcom 10A compilers.</p><p>The CC compilers generate 33 error messages when running the <i>strtst</i> test program. I suspectthese are due to a slightly different convention in deleting temporaries and don't matter.</p><p>For the indexes, lengths etc I use <b>unsigned int</b> (typedefed to uint). This isinstead of size_type in the official package. Using size_type as a type ofvariable seems too bizarre for me to use (as yet).</p><p>You will need to #include files <i>include.h</i> and <i>str.h</i> in your programs that use thispackage. Don't forget to edit <i>include.h</i> to determine whether exceptions are to be used,simulated or disabled. If you use the simulated exceptions you should turn off theexception capability of a compiler that does support exceptions.</p><p>I have included make files for Gnu G++ and Borland 5.5. Make files for some other compilers can be generated using my <a href="genemake.htm">genemake</a> utility. The file <i>st_targ.txt</i> gives the list of targets for <i>genemake</i> and<i>str.lfl</i> has the list of names of the libraries. See the <a href="genemake.htm">genemake</a> documentation for more details about the make files.</p><h2><a name="public"></a>The public member functions</h2><h3><a name="static"></a>Static variable</h3><div align="left"><table border="1" width="100%" cellpadding="2">  <tr>    <td width="50%" valign="top"><tt>static uint npos</tt></td>    <td width="50%" valign="top">String::npos is the largest possible value of uint and is    used to indicate that a find function has failed to find its target. All Strings must have    length strictly less than String::npos</td>  </tr></table></div><h3><a name="construct"></a>Constructors, destruction, operator=</h3><div align="left"><table border="1" width="100%" cellpadding="2">  <tr>    <td width="50%" valign="top"><tt>String()</tt> </td>    <td width="50%" valign="top">construct a String of zero length</td>  </tr>  <tr>    <td width="50%" valign="top"><tt>String(const String&amp;str)</tt> </td>    <td width="50%" valign="top">copy constructor (not explicitly in standard)</td>  </tr>  <tr>    <td width="50%" valign="top"><tt>String(const String&amp;str, uint pos, uint n = npos)</tt>    </td>    <td width="50%" valign="top">construct a String from str starting at location pos (first    location = 0) and continuing for the length of the String or for n characters, whichever    occurs first</td>  </tr>  <tr>    <td width="50%" valign="top"><tt>String(const char* s, uint n)</tt> </td>    <td width="50%" valign="top">construct a String from s taking a maximum of n characters or    the length of the String</td>  </tr>  <tr>    <td width="50%" valign="top"><tt>String(const char* s)</tt> </td>    <td width="50%" valign="top">construct a String from s</td>  </tr>  <tr>    <td width="50%" valign="top"><tt>String(uint n, char c)</tt> </td>    <td width="50%" valign="top">construct a String consisting of n copies of the character c</td>  </tr>  <tr>    <td width="50%" valign="top"><tt>~String()</tt> </td>    <td width="50%" valign="top">the destructor</td>  </tr>  <tr>    <td width="50%" valign="top"><tt>String&amp; operator=(const String&amp; str)</tt> </td>    <td width="50%" valign="top">copy a String (except that it may be able to avoid copying)</td>  </tr>  <tr>    <td width="50%" valign="top"><tt>String&amp; operator=(const char* s)</tt> </td>    <td width="50%" valign="top">set a String equal to a c-style character string pointed to    by s</td>  </tr>  <tr>    <td width="50%" valign="top"><tt>String&amp; operator=(const char c)</tt> </td>    <td width="50%" valign="top">set a String equal to a character</td>  </tr>

⌨️ 快捷键说明

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