]> git.lyx.org Git - features.git/commitdiff
Implement buffer-anonymize more efficiently
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 15 Feb 2018 11:07:33 +0000 (12:07 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 15 Feb 2018 11:07:33 +0000 (12:07 +0100)
The work is done now in Paragraph::anonymize().

Move the handling of the lfun to Buffer class.

Document the new feature in release notes.

(cherry picked from commit 1dba36c7cec6aeec2576e7a99e2967e867076a01)

lib/RELEASE-NOTES
src/Buffer.cpp
src/BufferView.cpp
src/Paragraph.cpp
src/Paragraph.h

index 59325c3bd2813f66033893d75ca61ccd93867d73..a48968b24d24c5df432642a5695bd0b4d1e6efb8 100644 (file)
   opened in editable mode. This state used to be hardcoded at compile
   time.
 
+* buffer-anonymize (2.3.2)
+  Replace all text n the document by streams of `a'. This is useful
+  for sharing private documents in a bug report.
+
 * font-crossout
   Cross out characters.
 
index ca3c049b4dbd096c03cfba779a7d8a2db7b1e44b..1ae48acc8a8f20917751375d078db3b946bb5b10 100644 (file)
@@ -2612,15 +2612,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;
@@ -2898,6 +2899,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;
index bf7c1ea165f9a32ebbc0dea5df1c72a1d36e4e1f..e141f34c7ec3784864a547f0014b7e0384b45463 100644 (file)
@@ -1112,7 +1112,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:
@@ -1576,14 +1575,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()));
-               }
-       }
-
        case LFUN_WORD_FINDADV: {
                FindAndReplaceOptions opt;
                istringstream iss(to_utf8(cmd.argument()));
index 5c5a728027f3c4cd4f9201749c44334394a75fdb..c905856e9cbb3de632370610807e3da67b07d071 100644 (file)
@@ -4176,6 +4176,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,
index d462f4c41356cfdbeb18468a744abfbeb8e8b062..0c6c48090f4da587e5d63547e15643177b648f34 100644 (file)
@@ -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 &,