• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavutil/avstring.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
00003  * Copyright (c) 2007 Mans Rullgard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include <stdarg.h>
00023 #include <stdio.h>
00024 #include <string.h>
00025 #include <ctype.h>
00026 #include "avstring.h"
00027 #include "mem.h"
00028 
00029 int av_strstart(const char *str, const char *pfx, const char **ptr)
00030 {
00031     while (*pfx && *pfx == *str) {
00032         pfx++;
00033         str++;
00034     }
00035     if (!*pfx && ptr)
00036         *ptr = str;
00037     return !*pfx;
00038 }
00039 
00040 int av_stristart(const char *str, const char *pfx, const char **ptr)
00041 {
00042     while (*pfx && toupper((unsigned)*pfx) == toupper((unsigned)*str)) {
00043         pfx++;
00044         str++;
00045     }
00046     if (!*pfx && ptr)
00047         *ptr = str;
00048     return !*pfx;
00049 }
00050 
00051 char *av_stristr(const char *s1, const char *s2)
00052 {
00053     if (!*s2)
00054         return s1;
00055 
00056     do {
00057         if (av_stristart(s1, s2, NULL))
00058             return s1;
00059     } while (*s1++);
00060 
00061     return NULL;
00062 }
00063 
00064 size_t av_strlcpy(char *dst, const char *src, size_t size)
00065 {
00066     size_t len = 0;
00067     while (++len < size && *src)
00068         *dst++ = *src++;
00069     if (len <= size)
00070         *dst = 0;
00071     return len + strlen(src) - 1;
00072 }
00073 
00074 size_t av_strlcat(char *dst, const char *src, size_t size)
00075 {
00076     size_t len = strlen(dst);
00077     if (size <= len + 1)
00078         return len + strlen(src);
00079     return len + av_strlcpy(dst + len, src, size - len);
00080 }
00081 
00082 size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)
00083 {
00084     int len = strlen(dst);
00085     va_list vl;
00086 
00087     va_start(vl, fmt);
00088     len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);
00089     va_end(vl);
00090 
00091     return len;
00092 }
00093 
00094 char *av_d2str(double d)
00095 {
00096     char *str= av_malloc(16);
00097     if(str) snprintf(str, 16, "%f", d);
00098     return str;
00099 }

Generated on Fri Sep 16 2011 17:17:51 for FFmpeg by  doxygen 1.7.1