misc/winutils/include/libavutil/avstring.h
author koda
Fri, 05 Apr 2013 22:57:31 +0200
changeset 8874 8121ce2b0a88
parent 7813 7ac83d79b897
permissions -rw-r--r--
fix displaying the right version of windows in system info
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7813
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     1
/*
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     2
 * Copyright (c) 2007 Mans Rullgard
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     3
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     4
 * This file is part of Libav.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     5
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     6
 * Libav is free software; you can redistribute it and/or
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     7
 * modify it under the terms of the GNU Lesser General Public
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     8
 * License as published by the Free Software Foundation; either
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     9
 * version 2.1 of the License, or (at your option) any later version.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    10
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    11
 * Libav is distributed in the hope that it will be useful,
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    14
 * Lesser General Public License for more details.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    15
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    16
 * You should have received a copy of the GNU Lesser General Public
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    17
 * License along with Libav; if not, write to the Free Software
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    19
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    20
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    21
#ifndef AVUTIL_AVSTRING_H
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    22
#define AVUTIL_AVSTRING_H
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    23
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    24
#include <stddef.h>
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    25
#include "attributes.h"
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    26
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    27
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    28
 * @addtogroup lavu_string
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    29
 * @{
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    30
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    31
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    32
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    33
 * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    34
 * the address of the first character in str after the prefix.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    35
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    36
 * @param str input string
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    37
 * @param pfx prefix to test
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    38
 * @param ptr updated if the prefix is matched inside str
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    39
 * @return non-zero if the prefix matches, zero otherwise
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    40
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    41
int av_strstart(const char *str, const char *pfx, const char **ptr);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    42
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    43
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    44
 * Return non-zero if pfx is a prefix of str independent of case. If
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    45
 * it is, *ptr is set to the address of the first character in str
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    46
 * after the prefix.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    47
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    48
 * @param str input string
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    49
 * @param pfx prefix to test
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    50
 * @param ptr updated if the prefix is matched inside str
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    51
 * @return non-zero if the prefix matches, zero otherwise
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    52
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    53
int av_stristart(const char *str, const char *pfx, const char **ptr);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    54
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    55
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    56
 * Locate the first case-independent occurrence in the string haystack
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    57
 * of the string needle.  A zero-length string needle is considered to
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    58
 * match at the start of haystack.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    59
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    60
 * This function is a case-insensitive version of the standard strstr().
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    61
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    62
 * @param haystack string to search in
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    63
 * @param needle   string to search for
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    64
 * @return         pointer to the located match within haystack
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    65
 *                 or a null pointer if no match
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    66
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    67
char *av_stristr(const char *haystack, const char *needle);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    68
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    69
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    70
 * Copy the string src to dst, but no more than size - 1 bytes, and
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    71
 * null-terminate dst.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    72
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    73
 * This function is the same as BSD strlcpy().
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    74
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    75
 * @param dst destination buffer
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    76
 * @param src source string
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    77
 * @param size size of destination buffer
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    78
 * @return the length of src
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    79
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    80
 * @warning since the return value is the length of src, src absolutely
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    81
 * _must_ be a properly 0-terminated string, otherwise this will read beyond
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    82
 * the end of the buffer and possibly crash.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    83
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    84
size_t av_strlcpy(char *dst, const char *src, size_t size);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    85
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    86
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    87
 * Append the string src to the string dst, but to a total length of
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    88
 * no more than size - 1 bytes, and null-terminate dst.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    89
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    90
 * This function is similar to BSD strlcat(), but differs when
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    91
 * size <= strlen(dst).
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    92
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    93
 * @param dst destination buffer
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    94
 * @param src source string
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    95
 * @param size size of destination buffer
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    96
 * @return the total length of src and dst
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    97
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    98
 * @warning since the return value use the length of src and dst, these
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    99
 * absolutely _must_ be a properly 0-terminated strings, otherwise this
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   100
 * will read beyond the end of the buffer and possibly crash.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   101
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   102
size_t av_strlcat(char *dst, const char *src, size_t size);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   103
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   104
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   105
 * Append output to a string, according to a format. Never write out of
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   106
 * the destination buffer, and always put a terminating 0 within
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   107
 * the buffer.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   108
 * @param dst destination buffer (string to which the output is
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   109
 *  appended)
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   110
 * @param size total size of the destination buffer
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   111
 * @param fmt printf-compatible format string, specifying how the
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   112
 *  following parameters are used
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   113
 * @return the length of the string that would have been generated
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   114
 *  if enough space had been available
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   115
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   116
size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   117
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   118
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   119
 * Convert a number to a av_malloced string.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   120
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   121
char *av_d2str(double d);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   122
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   123
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   124
 * Unescape the given string until a non escaped terminating char,
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   125
 * and return the token corresponding to the unescaped string.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   126
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   127
 * The normal \ and ' escaping is supported. Leading and trailing
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   128
 * whitespaces are removed, unless they are escaped with '\' or are
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   129
 * enclosed between ''.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   130
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   131
 * @param buf the buffer to parse, buf will be updated to point to the
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   132
 * terminating char
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   133
 * @param term a 0-terminated list of terminating chars
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   134
 * @return the malloced unescaped string, which must be av_freed by
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   135
 * the user, NULL in case of allocation failure
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   136
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   137
char *av_get_token(const char **buf, const char *term);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   138
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   139
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   140
 * Locale-independent conversion of ASCII characters to uppercase.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   141
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   142
static inline int av_toupper(int c)
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   143
{
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   144
    if (c >= 'a' && c <= 'z')
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   145
        c ^= 0x20;
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   146
    return c;
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   147
}
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   148
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   149
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   150
 * Locale-independent conversion of ASCII characters to lowercase.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   151
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   152
static inline int av_tolower(int c)
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   153
{
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   154
    if (c >= 'A' && c <= 'Z')
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   155
        c ^= 0x20;
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   156
    return c;
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   157
}
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   158
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   159
/*
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   160
 * Locale-independent case-insensitive compare.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   161
 * @note This means only ASCII-range characters are case-insensitive
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   162
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   163
int av_strcasecmp(const char *a, const char *b);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   164
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   165
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   166
 * Locale-independent case-insensitive compare.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   167
 * @note This means only ASCII-range characters are case-insensitive
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   168
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   169
int av_strncasecmp(const char *a, const char *b, size_t n);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   170
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   171
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   172
 * @}
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   173
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   174
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
   175
#endif /* AVUTIL_AVSTRING_H */