Added locked pattern to extended search.
[claws.git] / src / common / utils.c
index 7c2873680ed4a979bcf3b1c182f52039d9464ab4..3ce408aa0131e7a21e42ba8520b6fff2a71dd543 100644 (file)
@@ -470,52 +470,29 @@ wchar_t *wcscasestr(const wchar_t *haystack, const wchar_t *needle)
 }
 
 /* Examine if next block is non-ASCII string */
-gboolean is_next_nonascii(const wchar_t *s)
+gboolean is_next_nonascii(const guchar *s)
 {
-       const wchar_t *wp;
+       const guchar *p;
 
        /* skip head space */
-       for (wp = s; *wp != (wchar_t)0 && iswspace(*wp); wp++)
+       for (p = s; *p != '\0' && isspace(*p); p++)
                ;
-       for (; *wp != (wchar_t)0 && !iswspace(*wp); wp++) {
-               if (*wp > 127)
+       for (; *p != '\0' && !isspace(*p); p++) {
+               if (*p > 127 || *p < 32)
                        return TRUE;
        }
 
        return FALSE;
 }
 
-/* Examine if next block is multi-byte string */
-gboolean is_next_mbs(const wchar_t *s)
+gint get_next_word_len(const gchar *s)
 {
-       gint mbl;
-       const wchar_t *wp;
-       gchar tmp[MB_LEN_MAX];
+       gint len = 0;
 
-       /* skip head space */
-       for (wp = s; *wp != (wchar_t)0 && iswspace(*wp); wp++)
-               ;
-       for (; *wp != (wchar_t)0 && !iswspace(*wp); wp++) {
-               mbl = wctomb(tmp, *wp);
-               if (mbl > 1)
-                       return TRUE;
-       }
-
-       return FALSE;
-}
-
-wchar_t *find_wspace(const wchar_t *s)
-{
-       const wchar_t *wp;
-
-       for (wp = s; *wp != (wchar_t)0 && iswspace(*wp); wp++)
+       for (; *s != '\0' && !isspace(*s); s++, len++)
                ;
-       for (; *wp != (wchar_t)0; wp++) {
-               if (iswspace(*wp))
-                       return (wchar_t *)wp;
-       }
 
-       return NULL;
+       return len;
 }
 
 /* compare subjects */
@@ -2774,7 +2751,6 @@ void decode_uri(gchar *decoded_uri, const gchar *encoded_uri)
 
 gint open_uri(const gchar *uri, const gchar *cmdline)
 {
-       static gchar *default_cmdline = "netscape -remote openURL(%s,raise)";
        gchar buf[BUFFSIZE];
        gchar *p;
        gchar encoded_uri[BUFFSIZE];
@@ -2792,7 +2768,7 @@ gint open_uri(const gchar *uri, const gchar *cmdline)
                if (cmdline)
                        g_warning("Open URI command line is invalid: `%s'",
                                  cmdline);
-               g_snprintf(buf, sizeof(buf), default_cmdline, encoded_uri);
+               g_snprintf(buf, sizeof(buf), DEFAULT_BROWSER_CMD, encoded_uri);
        }
        
        execute_command_line(buf, TRUE);
@@ -3030,10 +3006,11 @@ FILE *get_tmpfile_in_dir(const gchar *dir, gchar **filename)
 /* allow Mutt-like patterns in quick search */
 gchar *expand_search_string(const gchar *search_string)
 {
-       int i, len, new_len = 0;
+       int i = 0;
        gchar term_char, save_char;
        gchar *cmd_start, *cmd_end;
-       gchar *new_str = NULL;
+       GString *matcherstr;
+       gchar *returnstr = NULL;
        gchar *copy_str;
        gboolean casesens, dontmatch;
        /* list of allowed pattern abbreviations */
@@ -3060,6 +3037,7 @@ gchar *expand_search_string(const gchar *search_string)
                { "h",  "headers_part",                 1,      TRUE,   TRUE  },
                { "i",  "header \"Message-Id\"",        1,      TRUE,   TRUE  },
                { "I",  "inreplyto",                    1,      TRUE,   TRUE  },
+               { "L",  "locked",                       0,      FALSE,  FALSE },
                { "n",  "newsgroups",                   1,      TRUE,   TRUE  },
                { "N",  "new",                          0,      FALSE,  FALSE },
                { "O",  "~new",                         0,      FALSE,  FALSE },
@@ -3101,6 +3079,7 @@ gchar *expand_search_string(const gchar *search_string)
        if (cmds[i].command)
                return copy_str;
 
+       matcherstr = g_string_sized_new(16);
        cmd_start = cmd_end = copy_str;
        while (cmd_end && *cmd_end) {
                /* skip all white spaces */
@@ -3136,26 +3115,15 @@ gchar *expand_search_string(const gchar *search_string)
                        if (!strcmp(cmd_start, cmds[i].abbreviated)) {
                                /* restore character */
                                *cmd_end = save_char;
-                               len = strlen(cmds[i].command) + 1;
-                               if (dontmatch)
-                                       len++;
-                               if (casesens)
-                                       len++;
 
                                /* copy command */
-                               if (new_str) {
-                                       new_len += 1;
-                                       new_str = g_realloc(new_str, new_len);
-                                       strcat(new_str, " ");
+                               if (matcherstr->len > 0) {
+                                       g_string_append(matcherstr, " ");
                                }
-                               new_len += (len + 1);
-                               new_str = g_realloc(new_str, new_len);
-                               if (new_len == len + 1)
-                                       *new_str = '\0';
                                if (dontmatch)
-                                       strcat(new_str, "~");
-                               strcat(new_str, cmds[i].command);
-                               strcat(new_str, " ");
+                                       g_string_append(matcherstr, "~");
+                               g_string_append(matcherstr, cmds[i].command);
+                               g_string_append(matcherstr, " ");
 
                                /* stop if no params required */
                                if (cmds[i].numparams == 0)
@@ -3184,33 +3152,23 @@ gchar *expand_search_string(const gchar *search_string)
                                save_char = *cmd_end;
                                *cmd_end = '\0';
 
-                               new_len += strlen(cmd_start);
-
-                               /* do we need to add regexpcase ? */
-                               if (cmds[i].qualifier)
-                                       new_len += 10; /* "regexpcase " */
-
-                               if (term_char != '"')
-                                       new_len += 2;
-                               new_str = g_realloc(new_str, new_len);
-
                                if (cmds[i].qualifier) {
                                        if (casesens)
-                                               strcat(new_str, "regexp ");
+                                               g_string_append(matcherstr, "regexp ");
                                        else
-                                               strcat(new_str, "regexpcase ");
+                                               g_string_append(matcherstr, "regexpcase ");
                                }
 
                                /* do we need to add quotes ? */
                                if (cmds[i].quotes && term_char != '"')
-                                       strcat(new_str, "\"");
+                                       g_string_append(matcherstr, "\"");
 
                                /* copy actual parameter */
-                               strcat(new_str, cmd_start);
+                               g_string_append(matcherstr, cmd_start);
 
                                /* do we need to add quotes ? */
                                if (cmds[i].quotes && term_char != '"')
-                                       strcat(new_str, "\"");
+                                       g_string_append(matcherstr, "\"");
 
                                /* restore original character */
                                *cmd_end = save_char;
@@ -3226,6 +3184,8 @@ gchar *expand_search_string(const gchar *search_string)
        }
 
        g_free(copy_str);
-       return new_str;
+       returnstr = matcherstr->str;
+       g_string_free(matcherstr, FALSE);
+       return returnstr;
 }