From 7a3feb12511fa02361f3cdd0e62396c084b143ad Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 10 Dec 2008 19:47:25 +0100 Subject: [PATCH] list_window: moved string matching to match.h Provide the new function match_line() which searches a string for a needle (ignoring case). This wraps the non-standard function strcasestr(). --- src/Makefile.am | 2 ++ src/list_window.c | 6 +++--- src/match.c | 28 ++++++++++++++++++++++++++++ src/match.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/match.c create mode 100644 src/match.h diff --git a/src/Makefile.am b/src/Makefile.am index ac34b85..a53e5d0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,7 @@ ncmpc_headers = \ colors.h\ support.h\ charset.h \ + match.h \ wreadln.h\ strfsong.h\ utils.h\ @@ -67,6 +68,7 @@ ncmpc_SOURCES = \ colors.c\ support.c\ charset.c \ + match.c \ wreadln.c\ strfsong.c\ utils.c\ diff --git a/src/list_window.c b/src/list_window.c index ea4b3c2..010deb8 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -20,7 +20,7 @@ #include "config.h" #include "options.h" #include "charset.h" -#include "support.h" +#include "match.h" #include "command.h" #include "colors.h" @@ -223,7 +223,7 @@ list_window_find(struct list_window *lw, do { while ((label = callback(i,&h,callback_data))) { - if (str && label && strcasestr(label, str)) { + if (str && label && match_line(label, str)) { lw->selected = i; return true; } @@ -259,7 +259,7 @@ list_window_rfind(struct list_window *lw, do { while (i >= 0 && (label = callback(i,&h,callback_data))) { - if( str && label && strcasestr(label, str) ) { + if( str && label && match_line(label, str) ) { lw->selected = i; return true; } diff --git a/src/match.c b/src/match.c new file mode 100644 index 0000000..e414d85 --- /dev/null +++ b/src/match.c @@ -0,0 +1,28 @@ +/* + * (c) 2008 Max Kellermann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "match.h" +#include "support.h" + +#include + +bool +match_line(const char *line, const char *needle) +{ + return strcasestr(line, needle) != NULL; +} diff --git a/src/match.h b/src/match.h new file mode 100644 index 0000000..1bb6ca3 --- /dev/null +++ b/src/match.h @@ -0,0 +1,31 @@ +/* + * (c) 2008 Max Kellermann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef MATCH_H +#define MATCH_H + +#include + +/** + * Checks whether the specified line matches the search string. Case + * is ignored. + */ +bool +match_line(const char *line, const char *needle); + +#endif -- 2.30.2