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

📄 gstring.htm

📁 自编的一个String类
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//SoftQuad Software//DTD HoTMetaL PRO 5.0::19981217::extensions to HTML 4.0//EN" "hmpro5.dtd"> <HTML> <HEAD><meta http-equiv="Content-Language" content="en-nz"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"> <TITLE>G-string editor</TITLE><META NAME="GENERATOR" CONTENT="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"><link rel="stylesheet" type="text/css" href="rbd.css"></HEAD><BODY><H1 ALIGN="left"><A NAME="Top"></A>G-String ascii fileeditor</H1><p ALIGN="left"><i>Version of July, 2001</i></p><UL><LI><A HREF="#StringList"><EM>StringList</EM> class</A></LI><LI><A HREF="#GString"><EM>GString</EM> classes</A></LI><LI><A HREF="#TaggedStringList"><EM>TaggedStringList</EM> classes</A></LI><LI><A HREF="#Examples">Examples</A></LI><LI><A HREF="#ToDo">To do</A></LI><LI><a href="string.htm">return to string library</a></LI>  <li><a HREF="ol_doc.htm">To online documentation page</a></li></UL><P>The GString class library is distributed as part of the <a href="string.htm">stringlibrary</a>. See the string library documentation on how to customise the<tt>include.h</tt> file for your compiler and for the file list.</P><P>The GString class library is an editor similar, in concept, to the Unix <EM>SED</EM> editor. Onewrites a series commands to edit an ASCII file such as, for example, HTML orC++ source. This is useful if you want to do the same editing job over and overagain on one or several files. For example you might want to change the name ofa class in a C++ program and have to go through all your source files to makethe change.</P><P>This editor, however, is a C++ library, and the series of commands, arewritten in C++. So one has a full power of C++ and one does not have to learn anew language. This editor, by itself, is slightly less ambitious than the SED editor.However, when you add in the extra flexibility and capabilities provided by itbeing embedded in C++, you get a much more powerful product, that is as easy touse if you already know the basics of C++. At least that is the intention.</P><P>This is a <EM>concept testing</EM> version and there are a number of rough edges. It needs further testing anddevelopment.</P><P>There are three components </P><UL><LI>the <A HREF="#StringList"><EM>StringList</EM> class</A></LI><LI>the <A HREF="#GString"><EM>GString</EM> classes</A></LI><LI>the <A HREF="#TaggedStringList"><EM>TagggedStringList</EM> classes</A></LI></UL><P>The StringList class stores the file as a linked list of strings, eachstring corresponding to a line in the original file. The GString(<EM>generalised</EM> strings) family of classes provide the editingcapability. The TaggedStringList family of classes allow one to edit subsets of the strings making up the original file.</P><P>See the <A HREF="#Examples">example</A> section for some simple examples. </P><P>This library uses my <A HREF="string.htm">string library</A>.</P><P>GString uses nested classes so will not run on older compilers.</P><H2><A NAME="StringList"></A><EM>StringList</EM>class</H2><p>This is similar to an implementation of the standard template class explicitly for <i>String</i>s.</p><H3>The member functions and friends</H3><DIV ALIGN="left"><TABLE BORDER="1" WIDTH="100%" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="1"><TR><TD WIDTH="50%" valign="top"><TT>StringList SL;</TT> </TD><TD WIDTH="50%" valign="top">Construct a StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>StringList(StringList&amp; SL);</TT> </TD><TD WIDTH="50%" valign="top">Construct a StringList from another StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>~StringList();</TT> </TD><TD WIDTH="50%" valign="top">The destructor.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>void operator=(StringList&amp; SL);</TT> </TD><TD WIDTH="50%" valign="top">Copy a StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>void push_back(const String&amp; s);</TT> </TD><TD WIDTH="50%" valign="top">Insert a new string at the end of a StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>void push_front(const String&amp; s);</TT></TD><TD WIDTH="50%" valign="top">Insert a new string at the beginning of a StringList</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>String pop_back();</TT> </TD><TD WIDTH="50%" valign="top">Return the string at the end of a StringList and erase it fromthe StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>String pop_front();</TT></TD><TD WIDTH="50%" valign="top">Return the string at the beginning of a StringList and erase itfrom the StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>void CleanUp();</TT> </TD><TD WIDTH="50%" valign="top">Erase all the strings from the StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>int size();</TT> </TD><TD WIDTH="50%" valign="top">Return the number of strings in the StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>void Format(int width, StringList&amp; sl);</TT> </TD><TD WIDTH="50%" valign="top">Word-wrap the document represented by the StringList to fit ina page of the given <EM>width</EM>. Return the result to <EM>sl.</EM></TD></TR><TR><TD WIDTH="50%" valign="top"><TT>friend ostream&amp; operator&lt;&lt;(ostream&amp; os,StringList&amp; sl);</TT> </TD><TD WIDTH="50%" valign="top">Output the entire StringList to a file.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>friend void operator&gt;&gt;(istream&amp; is,StringList&amp; sl);</TT> </TD><TD WIDTH="50%" valign="top">Read an entire file to a StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>StringList_String operator()(const String&amp; s);</TT></TD><TD WIDTH="50%" valign="top">Return a StringList_String by selecting strings containing thestring <EM>s</EM>.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>StringList_GString operator()(GString&amp; g);</TT> </TD><TD WIDTH="50%" valign="top">Return a StringList_GString by selecting strings conforming tothe pattern <EM>g</EM>.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>StringList_Range operator()(const String&amp; s1, constString&amp; s2, int ends = 3);</TT> </TD><TD WIDTH="50%" valign="top">Return a StringList_Range by selecting ranges delimited by thestrings <EM>s1</EM> and <EM>s2</EM>. See note below.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>TaggedStringList All();</TT> </TD><TD WIDTH="50%" valign="top">Return a TaggedStringList containing all of theStringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>iterator begin();</TT> </TD><TD WIDTH="50%" valign="top">Return an iterator pointing to the beginning of theStringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>iterator end();</TT> </TD><TD WIDTH="50%" valign="top">Return an iterator pointing to one past the end of theStringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>reverse_iterator rbegin();</TT> </TD><TD WIDTH="50%" valign="top">Return a reverse iterator pointing to the end of theStringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>reverse_iterator rend();</TT> </TD><TD WIDTH="50%" valign="top">Return a reverse iterator pointing one before the beginning ofthe StringList.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>iterator find(const String&amp; s);</TT> </TD><TD WIDTH="50%" valign="top">Return an iterator pointing to the first string containing<EM>s</EM>.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>reverse_iterator rfind(const String&amp; s);</TT> </TD><TD WIDTH="50%" valign="top">Return a reverse iterator pointing to the last stringcontaining <EM>s</EM>.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>iterator find(const String&amp; s, iterator i);</TT> </TD><TD WIDTH="50%" valign="top">Return an iterator pointing to the first string containing<EM>s</EM> after <EM>i</EM>.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>reverse_iterator rfind(const String&amp; s,reverse_iterator i);</TT> </TD><TD WIDTH="50%" valign="top">Return a reverse iterator pointing to the last stringcontaining <EM>s</EM> before <EM>i</EM>.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>void erase(iterator i);</TT> </TD><TD WIDTH="50%" valign="top">Erase the string corresponding to <EM>i</EM>. See notebelow.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>void erase(reverse_iterator i);</TT> </TD><TD WIDTH="50%" valign="top">Erase the string corresponding to <EM>i</EM>. See notebelow.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>void insert_before(const String&amp; s, iterator i);</TT></TD><TD WIDTH="50%" valign="top">Insert a string, s, before iterator <EM>i</EM>.</TD></TR><TR><TD WIDTH="50%" valign="top"><TT>void insert_after(const String&amp; s, iterator i);</TT></TD><TD WIDTH="50%" valign="top">Insert a string, s, after iterator <EM>i</EM>.</TD></TR></TABLE></DIV><H3>Notes</H3><P>The parameter <EM>ends</EM> in</P><P><TT>&nbsp;&nbsp; StringList_Range operator()(const String&amp; s1, constString&amp; s2, int ends = 3); </TT></P><P>determines which of the range ends are included in the range. </P><DIV ALIGN="center"><CENTER><TABLE BORDER="1" WIDTH="75%" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0"><TR><TD WIDTH="50%"><b>ends</b></TD><TD WIDTH="50%"><b>range ends included in TaggedStringList</b></TD></TR><TR><TD WIDTH="50%">0</TD><TD WIDTH="50%">neither</TD></TR><TR><TD WIDTH="50%">1</TD><TD WIDTH="50%">second</TD></TR><TR><TD WIDTH="50%">2</TD><TD WIDTH="50%">first</TD></TR><TR><TD WIDTH="50%">3</TD><TD WIDTH="50%">both</TD></TR></TABLE></CENTER></DIV><P>After erasing a string corresponding to an iterator <EM>i</EM> you cannotmanipulate <EM>i</EM>, for example, with <EM>i++</EM>. This means that specialcare must be taken with loops which erase elements from a StringList. Forexample, use</P><PRE>StringList::iterator i1;for (StringList::iterator i = SL.begin(); i != SL.end(); i=i1){   i1 = i; ++i1; SL.erase(i);}</PRE><P>rather than</P><PRE>for (StringList::iterator i = SL.begin(); i != SL.end(); ++i){   SL.erase(i);}</PRE><H3>Iterator functions</H3><DIV ALIGN="left"><TABLE BORDER="1" WIDTH="100%" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="1"><TR><TD WIDTH="33%"><b>Function</b></TD><TD WIDTH="33%"><b>iterator</b></TD><TD WIDTH="33%"><b>reverse iterator</b></TD></TR><TR><TD WIDTH="33%"><TT>++i</TT></TD><TD WIDTH="33%">point to next string</TD><TD WIDTH="33%">point to previous string</TD></TR><TR><TD WIDTH="33%"><TT>--i</TT></TD><TD WIDTH="33%">point to previous string</TD><TD WIDTH="33%">point to next string</TD></TR><TR><TD WIDTH="33%"><TT>i++</TT></TD>

⌨️ 快捷键说明

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