commit 1dba36c7cec6aeec2576e7a99e2967e867076a01
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Wed Feb 7 15:35:46 2018 +0100

    Implement buffer-anonymize more efficiently
    
    The work is done now in Paragraph::anonymize().
    
    Move the handling of the lfun to Buffer class.
---
 src/Buffer.cpp     |   18 ++++++++++++++----
 src/BufferView.cpp |   10 ----------
 src/Paragraph.cpp  |    9 +++++++++
 src/Paragraph.h    |    4 ++++
 4 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index f42233f..7cabe6f 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -2569,15 +2569,16 @@ bool Buffer::getStatus(FuncRequest const & cmd, 
FuncStatus & flag)
                flag.setOnOff(params().output_changes);
                break;
 
-       case LFUN_BUFFER_TOGGLE_COMPRESSION: {
+       case LFUN_BUFFER_TOGGLE_COMPRESSION:
                flag.setOnOff(params().compressed);
                break;
-       }
 
-       case LFUN_BUFFER_TOGGLE_OUTPUT_SYNC: {
+       case LFUN_BUFFER_TOGGLE_OUTPUT_SYNC:
                flag.setOnOff(params().output_sync);
                break;
-       }
+
+       case LFUN_BUFFER_ANONYMIZE:
+               break;
 
        default:
                return false;
@@ -2849,6 +2850,15 @@ void Buffer::dispatch(FuncRequest const & func, 
DispatchResult & dr)
                params().output_sync = !params().output_sync;
                break;
 
+       case LFUN_BUFFER_ANONYMIZE: {
+               undo().recordUndoFullBuffer(CursorData());
+               CursorData cur(doc_iterator_begin(this));
+               for ( ; cur ; cur.forwardPar())
+                       cur.paragraph().anonymize();
+               dr.forceBufferUpdate();
+               break;
+       }
+
        default:
                dispatched = false;
                break;
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 0f4b634..7d7dc7f 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1134,7 +1134,6 @@ bool BufferView::getStatus(FuncRequest const & cmd, 
FuncStatus & flag)
        case LFUN_WORD_FIND_FORWARD:
        case LFUN_WORD_FIND_BACKWARD:
        case LFUN_WORD_REPLACE:
-       case LFUN_BUFFER_ANONYMIZE:
        case LFUN_MARK_OFF:
        case LFUN_MARK_ON:
        case LFUN_MARK_TOGGLE:
@@ -1622,15 +1621,6 @@ void BufferView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
                break;
        }
 
-       case LFUN_BUFFER_ANONYMIZE: {
-               for (char c = '0'; c <= 'Z'; c++) {
-                       odocstringstream ss;
-                       ss << "a\n" << c << "\n0 0 1 1 0";
-                       lyx::dispatch(FuncRequest(LFUN_WORD_REPLACE, ss.str()));
-               }
-               break;
-       }
-
        case LFUN_WORD_FINDADV: {
                FindAndReplaceOptions opt;
                istringstream iss(to_utf8(cmd.argument()));
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 4ee612b..bc7bbee 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -4148,6 +4148,15 @@ SpellChecker::Result Paragraph::spellCheck(pos_type & 
from, pos_type & to,
 }
 
 
+void Paragraph::anonymize()
+{
+       // This is a very crude anonymization for now
+       for (char_type & c : d->text_)
+               if (isLetterChar(c) || isNumber(c))
+                       c = 'a';
+}
+
+
 void Paragraph::Private::markMisspelledWords(
        pos_type const & first, pos_type const & last,
        SpellChecker::Result result,
diff --git a/src/Paragraph.h b/src/Paragraph.h
index 790c3f2..84fcf75 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -505,6 +505,10 @@ public:
        /// presently used only in the XHTML output routines.
        std::string magicLabel() const;
 
+       /// anonymizes the paragraph contents (but not the paragraphs
+       /// contained inside it. Does not handle undo.
+       void anonymize();
+
 private:
        /// Expand the counters for the labelstring of \c layout
        docstring expandParagraphLabel(Layout const &, BufferParams const &,

Reply via email to