Whitespace massaging modifications.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@309 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
2001-08-21 Michael Bayne <mdb@bering>
|
||||
|
||||
* src/querybox.c: Massage the selection somewhat by converting
|
||||
newlines to spaces and if we believe that we're looking at a URL,
|
||||
by removing spaces.
|
||||
|
||||
2001-08-17 Michael Bayne <mdb@bering>
|
||||
|
||||
* src/lookuplet.c: Got support for running as an applet working
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
- Convert newlines to spaces when grabbing the selection. If we think that
|
||||
the selection is a URL (it starts with http: etc.), then we remove
|
||||
spaces as well.
|
||||
|
||||
* lookuplet-1.1 (2001-08-17)
|
||||
|
||||
- Fixed support for running as an applet and made the code automatically
|
||||
@@ -9,4 +13,4 @@
|
||||
|
||||
- Initial release.
|
||||
|
||||
$Id: NEWS,v 1.3 2001/08/18 02:39:36 mdb Exp $
|
||||
$Id: NEWS,v 1.4 2001/08/21 18:46:10 mdb Exp $
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* $Id: querybox.c,v 1.7 2001/08/18 02:34:06 mdb Exp $
|
||||
* $Id: querybox.c,v 1.8 2001/08/21 18:46:10 mdb Exp $
|
||||
*
|
||||
* lookuplet - a utility for quickly looking up information
|
||||
* Copyright (C) 2001 Michael Bayne
|
||||
@@ -34,15 +34,32 @@
|
||||
|
||||
static GtkWidget* _query;
|
||||
|
||||
/* used by url_p */
|
||||
#define MATCH_PREFIX(text, prefix) !strncmp(text, prefix, sizeof(prefix)-1)
|
||||
|
||||
/**
|
||||
* A very primitive function to try to determine if the selection is a URL
|
||||
* of some sort.
|
||||
*/
|
||||
static int
|
||||
url_p (const char* text)
|
||||
{
|
||||
return (MATCH_PREFIX(text, "http://") ||
|
||||
MATCH_PREFIX(text, "ftp://") ||
|
||||
MATCH_PREFIX(text, "https://") ||
|
||||
MATCH_PREFIX(text, "file:/"));
|
||||
}
|
||||
|
||||
static void
|
||||
selection_received (GtkWidget* widget, GtkSelectionData* selection_data,
|
||||
gpointer data)
|
||||
{
|
||||
int length = selection_data->length;
|
||||
int is_url;
|
||||
|
||||
/* make sure some selection was provided */
|
||||
if (length > 0) {
|
||||
gchar* start, *end;
|
||||
gchar* start, *end, *pos;
|
||||
gchar* search_text =
|
||||
gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
|
||||
|
||||
@@ -51,6 +68,21 @@ selection_received (GtkWidget* widget, GtkSelectionData* selection_data,
|
||||
for (end = search_text + length - 1; isspace(*end); end--);
|
||||
end++; *end = '\0';
|
||||
|
||||
/* check to see if we're looking at a url here */
|
||||
is_url = url_p(start);
|
||||
|
||||
/* do some whitespace processing */
|
||||
for (pos = start; *pos != '\0'; pos++) {
|
||||
/* convert newlines to spaces */
|
||||
if ((*pos == '\n') || (*pos == '\r')) {
|
||||
*pos = ' ';
|
||||
}
|
||||
/* if this is a URL, we want to eat whitespace */
|
||||
if (*pos == ' ' && is_url) {
|
||||
memmove(pos, pos+1, strlen(pos));
|
||||
}
|
||||
}
|
||||
|
||||
/* only set the new text if we changed anything */
|
||||
if (length != strlen(start)) {
|
||||
length = strlen(start);
|
||||
|
||||
Reference in New Issue
Block a user