Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=2dc5b65a60e612dbbdfe748e0c02e467eec60827
commit 2dc5b65a60e612dbbdfe748e0c02e467eec60827 Author: Michel Hermier <[email protected]> Date: Fri Nov 29 13:17:59 2013 +0100 libpacman: Make f_strtrim of _pacman_strtrim. diff --git a/lib/libpacman/CMakeLists.txt b/lib/libpacman/CMakeLists.txt index ed213df..7614e0e 100644 --- a/lib/libpacman/CMakeLists.txt +++ b/lib/libpacman/CMakeLists.txt @@ -19,6 +19,7 @@ set(LIBPACMAN_SOURCES util/log.c util/stringlist.c util/time.c + fstring.c add.c be_files.c cache.c diff --git a/lib/libpacman/fstring.c b/lib/libpacman/fstring.c new file mode 100644 index 0000000..035a313 --- /dev/null +++ b/lib/libpacman/fstring.c @@ -0,0 +1,62 @@ +/* + * fstring.c + * + * Copyright (c) 2013 by Michel Hermier <[email protected]> + * + * 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 "config.h" + +#include <ctype.h> + +#include "fstring.h" + +#include "fstdlib.h" + +/* Trim whitespace and newlines from a string + */ +char *f_strtrim(char *str) +{ + char *pch = str; + + if(f_strempty(str)) { + /* string is empty, so we're done. */ + return(str); + } + + while(isspace((int)*pch)) { + pch++; + } + if(pch != str) { + memmove(str, pch, (strlen(pch) + 1)); + } + + /* check if there wasn't anything but whitespace in the string. */ + if(f_strempty(str)) { + return(str); + } + + pch = (char *)(str + (strlen(str) - 1)); + while(isspace((int)*pch)) { + pch--; + } + *++pch = '\0'; + + return(str); +} + +/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/fstring.h b/lib/libpacman/fstring.h index 8188027..ed897b5 100644 --- a/lib/libpacman/fstring.h +++ b/lib/libpacman/fstring.h @@ -23,6 +23,8 @@ #include <string.h> +#define _pacman_strtrim f_strtrim + static inline int f_strempty(const char *s) { @@ -35,6 +37,8 @@ size_t f_strlen(const char *s) return s != NULL ? strlen(s) : 0; } +char *f_strtrim(char *str); + #endif /* _F_STRING_H */ /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/util.h b/lib/libpacman/util.h index 103de74..d2ca11f 100644 --- a/lib/libpacman/util.h +++ b/lib/libpacman/util.h @@ -66,7 +66,6 @@ char *_pacman_basename(const char *path); int _pacman_makepath(char *path); int _pacman_copyfile(char *src, char *dest); char *_pacman_strtoupper(char *str); -char *_pacman_strtrim(char *str); int _pacman_lckmk(char *file); int _pacman_lckrm(char *file); int _pacman_unpack(const char *archive, const char *prefix, const char *fn); _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
