From 0b397099c74e670e457f369d9f38574a6321085c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 27 Jul 2000 14:01:59 +0000 Subject: [PATCH] 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 --- docs/latex/wx/textfile.tex | 21 +++++++++++++++++++-- samples/console/console.cpp | 27 +++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/docs/latex/wx/textfile.tex b/docs/latex/wx/textfile.tex index ff7ecc856f..7cd79b94a0 100644 --- a/docs/latex/wx/textfile.tex +++ b/docs/latex/wx/textfile.tex @@ -189,10 +189,13 @@ allows more "iterator-like" traversal of the list of lines, i.e. you may write something like: \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 last line in str \end{verbatim} \membersection{wxTextFile::GetNextLine}\label{wxtextfilegetnextline} @@ -212,7 +215,21 @@ Gets the previous line in the file. \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} diff --git a/samples/console/console.cpp b/samples/console/console.cpp index dfd10befa1..a935db655f 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -41,7 +41,7 @@ //#define TEST_DIR //#define TEST_DLLLOADER //#define TEST_EXECUTE -//#define TEST_FILE +#define TEST_FILE //#define TEST_FILECONF //#define TEST_HASH //#define TEST_LIST @@ -56,7 +56,7 @@ //#define TEST_VCARD -- don't enable this (VZ) //#define TEST_WCHAR //#define TEST_ZIP -#define TEST_ZLIB +//#define TEST_ZLIB // ---------------------------------------------------------------------------- // test class for container objects @@ -368,7 +368,7 @@ static void TestFileRead() puts("File dump:\n----------"); - static const size_t len = 1024; + static const off_t len = 1024; char buf[len]; for ( ;; ) { @@ -404,6 +404,24 @@ static void TestTextFileRead() { printf("Number of lines: %u\n", file.GetLineCount()); 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 { @@ -3505,7 +3523,8 @@ int main(int argc, char **argv) #endif // TEST_LOG #ifdef TEST_FILE - TestFileRead(); + if ( 0 ) + TestFileRead(); TestTextFileRead(); #endif // TEST_FILE