Mercurial > libavutil.hg
comparison string.c @ 347:2fb35d82b0bd libavutil
add some string functions
| author | mru |
|---|---|
| date | Sat, 23 Jun 2007 23:10:26 +0000 |
| parents | |
| children | 92b31fec32b0 |
comparison
equal
deleted
inserted
replaced
| 346:e9937dcd0afd | 347:2fb35d82b0bd |
|---|---|
| 1 /* | |
| 2 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | |
| 3 * Copyright (c) 2007 Mans Rullgard | |
| 4 * | |
| 5 * This file is part of FFmpeg. | |
| 6 * | |
| 7 * FFmpeg is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Lesser General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 2.1 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * FFmpeg is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Lesser General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Lesser General Public | |
| 18 * License along with FFmpeg; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 */ | |
| 21 | |
| 22 #include <string.h> | |
| 23 #include <ctype.h> | |
| 24 #include "avstring.h" | |
| 25 | |
| 26 int av_strstart(const char *str, const char *pfx, const char **ptr) | |
| 27 { | |
| 28 while (*pfx && *pfx++ == *str++); | |
| 29 if (!*pfx && ptr) | |
| 30 *ptr = str; | |
| 31 return !*pfx; | |
| 32 } | |
| 33 | |
| 34 int av_stristart(const char *str, const char *pfx, const char **ptr) | |
| 35 { | |
| 36 while (*pfx && toupper((unsigned)*pfx++) == toupper((unsigned)*str++)); | |
| 37 if (!*pfx && ptr) | |
| 38 *ptr = str; | |
| 39 return !*pfx; | |
| 40 } | |
| 41 | |
| 42 size_t av_strlcpy(char *dst, const char *src, size_t size) | |
| 43 { | |
| 44 size_t len = 0; | |
| 45 while (++len < size && *src) | |
| 46 *dst++ = *src++; | |
| 47 if (len <= size) | |
| 48 *dst = 0; | |
| 49 return len + strlen(src) - 1; | |
| 50 } | |
| 51 | |
| 52 size_t av_strlcat(char *dst, const char *src, size_t size) | |
| 53 { | |
| 54 size_t len = strlen(dst); | |
| 55 if (size <= len + 1) | |
| 56 return len + strlen(src); | |
| 57 return len + av_strlcpy(dst + len, src, size - len); | |
| 58 } |
