diff gui/util/string.c @ 33048:c6d0adf896ea

Move auxiliary string functions into separate file. (Besides, name parameters more intelligibly.)
author ib
date Mon, 28 Mar 2011 15:51:20 +0000
parents
children fc7a3f9f74f8
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui/util/string.c	Mon Mar 28 15:51:20 2011 +0000
@@ -0,0 +1,59 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stddef.h>
+#include <string.h>
+
+#include "string.h"
+
+char *strswap(char *in, char from, char to)
+{
+    int i;
+
+    if (!*in)
+        return NULL;
+
+    for (i = 0; in[i]; i++)
+        if (in[i] == from)
+            in[i] = to;
+
+    return in;
+}
+
+char *trim(char *in)
+{
+    int c = 0, id = 0, i;
+
+    if (!*in)
+        return NULL;
+
+    while (c != (int)strlen(in)) {
+        if (in[c] == '"')
+            id = !id;
+
+        if ((in[c] == ' ') && (!id)) {
+            for (i = 0; i < (int)strlen(in) - c; i++)
+                in[c + i] = in[c + i + 1];
+            continue;
+        }
+
+        c++;
+    }
+
+    return in;
+}