You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
310 lines
16 KiB
310 lines
16 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/tools/tqstringlist.cpp:46 -->
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>TQStringList Class</title>
|
|
<style type="text/css"><!--
|
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
|
a:link { color: #004faf; text-decoration: none }
|
|
a:visited { color: #672967; text-decoration: none }
|
|
body { background: #ffffff; color: black; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr bgcolor="#E5E5E5">
|
|
<td valign=center>
|
|
<a href="index.html">
|
|
<font color="#004faf">Home</font></a>
|
|
| <a href="classes.html">
|
|
<font color="#004faf">All Classes</font></a>
|
|
| <a href="mainclasses.html">
|
|
<font color="#004faf">Main Classes</font></a>
|
|
| <a href="annotated.html">
|
|
<font color="#004faf">Annotated</font></a>
|
|
| <a href="groups.html">
|
|
<font color="#004faf">Grouped Classes</font></a>
|
|
| <a href="functions.html">
|
|
<font color="#004faf">Functions</font></a>
|
|
</td>
|
|
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQStringList Class Reference</h1>
|
|
|
|
<p>The TQStringList class provides a list of strings.
|
|
<a href="#details">More...</a>
|
|
<p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when TQt is built with thread support.</p>
|
|
<p><tt>#include <<a href="tqstringlist-h.html">tqstringlist.h</a>></tt>
|
|
<p>Inherits <a href="tqvaluelist.html">TQValueList</a><TQString>.
|
|
<p><a href="tqstringlist-members.html">List of all member functions.</a>
|
|
<h2>Public Members</h2>
|
|
<ul>
|
|
<li class=fn><a href="#TQStringList"><b>TQStringList</b></a> ()</li>
|
|
<li class=fn><a href="#TQStringList-2"><b>TQStringList</b></a> ( const TQStringList & l )</li>
|
|
<li class=fn><a href="#TQStringList-3"><b>TQStringList</b></a> ( const TQValueList<TQString> & l )</li>
|
|
<li class=fn><a href="#TQStringList-4"><b>TQStringList</b></a> ( const TQString & i )</li>
|
|
<li class=fn><a href="#TQStringList-5"><b>TQStringList</b></a> ( const char * i )</li>
|
|
<li class=fn>void <a href="#sort"><b>sort</b></a> ()</li>
|
|
<li class=fn>TQString <a href="#join"><b>join</b></a> ( const TQString & sep ) const</li>
|
|
<li class=fn>TQStringList <a href="#grep"><b>grep</b></a> ( const TQString & str, bool cs = TRUE ) const</li>
|
|
<li class=fn>TQStringList <a href="#grep-2"><b>grep</b></a> ( const TQRegExp & rx ) const</li>
|
|
<li class=fn>TQStringList & <a href="#gres"><b>gres</b></a> ( const TQString & before, const TQString & after, bool cs = TRUE )</li>
|
|
<li class=fn>TQStringList & <a href="#gres-2"><b>gres</b></a> ( const TQRegExp & rx, const TQString & after )</li>
|
|
</ul>
|
|
<h2>Static Public Members</h2>
|
|
<ul>
|
|
<li class=fn>TQStringList <a href="#fromStrList"><b>fromStrList</b></a> ( const TQStrList & ascii )</li>
|
|
<li class=fn>TQStringList <a href="#split-2"><b>split</b></a> ( const TQString & sep, const TQString & str, bool allowEmptyEntries = FALSE )</li>
|
|
<li class=fn>TQStringList <a href="#split-3"><b>split</b></a> ( const TQChar & sep, const TQString & str, bool allowEmptyEntries = FALSE )</li>
|
|
<li class=fn>TQStringList <a href="#split"><b>split</b></a> ( const TQRegExp & sep, const TQString & str, bool allowEmptyEntries = FALSE )</li>
|
|
</ul>
|
|
<hr><a name="details"></a><h2>Detailed Description</h2>
|
|
|
|
|
|
|
|
The TQStringList class provides a list of strings.
|
|
<p>
|
|
|
|
|
|
|
|
<p> It is used to store and manipulate strings that logically belong
|
|
together. Essentially TQStringList is a <a href="tqvaluelist.html">TQValueList</a> of <a href="tqstring.html">TQString</a>
|
|
objects. Unlike <a href="tqstrlist.html">TQStrList</a>, which stores pointers to characters,
|
|
TQStringList holds real TQString objects. It is the class of choice
|
|
whenever you work with Unicode strings. TQStringList is part of the
|
|
<a href="tqtl.html">TQt Template Library</a>.
|
|
<p> Like TQString itself, TQStringList objects are <a href="shclass.html#implicitly-shared">implicitly shared</a>, so
|
|
passing them around as value-parameters is both fast and safe.
|
|
<p> Strings can be added to a list using <a href="tqvaluelist.html#append">append</a>(), <a href="tqvaluelist.html#operator+-eq">operator+=</a>() or
|
|
<a href="tqvaluelist.html#operator-lt-lt">operator<<</a>(), e.g.
|
|
<pre>
|
|
TQStringList fonts;
|
|
fonts.<a href="tqvaluelist.html#append">append</a>( "Times" );
|
|
fonts += "Courier";
|
|
fonts += "Courier New";
|
|
fonts << "Helvetica [Cronyx]" << "Helvetica [Adobe]";
|
|
</pre>
|
|
|
|
<p> String lists have an iterator, TQStringList::Iterator(), e.g.
|
|
<pre>
|
|
for ( TQStringList::<a href="tqvaluelist.html#Iterator">Iterator</a> it = fonts.begin(); it != fonts.end(); ++it ) {
|
|
cout << *it << ":";
|
|
}
|
|
cout << endl;
|
|
// Output:
|
|
// Times:Courier:Courier New:Helvetica [Cronyx]:Helvetica [Adobe]:
|
|
</pre>
|
|
|
|
<p> Many TQt functions return string lists by value; to iterate over
|
|
these you should make a copy and iterate over the copy.
|
|
<p> You can concatenate all the strings in a string list into a single
|
|
string (with an optional separator) using <a href="#join">join</a>(), e.g.
|
|
<pre>
|
|
<a href="tqstring.html">TQString</a> allFonts = fonts.join( ", " );
|
|
cout << allFonts << endl;
|
|
// Output:
|
|
// Times, Courier, Courier New, Helvetica [Cronyx], Helvetica [Adobe]
|
|
</pre>
|
|
|
|
<p> You can sort the list with <a href="#sort">sort</a>(), and extract a new list which
|
|
contains only those strings which contain a particular substring
|
|
(or match a particular <a href="tqregexp.html#regular-expression">regular expression</a>) using the <a href="#grep">grep</a>()
|
|
functions, e.g.
|
|
<pre>
|
|
fonts.sort();
|
|
cout << fonts.join( ", " ) << endl;
|
|
// Output:
|
|
// Courier, Courier New, Helvetica [Adobe], Helvetica [Cronyx], Times
|
|
|
|
TQStringList helveticas = fonts.grep( "Helvetica" );
|
|
cout << helveticas.<a href="#join">join</a>( ", " ) << endl;
|
|
// Output:
|
|
// Helvetica [Adobe], Helvetica [Cronyx]
|
|
</pre>
|
|
|
|
<p> Existing strings can be split into string lists with character,
|
|
string or regular expression separators, e.g.
|
|
<pre>
|
|
<a href="tqstring.html">TQString</a> s = "Red\tGreen\tBlue";
|
|
TQStringList colors = TQStringList::<a href="#split">split</a>( "\t", s );
|
|
cout << colors.<a href="#join">join</a>( ", " ) << endl;
|
|
// Output:
|
|
// Red, Green, Blue
|
|
</pre>
|
|
|
|
<p>See also <a href="shared.html">Implicitly and Explicitly Shared Classes</a>, <a href="text.html">Text Related Classes</a>, and <a href="tools.html">Non-GUI Classes</a>.
|
|
|
|
<hr><h2>Member Function Documentation</h2>
|
|
<h3 class=fn><a name="TQStringList"></a>TQStringList::TQStringList ()
|
|
</h3>
|
|
|
|
<p> Creates an empty string list.
|
|
|
|
<h3 class=fn><a name="TQStringList-2"></a>TQStringList::TQStringList ( const <a href="tqstringlist.html">TQStringList</a> & l )
|
|
</h3>
|
|
|
|
<p> Creates a copy of the list <em>l</em>. This function is very fast
|
|
because TQStringList is <a href="shclass.html#implicitly-shared">implicitly shared</a>. In most situations this
|
|
acts like a <a href="shclass.html#deep-copy">deep copy</a>, for example, if this list or the original
|
|
one or some other list referencing the same shared data is
|
|
modified, the modifying list first makes a copy, i.e.
|
|
copy-on-write.
|
|
In a threaded environment you may require a real deep copy
|
|
.
|
|
|
|
<h3 class=fn><a name="TQStringList-3"></a>TQStringList::TQStringList ( const <a href="tqvaluelist.html">TQValueList</a><TQString> & l )
|
|
</h3>
|
|
|
|
<p> Constructs a new string list that is a copy of <em>l</em>.
|
|
|
|
<h3 class=fn><a name="TQStringList-4"></a>TQStringList::TQStringList ( const <a href="tqstring.html">TQString</a> & i )
|
|
</h3>
|
|
|
|
<p> Constructs a string list consisting of the single string <em>i</em>.
|
|
Longer lists are easily created as follows:
|
|
<p> <pre>
|
|
TQStringList items;
|
|
items << "Buy" << "Sell" << "Update" << "Value";
|
|
</pre>
|
|
|
|
|
|
<h3 class=fn><a name="TQStringList-5"></a>TQStringList::TQStringList ( const char * i )
|
|
</h3>
|
|
|
|
<p> Constructs a string list consisting of the single Latin-1 string <em>i</em>.
|
|
|
|
<h3 class=fn><a href="tqstringlist.html">TQStringList</a> <a name="fromStrList"></a>TQStringList::fromStrList ( const <a href="tqstrlist.html">TQStrList</a> & ascii )<tt> [static]</tt>
|
|
</h3>
|
|
Converts from an ASCII-TQStrList <em>ascii</em> to a TQStringList (Unicode).
|
|
|
|
<h3 class=fn><a href="tqstringlist.html">TQStringList</a> <a name="grep"></a>TQStringList::grep ( const <a href="tqstring.html">TQString</a> & str, bool cs = TRUE ) const
|
|
</h3>
|
|
Returns a list of all the strings containing the substring <em>str</em>.
|
|
<p> If <em>cs</em> is TRUE, the grep is done case-sensitively; otherwise
|
|
case is ignored.
|
|
<p> <pre>
|
|
TQStringList list;
|
|
list << "Bill Gates" << "John Doe" << "Bill Clinton";
|
|
list = list.<a href="#grep">grep</a>( "Bill" );
|
|
// list == ["Bill Gates", "Bill Clinton"]
|
|
</pre>
|
|
|
|
<p> <p>See also <a href="tqstring.html#find">TQString::find</a>().
|
|
|
|
<h3 class=fn><a href="tqstringlist.html">TQStringList</a> <a name="grep-2"></a>TQStringList::grep ( const <a href="tqregexp.html">TQRegExp</a> & rx ) const
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Returns a list of all the strings that match the <a href="tqregexp.html#regular-expression">regular expression</a> <em>rx</em>.
|
|
<p> <p>See also <a href="tqstring.html#find">TQString::find</a>().
|
|
|
|
<h3 class=fn><a href="tqstringlist.html">TQStringList</a> & <a name="gres"></a>TQStringList::gres ( const <a href="tqstring.html">TQString</a> & before, const <a href="tqstring.html">TQString</a> & after, bool cs = TRUE )
|
|
</h3>
|
|
Replaces every occurrence of the string <em>before</em> in the strings
|
|
that constitute the string list with the string <em>after</em>. Returns
|
|
a reference to the string list.
|
|
<p> If <em>cs</em> is TRUE, the search is case sensitive; otherwise the
|
|
search is case insensitive.
|
|
<p> Example:
|
|
<pre>
|
|
TQStringList list;
|
|
list << "alpha" << "beta" << "gamma" << "epsilon";
|
|
list.<a href="#gres">gres</a>( "a", "o" );
|
|
// list == ["olpho", "beto", "gommo", "epsilon"]
|
|
</pre>
|
|
|
|
<p> <p>See also <a href="tqstring.html#replace">TQString::replace</a>().
|
|
|
|
<h3 class=fn><a href="tqstringlist.html">TQStringList</a> & <a name="gres-2"></a>TQStringList::gres ( const <a href="tqregexp.html">TQRegExp</a> & rx, const <a href="tqstring.html">TQString</a> & after )
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Replaces every occurrence of the regexp <em>rx</em> in the string
|
|
with <em>after</em>. Returns a reference to the string list.
|
|
<p> Example:
|
|
<pre>
|
|
TQStringList list;
|
|
list << "alpha" << "beta" << "gamma" << "epsilon";
|
|
list.<a href="#gres">gres</a>( TQRegExp("^a"), "o" );
|
|
// list == ["olpha", "beta", "gamma", "epsilon"]
|
|
</pre>
|
|
|
|
<p> For regexps containing <a href="tqregexp.html#capturing-text">capturing parentheses</a>, occurrences of <b>\1</b>,
|
|
<b>\2</b>, ..., in <em>after</em> are replaced with <em>rx</em>.cap(1),
|
|
cap(2), ...
|
|
<p> Example:
|
|
<pre>
|
|
TQStringList list;
|
|
list << "Bill Clinton" << "Gates, Bill";
|
|
list.<a href="#gres">gres</a>( TQRegExp("^(.*), (.*)$"), "\\2 \\1" );
|
|
// list == ["Bill Clinton", "Bill Gates"]
|
|
</pre>
|
|
|
|
<p> <p>See also <a href="tqstring.html#replace">TQString::replace</a>().
|
|
|
|
<h3 class=fn><a href="tqstring.html">TQString</a> <a name="join"></a>TQStringList::join ( const <a href="tqstring.html">TQString</a> & sep ) const
|
|
</h3>
|
|
Joins the string list into a single string with each element
|
|
separated by the string <em>sep</em> (which can be empty).
|
|
<p> <p>See also <a href="#split">split</a>().
|
|
|
|
<p>Examples: <a href="fileiconview-example.html#x872">fileiconview/tqfileiconview.cpp</a> and <a href="toplevel-example.html#x2533">toplevel/options.ui.h</a>.
|
|
<h3 class=fn>void <a name="sort"></a>TQStringList::sort ()
|
|
</h3>
|
|
Sorts the list of strings in ascending case-sensitive order.
|
|
<p> Sorting is very fast. It uses the <a href="tqtl.html">TQt Template
|
|
Library's</a> efficient HeapSort implementation that has a
|
|
time complexity of O(n*log n).
|
|
<p> If you want to sort your strings in an arbitrary order consider
|
|
using a <a href="tqmap.html">TQMap</a>. For example you could use a TQMap<TQString,TQString>
|
|
to create a case-insensitive ordering (e.g. mapping the lowercase
|
|
text to the text), or a TQMap<int,TQString> to sort the strings by
|
|
some integer index, etc.
|
|
|
|
<p>Example: <a href="themes-example.html#x341">themes/themes.cpp</a>.
|
|
<h3 class=fn><a href="tqstringlist.html">TQStringList</a> <a name="split"></a>TQStringList::split ( const <a href="tqregexp.html">TQRegExp</a> & sep, const <a href="tqstring.html">TQString</a> & str, bool allowEmptyEntries = FALSE )<tt> [static]</tt>
|
|
</h3>
|
|
Splits the string <em>str</em> into strings wherever the <a href="tqregexp.html#regular-expression">regular expression</a> <em>sep</em> occurs, and returns the list of those strings.
|
|
<p> If <em>allowEmptyEntries</em> is TRUE, a null string is inserted in
|
|
the list wherever the separator matches twice without intervening
|
|
text.
|
|
<p> For example, if you split the string "a,,b,c" on commas, <a href="#split">split</a>()
|
|
returns the three-item list "a", "b", "c" if <em>allowEmptyEntries</em>
|
|
is FALSE (the default), and the four-item list "a", "", "b", "c"
|
|
if <em>allowEmptyEntries</em> is TRUE.
|
|
<p> If <em>sep</em> does not match anywhere in <em>str</em>, split() returns a
|
|
single element list with the element containing the single string
|
|
<em>str</em>.
|
|
<p> <p>See also <a href="#join">join</a>() and <a href="tqstring.html#section">TQString::section</a>().
|
|
|
|
<p>Examples: <a href="tutorial2-03.html#x2552">chart/element.cpp</a>, <a href="dirview-example.html#x1703">dirview/dirview.cpp</a>, and <a href="httpd-example.html#x733">network/httpd/httpd.cpp</a>.
|
|
<h3 class=fn><a href="tqstringlist.html">TQStringList</a> <a name="split-2"></a>TQStringList::split ( const <a href="tqstring.html">TQString</a> & sep, const <a href="tqstring.html">TQString</a> & str, bool allowEmptyEntries = FALSE )<tt> [static]</tt>
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> This version of the function uses a <a href="tqstring.html">TQString</a> as separator, rather
|
|
than a <a href="tqregexp.html#regular-expression">regular expression</a>.
|
|
<p> If <em>sep</em> is an empty string, the return value is a list of
|
|
one-character strings: <a href="#split">split</a>( TQString( "" ), "four" ) returns the
|
|
four-item list, "f", "o", "u", "r".
|
|
<p> If <em>allowEmptyEntries</em> is TRUE, a null string is inserted in
|
|
the list wherever the separator matches twice without intervening
|
|
text.
|
|
<p> <p>See also <a href="#join">join</a>() and <a href="tqstring.html#section">TQString::section</a>().
|
|
|
|
<h3 class=fn><a href="tqstringlist.html">TQStringList</a> <a name="split-3"></a>TQStringList::split ( const <a href="tqchar.html">TQChar</a> & sep, const <a href="tqstring.html">TQString</a> & str, bool allowEmptyEntries = FALSE )<tt> [static]</tt>
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> This version of the function uses a <a href="tqchar.html">TQChar</a> as separator, rather
|
|
than a <a href="tqregexp.html#regular-expression">regular expression</a>.
|
|
<p> <p>See also <a href="#join">join</a>() and <a href="tqstring.html#section">TQString::section</a>().
|
|
|
|
<!-- eof -->
|
|
<hr><p>
|
|
This file is part of the <a href="index.html">TQt toolkit</a>.
|
|
Copyright © 1995-2007
|
|
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
|
<table width=100% cellspacing=0 border=0><tr>
|
|
<td>Copyright © 2007
|
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|
<td align=right><div align=right>TQt 3.3.8</div>
|
|
</table></div></address></body>
|
|
</html>
|