Set len to 0 if string is empty.
[lms] / lightmediascanner / src / lib / lightmediascanner_utils.c
index 4024ca1..103af44 100644 (file)
@@ -1,7 +1,34 @@
+/**
+ * Copyright (C) 2007 by INdT
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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 Lesser 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.
+ *
+ * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
+ */
+
 #include <lightmediascanner_utils.h>
 #include <ctype.h>
 #include <alloca.h>
 
+/**
+ * Strips string, in place.
+ *
+ * @param str string to be stripped.
+ * @param p_len string length to analyse, also the place where the final size
+ *        is stored.
+ */
 void
 lms_strstrip(char *str, unsigned int *p_len)
 {
@@ -10,12 +37,17 @@ lms_strstrip(char *str, unsigned int *p_len)
 
     len = *p_len;
 
-    if (len < 2) /* just '\0'? */
+    if (len == 0)
         return;
 
+    if (*str == '\0') {
+        *p_len = 0;
+        return;
+    }
+
     p = str + len - 1;
     for (i = len - 1; i >= 0; i--) {
-        if (isspace(*p)) {
+        if (isspace(*p) || *p == '\0') {
             *p = '\0';
             len--;
             p--;
@@ -48,6 +80,16 @@ lms_strstrip(char *str, unsigned int *p_len)
             *str = *p;
 }
 
+/**
+ * Find out which of the given extensions matches the given name.
+ *
+ * @param name string to analyse.
+ * @param name_len string length.
+ * @param exts array of extensions to be checked.
+ * @param exts_len number of items in array @p exts
+ *
+ * @return index in @p exts or -1 if it doesn't match none.
+ */
 int
 lms_which_extension(const char *name, unsigned int name_len, const struct lms_string_size *exts, unsigned int exts_len) {
     int i;