From: Dom Lachowicz (domlachowicz_at_yahoo.com)
Date: Sat Dec 13 2003 - 15:15:18 EST
Hi Jesper,
This code is really clean and we should definitely
work to move this into HEAD before 2.2 is out. I've
managed to re-integrate the patch into HEAD and fix
all of the SEGVs. Unfortunately, it still doesn't come
close to working properly.
I suppose I'll try to maintain this in one of my local
trees for the time being.
Dom
--- Jesper Skov <jskov_at_zoftcorp.dk> wrote:
> Hi
>
> I had some fun starting to rewrite the find/replace
> code. The core
> functionality is pretty much done (although some
> debugging may be
> needed). But now I lack the enthusiasm to complete
> it.
>
> Maybe someone here feels like picking up the pieces
> and completing the
> job?
>
> Looking at the new code and comparing it to the old
> code should provide
> you with the incitament. I find it much simpler and
> easier to understand
> than the old code. And I'm pretty sure it performs
> better as well. Oh,
> and it will allow programmed access to the
> find/replace functionality
> (which is why I started the rewrite).
>
> Some changes to the find/replace dialogs are needed
> to make the new
> iterator work as intended. Today, all dialogs set
> the search/replace
> string, even if these do not change. I started to
> change the GTK dialog
> to only set the strings if the user changed them,
> but didn't complete
> the task (as I recall). Other front ends need
> similar changes.
>
> There may be other stuff that needs to be done to
> make it all work. I'm
> available for answering questions if anyone should
> feel like making the
> last necessary changes.
>
> Cheers,
> Jesper
>
>
> > ? text/fmt/xp/Untitled1.abw.CRASHED
> Index: text/fmt/xp/GNUmakefile.am
>
===================================================================
> RCS file:
> /cvsroot/abi/src/text/fmt/xp/GNUmakefile.am,v
> retrieving revision 1.22
> diff -u -p -u -5 -p -r1.22 GNUmakefile.am
> --- text/fmt/xp/GNUmakefile.am 30 Nov 2003 14:23:10
> -0000 1.22
> +++ text/fmt/xp/GNUmakefile.am 3 Dec 2003 17:36:43
> -0000
> @@ -23,12 +23,13 @@ INCLUDES= $(TEXT_INCLUDES)
> $(WP_INCLUDES
> noinst_LIBRARIES = libFmt.a
>
> libFmt_a_SOURCES= \
> fv_View.cpp \
> fv_View_cmd.cpp \
> - fv_View_protected.cpp \
> + fv_View_protected.cpp \
> fv_View_TestRoutines.cpp \
> + fv_SearchReplace.cpp \
> fb_LineBreaker.cpp \
> fb_Alignment.cpp \
> fl_BlockLayout.cpp \
> fl_Squiggles.cpp \
> fl_DocLayout.cpp \
> Index: text/fmt/xp/fv_SearchReplace.cpp
>
===================================================================
> RCS file: text/fmt/xp/fv_SearchReplace.cpp
> diff -N text/fmt/xp/fv_SearchReplace.cpp
> --- text/fmt/xp/fv_SearchReplace.cpp 1 Jan 1970
> 00:00:00 -0000
> +++ text/fmt/xp/fv_SearchReplace.cpp 3 Dec 2003
> 17:36:44 -0000
> @@ -0,0 +1,578 @@
> +/* AbiWord
> + * Copyright (C) 2003 Jesper Skov
> + *
> + * This program is free software; you can
> redistribute it and/or
> + * modify it under the terms of the GNU General
> Public License
> + * as published by the Free Software Foundation;
> either version 2
> + * of the License, or (at your option) any later
> version.
> + *
> + * This program is distributed in the hope that it
> will be useful,
> + * but WITHOUT ANY WARRANTY; without even the
> implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU
> General Public License
> + * along with this program; if not, write to the
> Free Software
> + * Foundation, Inc., 59 Temple Place - Suite 330,
> Boston, MA
> + * 02111-1307, USA.
> + */
> +
> +#include "fv_View.h"
> +#include "fv_SearchReplace.h"
> +
> +#include "ut_debugmsg.h"
> +#include "ut_assert.h"
> +#include "ut_string.h"
> +
> +/*! \page searchreplace_overview Search and Replace
> +
> +The search/replace code is using a one-way iterator
> to work its way
> +through the document looking for matches. The
> (forward and backward)
> +iterators take care of skipping to the next block
> when required.
> +
> +*/
> +
> +/******************************
> +Problems in old code:
> +
> + o New doc, "test test|", reverse search for "test"
> causes assertion
> + and crash!
> + o Reverse find does not find word at start of line
> + o Reverse find does not find word at end of line
> + o (untested) Reverse replace should not stop at
> correct position
> +
> +Problems in new code:
> +
> + o last block, start pos > than maxOffset -> will
> never terminate
> + o dialog needs to set new pos -> new iterator ->
> old iterator starting point/wrap state is lost
> + (see ap_Dialog_Replace.cpp/h +
> ap_UnixDialog_Replace.cpp/h)
> +
> +
> +*******************************/
> +
> +/*!
> + Find next occurrence of string in document and
> select it.
> + \return true if a match was found, otherwise
> false.
> +*/
> +bool
> +fv_SearchReplace::findAndSelect(void)
> +{
> + if (!find()) return false;
> +
> + fv_SearchReplaceBufferIterator* ix =
> getIterator();
> + FV_View* pView = getView();
> + pView->_setPoint(ix->getPos());
> + pView->_setSelectionAnchor();
> + pView->_charMotion(!isReverse(),
> getSearchStrLen());
> +
> + return true;
> +}
> +
> +/*!
> + Find next occurrence of string in document.
> + \return true if match was found, otherwise false.
> +*/
> +bool
> +fv_SearchReplace::find(void)
> +{
> + _setFound(false);
> +
> + const UT_UCSChar* pSearch = getSearchString();
> + const UT_sint32 iSearchLen = getSearchStrLen();
> + const UT_UCSChar firstChar = pSearch[0];
> +
> + fv_SearchReplaceBufferIterator* ix =
> getIterator();
> + UT_UCSChar currentChar;
> + // First find match on first character of
> string
> +
> + if (!ix->getCurrentChar(currentChar))
> + {
> + return false;
> + }
> +
> + do
> + {
> + if (currentChar == UCS_RQUOTE) currentChar
> = '\'';
> + if (!isCaseSensitive()) currentChar =
> UT_UCS4_tolower(currentChar);
> +
> + if (currentChar != firstChar) continue;
> +
> + // Then try to match of the remainder of
> the string
> + UT_sint32 iMatchLen = 1;
> + while (iMatchLen < iSearchLen)
> + {
> + currentChar =
> ix->getAtOffset(iMatchLen);
> + if (currentChar == UCS_RQUOTE)
> currentChar = '\'';
> + if (!isCaseSensitive()) currentChar =
> UT_UCS4_tolower(currentChar);
> +
> + if (currentChar != pSearch[iMatchLen])
> break;
> +
> + iMatchLen++;
> + }
> +
> + if (iMatchLen == iSearchLen)
> + {
> + if (!isWholeWord()
> + ||
> (UT_isWordDelimiter(ix->getAtOffset(-1),
> UCS_UNKPUNK, UCS_UNKPUNK)
> + &&
> UT_isWordDelimiter(ix->getAtOffset(iMatchLen),
> UCS_UNKPUNK, UCS_UNKPUNK)))
> + {
> + _setFound(true);
> + return true;
> + }
> + }
> + } while (ix->step(currentChar));
> +
> + return false;
> +}
> +
> +
> +/*!
> + Find and replace text string
>
=== message truncated ===
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
This archive was generated by hypermail 2.1.4 : Sat Dec 13 2003 - 15:14:40 EST