avstring.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2007 Mans Rullgard
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVUTIL_AVSTRING_H
  21. #define AVUTIL_AVSTRING_H
  22. #include <stddef.h>
  23. /**
  24. * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
  25. * the address of the first character in str after the prefix.
  26. *
  27. * @param str input string
  28. * @param pfx prefix to test
  29. * @param ptr updated if the prefix is matched inside str
  30. * @return non-zero if the prefix matches, zero otherwise
  31. */
  32. int av_strstart(const char *str, const char *pfx, const char **ptr);
  33. /**
  34. * Return non-zero if pfx is a prefix of str independent of case. If
  35. * it is, *ptr is set to the address of the first character in str
  36. * after the prefix.
  37. *
  38. * @param str input string
  39. * @param pfx prefix to test
  40. * @param ptr updated if the prefix is matched inside str
  41. * @return non-zero if the prefix matches, zero otherwise
  42. */
  43. int av_stristart(const char *str, const char *pfx, const char **ptr);
  44. /**
  45. * Copy the string src to dst, but no more than size - 1 bytes, and
  46. * null-terminate dst.
  47. *
  48. * This function is the same as BSD strlcpy().
  49. *
  50. * @param dst destination buffer
  51. * @param src source string
  52. * @param size size of destination buffer
  53. * @return the length of src
  54. *
  55. * WARNING: since the return value is the length of src, src absolutely
  56. * _must_ be a properly 0-terminated string, otherwise this will read beyond
  57. * the end of the buffer and possibly crash.
  58. */
  59. size_t av_strlcpy(char *dst, const char *src, size_t size);
  60. /**
  61. * Append the string src to the string dst, but to a total length of
  62. * no more than size - 1 bytes, and null-terminate dst.
  63. *
  64. * This function is similar to BSD strlcat(), but differs when
  65. * size <= strlen(dst).
  66. *
  67. * @param dst destination buffer
  68. * @param src source string
  69. * @param size size of destination buffer
  70. * @return the total length of src and dst
  71. *
  72. * WARNING: since the return value use the length of src and dst, these absolutely
  73. * _must_ be a properly 0-terminated strings, otherwise this will read beyond
  74. * the end of the buffer and possibly crash.
  75. */
  76. size_t av_strlcat(char *dst, const char *src, size_t size);
  77. /**
  78. * Append output to a string, according to a format. Never write out of
  79. * the destination buffer, and always put a terminating 0 within
  80. * the buffer.
  81. * @param dst destination buffer (string to which the output is
  82. * appended)
  83. * @param size total size of the destination buffer
  84. * @param fmt printf-compatible format string, specifying how the
  85. * following parameters are used
  86. * @return the length of the string that would have been generated
  87. * if enough space had been available
  88. */
  89. size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...);
  90. /**
  91. * Convert a number to a av_malloced string.
  92. */
  93. char *av_d2str(double d);
  94. #endif /* AVUTIL_AVSTRING_H */