📄 gstring.htm
字号:
particularly the case when <i>WS</i> or <i>OWS</i> terms are present. This needs further work. Meanwhile, avoid using <i>LongestString</i> or <i>LDOTS</i> in expressions that also include <i>WS</i> or <i>OWS</i>.</p><H2><EM><A NAME="TaggedStringList"></A>TaggedStringList</EM> classes</H2><P>The <EM>TaggedStringList</EM> family is used to select a subset of the StringList for editing. It includes the <EM>TaggedStringList</EM>class and three classes, <EM>StringList_String</EM>, <EM>StringList_Range</EM> and <EM>StringList_GString</EM> derived from it.Objects from these classes are generated from one of the following expressions </P><PRE> SL.All() SL(string) SL(string, string, ends) SL(gstring)</PRE><P>where <EM>SL</EM> is a StringList, <EM>string</EM> is a String,<EM>gstring</EM> is a GString, and <EM>ends</EM> is an int. These classesenable one to edit a subset of the strings in a StringList.</P><P><EM>SL.All()</EM> includes <EM>all</EM> the strings in <EM>SL</EM>.</P><P><EM>SL(s)</EM>, where <EM>s</EM> is either a character string or an objectof class <EM>String</EM>, includes those strings in <EM>SL</EM> which includethe string <EM>s</EM>.</P><P><EM>SL(s1,s2, ends)</EM>, where <EM>s1</EM> and <EM>s2</EM> are eithercharacter strings or objects of class <EM>String</EM>, include those strings in<EM>SL</EM> selected in the range <EM>s1</EM> to <EM>s2</EM>. The <EM>ends</EM>parameter, if included, determines which ends of the ranges are included. Seethe description in the notes on the <A HREF="#StringList">StringList class</A>.The default is to include both ends.</P><P><EM>SL(gs)</EM>, where <EM>gs</EM> is a <EM>GString</EM> expression,includes those strings in <EM>SL</EM> which match the pattern <EM>gs</EM>. Notethat here, as elsewhere, the pattern must match the complete string and notjust a subset of it.</P><P>Objects of these classes should not be constructed as stand-alone objectsbut should be used as part of an editing function such as</P><PRE> SL.All().sa("target","replace with");</PRE><P>They can also the passed to a function as a <EM>TaggedStringList&</EM>parameter. This provides a way of carrying out more complicated editingfunctions that cannot be carried out directly with the functions provided inTaggedStringList family. These classes can access<EM>TaggedStringList::iterator</EM> and<EM>TaggedStringList::reverse_iterator</EM> classes which have the sameproperties with corresponding classes associated with the <EM>StringList</EM>class.</P><P><STRONG>Note:</STRONG> do not use the <EM>reverse_iterator</EM> class with a<EM>StringList_Range</EM> object.</P><P><b>Note:</b> if possible, usea simple string as an argument to <EM>SL</EM> to reduce the number of stringsthat have to be searched with a GString.</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%"><TT>friend ostream& operator<<(ostream& os,TaggedStringList& tsl);</TT></TD><TD WIDTH="50%">Output the entire TaggedStringList to a file.</TD></TR><TR><TD WIDTH="50%"><TT>iterator begin();</TT></TD><TD WIDTH="50%">Return an iterator pointing to the beginning of theStringList.</TD></TR><TR><TD WIDTH="50%"><TT>iterator end();</TT></TD><TD WIDTH="50%">Return an iterator pointing to one past the end of theStringList.</TD></TR><TR><TD WIDTH="50%"><TT>reverse_iterator rbegin();</TT></TD><TD WIDTH="50%">Return a reverse iterator pointing to the end of theStringList.</TD></TR><TR><TD WIDTH="50%"><TT>reverse_iterator rend();</TT></TD><TD WIDTH="50%">Return a reverse iterator pointing one before the beginning ofthe StringList.</TD></TR><TR><TD WIDTH="50%"><TT>void erase(iterator i);</TT></TD><TD WIDTH="50%">Erase the string corresponding to <EM>i.</EM> See note aboutthe corresponding entry in the StringList class.</TD></TR><TR><TD WIDTH="50%"><TT>void erase(reverse_iterator i);</TT></TD><TD WIDTH="50%">Erase the string corresponding to <EM>i.</EM> See note aboutthe corresponding entry in the StringList class.</TD></TR><TR><TD WIDTH="50%"><TT>void insert_before(const String& s, iteratori)</TT></TD><TD WIDTH="50%">Insert <EM>s</EM> before the string corresponding to<EM>i</EM>.</TD></TR><TR><TD WIDTH="50%"><TT>void insert_after(const String& s, iteratori)</TT></TD><TD WIDTH="50%">Insert <EM>s</EM> after the string corresponding to<EM>i</EM>.</TD></TR><TR><TD WIDTH="50%"><TT>void sf(const String& s1, const String& s2,iterator i);</TT></TD><TD WIDTH="50%">Substitute the first occurrence of <EM>s1</EM> by <EM>s2</EM>in the string corresponding to <EM>i</EM>.</TD></TR><TR><TD WIDTH="50%"><TT>void sl(const String& s1, const String& s2,iterator i);</TT></TD><TD WIDTH="50%">Substitute the last occurrence of <EM>s1</EM> by <EM>s2</EM> inthe string corresponding to <EM>i</EM>.</TD></TR><TR><TD WIDTH="50%"><TT>void sa(const String& s1, const String& s2,iterator i);</TT></TD><TD WIDTH="50%">Substitute all occurrences of <EM>s1</EM> by <EM>s2</EM> in thestring corresponding to <EM>i</EM>.</TD></TR><TR><TD WIDTH="50%"><TT>void s(GString& g1, GString& g2, iteratori);</TT></TD><TD WIDTH="50%">Substitute the pattern of <EM>g1</EM> by <EM>g2</EM> in thestring corresponding to <EM>i</EM>.</TD></TR><TR><TD WIDTH="50%"><TT>void UpperCase(iterator i);</TT></TD><TD WIDTH="50%">Convert the string corresponding to <EM>i</EM> to uppercase.</TD></TR><TR><TD WIDTH="50%"><TT>void LowerCase(iterator i);</TT></TD><TD WIDTH="50%">Convert the string corresponding to <EM>i</EM> to lowercase.</TD></TR><TR><TD WIDTH="50%"><TT>void erase();</TT></TD><TD WIDTH="50%">Erase all strings selected by the TaggedStringList class.</TD></TR><TR><TD WIDTH="50%"><TT>void insert_before(const String& s)</TT></TD><TD WIDTH="50%">Insert <EM>s</EM> before each of the selected strings.</TD></TR><TR><TD WIDTH="50%"><TT>void insert_after(const String& s)</TT></TD><TD WIDTH="50%">Insert <EM>s</EM> after each of the selected strings.</TD></TR><TR><TD WIDTH="50%"><TT>void sf(const String& s1, const String&s2);</TT></TD><TD WIDTH="50%">Substitute the first occurrence of <EM>s1</EM> by <EM>s2</EM>in each of the selected strings.</TD></TR><TR><TD WIDTH="50%"><TT>void sl(const String& s1, const String&s2);</TT></TD><TD WIDTH="50%">Substitute the last occurrence of <EM>s1</EM> by <EM>s2</EM> ineach of the selected strings.</TD></TR><TR><TD WIDTH="50%"><TT>void sa(const String& s1, const String&s2);</TT></TD><TD WIDTH="50%">Substitute all occurrences of <EM>s1</EM> by <EM>s2</EM> ineach of the selected strings.</TD></TR><TR><TD WIDTH="50%"><TT>void s(GString& g1, GString& g2);</TT></TD><TD WIDTH="50%">Substitute the pattern of <EM>g1</EM> by <EM>g2</EM> in each ofthe selected strings.</TD></TR><TR><TD WIDTH="50%"><TT>void UpperCase();</TT></TD><TD WIDTH="50%">Convert the selected strings to upper case.</TD></TR><TR><TD WIDTH="50%"><TT>void LowerCase();</TT></TD><TD WIDTH="50%">Convert the selected strings to lower case.</TD></TR></TABLE></DIV><P>The iterator versions of the editing functions are intended to be usedwithin loops involving an iterator. Use a (forward) iterator rather than areverse iterator. The editing functions without iterators refer to the wholeTaggedStringList family object.</P><H2><A NAME="Examples"></A>Examples</H2><P>I have a file, fox.txt, containing the single line:</P><PRE> The quick brown fox jumps over the lazy dog.</PRE><P>I demonstrate a variety of statements for editing this line.</P><P>Change <EM>quick</EM> to <EM>fast</EM> and print out the resulting line.</P><PRE> ifstream is("fox.txt"); StringList Fox; is >> Fox; Fox.All().sa("quick", "fast"); cout << Fox;</PRE><P>or using GStrings</P><PRE> ifstream is("fox.txt"); StringList Fox; is >> Fox; Fox.All().s(DOTS + "quick" + DOTS, DOTS + "fast" + DOTS); cout << Fox;</PRE><P>Suppose the fox line is one line in a long file. I want the editing to applyonly to lines that include the word <EM>fox</EM> (where we are ignoring thepossibility that <EM>fox</EM> is included in some other word).</P><PRE> ifstream is("fox.txt"); StringList Fox; is >> Fox; Fox("fox").s(DOTS + "quick" + DOTS, DOTS + "fast" + DOTS); cout << Fox;</PRE><P>I don't know what the adjectives between <EM>The</EM> and <EM>fox</EM> arebut I want to change them to <EM>slow grey</EM>. I show just the editing line. </P><PRE> Fox.All().s(GS + "The" + DOTS + "fox" + DOTS, DOTS + " slow grey " + DOTS + DOTS);</PRE><P>I am not sure whether the verb is <EM>jump</EM> or <EM>jumps</EM> but I wantto change it to <EM>leap</EM> or <EM>leaps</EM> respectively.</P><PRE> Fox.All().s(DOTS + (GS | "jump" | "jumps") + DOTS, DOTS + (GS | "leap" | "leaps") + DOTS);</PRE><P>I don't what the animals involved are but I want to swap them.</P><PRE> ShortestString SS1, SS2; Fox.All().s(GS + "The quick brown " + SS1 + " jumps over the lazy " + SS2 + ".", DOTS + SS2 + DOTS + SS1 + DOTS);</PRE><P> </P><H2><A NAME="ToDo"></A>To do</H2><P>Operator * to allow multiple copies of a target. I will need three types ofcounters <EM>N0</EM> (may be 0 or 1 repetitions), <EM>NN</EM> (may be anynumber of repetitions including 0, <EM>N1</EM> (may be any number ofrepetitions > 0). Can also have a positive integer. Assume <tt>></tt> combinationrather than <tt>+</tt>. Assume longest when saying type of <tt>*</tt> expression. This isgoing to be a bit of problem as Collect won't work correctly; may need a IntList class to hold switching data.</P><P>Review rules regarding shortest and longest.</P><P>Rethink handling of white space objects.</P><P>Letter by letter translations (SED <EM>y</EM> operator) - need functionR('a', 'z');</P><P>Fix problem with <TT>i.erase(); ++i;</TT>. Decide how to handle<TT>i.insert_next(S); ++i;</TT>.</P><P>In TaggedStringList make iterators forward only; make reverse iterator fullyfunctional (?)</P><P>Introduce new editing phase, <EM>Load</EM>, between <EM>Match</EM> and<EM>Collect</EM> to load values into ShortestString etc. This will ensure valueis not set if not involved in a match. Introduce boolean indicator intoShortestString etc to show if value has been set; reset when assigned a valuewith =. Run <EM>Load</EM> at search stage as well as edit phase.(??)</P><P>More internal checking - iterators correctly matched with object they areaccessing, comparisons valid.</P><P>Check that operators in collect and translate phases agree.</P><P>Notes on implementing new facilities. What is needed for a newTaggedStringList class and what is needed for a new operator (operator - needto define action in both GString and InitialGstring; list functions required)or a new target object. Requirements on Match Load Collect and Translate.Interchangeable target object <tt>-></tt> must push one string to list at collecttime and pop one at translate time - note defaults.</P><P>Check all target objects are interchangeable between Collect and Translatephases. Collect must push a value; Translate must Pop a value.</P><P>Directory read into StringList - how to handle attributes? </P><P>Column oriented input and output</P><P>Regular expression input</P><P>Number input (eg recognise E format)</P><P>Extend and document substitution list facilities </P><UL><LI><a href="string.htm">return to string library</a></LI> <li><a HREF="ol_doc.htm">To online documentation page</a></li> <li><A HREF="#Top">Back to top</A></li></UL><P> </P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -