[geary/wip/362-utf8-attachments: 2/8] Update Buffer UTF-8 conversion APIs



commit 069763235879e7a1572d454aec14ac96d6850125
Author: Michael Gratton <mike vee net>
Date:   Thu Jul 18 15:55:09 2019 +1000

    Update Buffer UTF-8 conversion APIs
    
    Use GLib.string.make_valid() to ensure buffer strings are UTF-8 since
    that tries a bit harder to retain valid chars. Remove unowned version
    since callers can just use make_valid themselves if needed.

 src/engine/memory/memory-buffer.vala                | 18 +++++++-----------
 src/engine/memory/memory-unowned-string-buffer.vala |  9 ---------
 2 files changed, 7 insertions(+), 20 deletions(-)
---
diff --git a/src/engine/memory/memory-buffer.vala b/src/engine/memory/memory-buffer.vala
index e566a281..9b4527f3 100644
--- a/src/engine/memory/memory-buffer.vala
+++ b/src/engine/memory/memory-buffer.vala
@@ -101,19 +101,15 @@ public abstract class Geary.Memory.Buffer : BaseObject {
     }
 
     /**
-     * Returns a copy of the contents of the buffer as though it was a UTF-8 string.
+     * Returns a copy of the contents of the buffer as a UTF-8 string.
      *
-     * The base class implementation uses {@link get_bytes} to create the InputStream.  Subclasses
-     * should look for more optimal implementations.
-     *
-     * If the conversion fails or decodes as invalid UTF-8, an empty string is returned.
-     *
-     * @see UnownedStringBuffer.get_unowned_valid_utf8
+     * The base class implementation uses {@link to_string} to create
+     * the string and and {@link GLib.string.make_valid} to perform
+     * the validation.  Subclasses should look for more optimal
+     * implementations.
      */
     public virtual string get_valid_utf8() {
-        string str = to_string();
-
-        return str.validate() ? str : "";
+        return to_string().make_valid();
     }
-}
 
+}
diff --git a/src/engine/memory/memory-unowned-string-buffer.vala 
b/src/engine/memory/memory-unowned-string-buffer.vala
index c3721ca8..372b1e1e 100644
--- a/src/engine/memory/memory-unowned-string-buffer.vala
+++ b/src/engine/memory/memory-unowned-string-buffer.vala
@@ -22,13 +22,4 @@ public interface Geary.Memory.UnownedStringBuffer : Memory.Buffer {
      */
     public abstract unowned string to_unowned_string();
 
-    /**
-     * An unowned version of {@link Memory.Buffer.get_valid_utf8}.
-     */
-    public virtual unowned string get_unowned_valid_utf8() {
-        string str = to_unowned_string();
-
-        return str.validate() ? str : "";
-    }
 }
-


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]