[gmime] Disable GMimeStreamNull counting newlines by default



commit 69aecca085f94cd2786bb6f30d25a7b6cfef3b98
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Sun Mar 19 14:58:06 2017 -0400

    Disable GMimeStreamNull counting newlines by default

 gmime/gmime-stream-null.c |   46 +++++++++++++++++++++++++++++++++++++++++---
 gmime/gmime-stream-null.h |    6 +++++
 2 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/gmime/gmime-stream-null.c b/gmime/gmime-stream-null.c
index deed77c..26ac924 100644
--- a/gmime/gmime-stream-null.c
+++ b/gmime/gmime-stream-null.c
@@ -113,6 +113,7 @@ g_mime_stream_null_init (GMimeStreamNull *stream, GMimeStreamNullClass *klass)
 {
        stream->written = 0;
        stream->newlines = 0;
+       stream->count_newlines = FALSE;
 }
 
 static void
@@ -139,10 +140,12 @@ stream_write (GMimeStream *stream, const char *buf, size_t len)
        register const char *inptr = buf;
        const char *inend = buf + len;
        
-       while (inptr < inend) {
-               if (*inptr == '\n')
-                       null->newlines++;
-               inptr++;
+       if (null->count_newlines) {
+               while (inptr < inend) {
+                       if (*inptr == '\n')
+                               null->newlines++;
+                       inptr++;
+               }
        }
        
        null->written += len;
@@ -252,3 +255,38 @@ g_mime_stream_null_new (void)
        
        return null;
 }
+
+
+/**
+ * g_mime_stream_null_set_count_newlines:
+ * @stream: a #GMimeStreamNull
+ * @count: %TRUE if newlines should be counted or %FALSE otherwise
+ *
+ * Sets whether or not the stream should keep track of the number of newlines
+ * encountered.
+ **/
+void
+g_mime_stream_null_count_newlines (GMimeStreamNull *stream, gboolean count)
+{
+       g_return_if_fail (GMIME_IS_STREAM_NULL (stream));
+       
+       stream->count_newlines = count;
+}
+
+
+/**
+ * g_mime_stream_null_get_count_newlines:
+ * @stream: a #GMimeStreamNull
+ *
+ * Gets whether or not the stream should keep track of the number of newlines
+ * encountered.
+ *
+ * Returns: %TRUE if the stream should count the number of newlines or %FALSE otherwise.
+ **/
+gboolean
+g_mime_stream_null_get_count_newlines (GMimeStreamNull *stream)
+{
+       g_return_val_if_fail (GMIME_IS_STREAM_NULL (stream), FALSE);
+       
+       return stream->count_newlines;
+}
diff --git a/gmime/gmime-stream-null.h b/gmime/gmime-stream-null.h
index b4dc0ad..bf46478 100644
--- a/gmime/gmime-stream-null.h
+++ b/gmime/gmime-stream-null.h
@@ -42,6 +42,7 @@ typedef struct _GMimeStreamNullClass GMimeStreamNullClass;
  * @parent_object: parent #GMimeStream
  * @written: number of bytes written to this stream
  * @newlines: the number of newlines written to this stream
+ * @count_newlines: whether or not the stream should count newlines
  *
  * A #GMimeStream which has no backing store.
  **/
@@ -50,6 +51,8 @@ struct _GMimeStreamNull {
        
        size_t written;
        size_t newlines;
+       
+       gboolean count_newlines;
 };
 
 struct _GMimeStreamNullClass {
@@ -62,6 +65,9 @@ GType g_mime_stream_null_get_type (void);
 
 GMimeStream *g_mime_stream_null_new (void);
 
+void g_mime_stream_null_set_count_newlines (GMimeStreamNull *stream, gboolean count);
+gboolean g_mime_stream_null_get_count_newlines (GMimeStreamNull *stream);
+
 G_END_DECLS
 
 #endif /* __GMIME_STREAM_NULL_H__ */


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