[geany/geany] 43c49b: Make sci_get_contents() accept -1 for buffer_len to get all text

Nick Treleaven git-noreply at geany.org
Wed Nov 21 13:34:39 UTC 2012


Branch:      refs/heads/master
Author:      Nick Treleaven <nick.treleaven at btinternet.com>
Committer:   Nick Treleaven <nick.treleaven at btinternet.com>
Date:        Wed, 21 Nov 2012 13:34:39 UTC
Commit:      43c49ba46d79e57314fd977465dd3819c2522c4f
             https://github.com/geany/geany/commit/43c49ba46d79e57314fd977465dd3819c2522c4f

Log Message:
-----------
Make sci_get_contents() accept -1 for buffer_len to get all text


Modified Paths:
--------------
    src/sciwrappers.c
    src/tools.c

Modified: src/sciwrappers.c
18 files changed, 12 insertions(+), 6 deletions(-)
===================================================================
@@ -592,14 +592,21 @@ void sci_get_text(ScintillaObject *sci, gint len, gchar *text)
 
 /** Allocates and fills a buffer with text from the start of the document.
  * @param sci Scintilla widget.
- * @param buffer_len Buffer length to allocate, usually sci_get_length() + 1.
+ * @param buffer_len Buffer length to allocate, including the terminating
+ * null char, e.g. sci_get_length() + 1. Alternatively use @c -1 to get all
+ * text (since Geany 1.23).
  * @return A copy of the text. Should be freed when no longer needed.
  *
- * @since 0.17
+ * @since 1.23 (0.17)
  */
 gchar *sci_get_contents(ScintillaObject *sci, gint buffer_len)
 {
-	gchar *text = g_malloc(buffer_len);
+	gchar *text;
+
+	if (buffer_len < 0)
+		buffer_len = sci_get_length(sci) + 1;
+
+	text = g_malloc(buffer_len);
 	SSM(sci, SCI_GETTEXT, (uptr_t) buffer_len, (sptr_t) text);
 	return text;
 }
@@ -926,10 +933,9 @@ void sci_get_text_range(ScintillaObject *sci, gint start, gint end, gchar *text)
 
 
 /** Gets text between @a start and @a end.
- *
  * @param sci Scintilla widget.
- * @param start Start.
- * @param end End.
+ * @param start Start position.
+ * @param end End position.
  * @return The text inside the given range. Should be freed when no longer needed.
  *
  * @since 0.17


Modified: src/tools.c
6 files changed, 2 insertions(+), 4 deletions(-)
===================================================================
@@ -848,14 +848,12 @@ void tools_word_count(void)
 
 	if (sci_has_selection(doc->editor->sci))
 	{
-		text = g_malloc0(sci_get_selected_text_length(doc->editor->sci) + 1);
-		sci_get_selected_text(doc->editor->sci, text);
+		text = sci_get_selection_contents(doc->editor->sci);
 		range = _("selection");
 	}
 	else
 	{
-		text = g_malloc(sci_get_length(doc->editor->sci) + 1);
-		sci_get_text(doc->editor->sci, sci_get_length(doc->editor->sci) + 1 , text);
+		text = sci_get_contents(doc->editor->sci, -1);
 		range = _("whole document");
 	}
 	word_count(text, &chars, &lines, &words);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).


More information about the Commits mailing list