documented the weird behaviour of wxTextFile:GetPrev/NextLine

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7874 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-07-27 14:01:59 +00:00
parent 2c33291c88
commit 0b397099c7
2 changed files with 42 additions and 6 deletions

View File

@@ -189,10 +189,13 @@ allows more "iterator-like" traversal of the list of lines, i.e. you may
write something like: write something like:
\begin{verbatim} \begin{verbatim}
for ( str = GetFirstLine(); !Eof(); str = GetNextLine() ) wxTextFile file;
...
for ( str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
{ {
// do something with the current line in str // do something with the current line in str
} }
// do something with the last line in str
\end{verbatim} \end{verbatim}
\membersection{wxTextFile::GetNextLine}\label{wxtextfilegetnextline} \membersection{wxTextFile::GetNextLine}\label{wxtextfilegetnextline}
@@ -212,7 +215,21 @@ Gets the previous line in the file.
\func{wxString\&}{GetLastLine}{\void} \func{wxString\&}{GetLastLine}{\void}
Gets the last line of the file. Gets the last line of the file. Together with
\helpref{GetPrevLine}{wxtextfilegetprevline} it allows to enumerate the lines
in the file from the end to the beginning like this:
\begin{verbatim}
wxTextFile file;
...
for ( str = file.GetLastLine();
file.GetCurrentLine() > 0;
str = file.GetPrevLine() )
{
// do something with the current line in str
}
// do something with the first line in str
\end{verbatim}
\membersection{wxTextFile::GetLineType}\label{wxtextfilegetlinetype} \membersection{wxTextFile::GetLineType}\label{wxtextfilegetlinetype}

View File

@@ -41,7 +41,7 @@
//#define TEST_DIR //#define TEST_DIR
//#define TEST_DLLLOADER //#define TEST_DLLLOADER
//#define TEST_EXECUTE //#define TEST_EXECUTE
//#define TEST_FILE #define TEST_FILE
//#define TEST_FILECONF //#define TEST_FILECONF
//#define TEST_HASH //#define TEST_HASH
//#define TEST_LIST //#define TEST_LIST
@@ -56,7 +56,7 @@
//#define TEST_VCARD -- don't enable this (VZ) //#define TEST_VCARD -- don't enable this (VZ)
//#define TEST_WCHAR //#define TEST_WCHAR
//#define TEST_ZIP //#define TEST_ZIP
#define TEST_ZLIB //#define TEST_ZLIB
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// test class for container objects // test class for container objects
@@ -368,7 +368,7 @@ static void TestFileRead()
puts("File dump:\n----------"); puts("File dump:\n----------");
static const size_t len = 1024; static const off_t len = 1024;
char buf[len]; char buf[len];
for ( ;; ) for ( ;; )
{ {
@@ -404,6 +404,24 @@ static void TestTextFileRead()
{ {
printf("Number of lines: %u\n", file.GetLineCount()); printf("Number of lines: %u\n", file.GetLineCount());
printf("Last line: '%s'\n", file.GetLastLine().c_str()); printf("Last line: '%s'\n", file.GetLastLine().c_str());
wxString s;
puts("\nDumping the entire file:");
for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
{
printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
}
printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
puts("\nAnd now backwards:");
for ( s = file.GetLastLine();
file.GetCurrentLine() != 0;
s = file.GetPrevLine() )
{
printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
}
printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
} }
else else
{ {
@@ -3505,7 +3523,8 @@ int main(int argc, char **argv)
#endif // TEST_LOG #endif // TEST_LOG
#ifdef TEST_FILE #ifdef TEST_FILE
TestFileRead(); if ( 0 )
TestFileRead();
TestTextFileRead(); TestTextFileRead();
#endif // TEST_FILE #endif // TEST_FILE