[Github-comments] [geany-plugins] Add new "Lineoperations" plugin (#324)

Matthew Brush notifications at xxxxx
Wed Jan 13 00:21:32 UTC 2016


> +	newfile       = g_malloc(sizeof(gchar) * (totalnumchars+1));
> +	numlines      = 0;
> +	nfposn        = 0;
> +	k             = 0;
> +
> +	if(newfile && lines)    // verify memory allocation
> +	{
> +		// copy *all* lines into **lines array
> +		for(i = 0; i < totalnumlines; i++)
> +			lines[numlines++] = sci_get_line(doc->editor->sci, i);
> +
> +		qsort(lines, numlines, sizeof(gchar *), compareasc);
> +
> +		if(numlines > 0)	// copy the first line into *newfile
> +			for(j = 0; lines[0][j] != '\0'; j++)
> +				newfile[nfposn++] = lines[0][j];

> mostly for joining array of lines into new_file string

Not sure if it's applicable here (didn't really look at the code), but if you can enforce the last array element is `NULL`, you could maybe use [`g_strjoinv()`](https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strjoinv) and using `\n` as the `separator` argument.

---
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/324/files#r49536019
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20160112/97bb97e1/attachment.html>


More information about the Github-comments mailing list