string.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * string.h - string handling routines
  4. *
  5. * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This 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
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. #ifndef LIBDPKG_STRING_H
  21. #define LIBDPKG_STRING_H
  22. #include <stddef.h>
  23. #include <stdbool.h>
  24. #include <dpkg/macros.h>
  25. DPKG_BEGIN_DECLS
  26. /**
  27. * @defgroup string String handling
  28. * @ingroup dpkg-internal
  29. * @{
  30. */
  31. /**
  32. * Check if a string is either NULL or empty.
  33. */
  34. static inline bool
  35. str_is_unset(const char *str)
  36. {
  37. return str == NULL || str[0] == '\0';
  38. }
  39. /**
  40. * Check if a string has content.
  41. */
  42. static inline bool
  43. str_is_set(const char *str)
  44. {
  45. return str != NULL && str[0] != '\0';
  46. }
  47. bool str_match_end(const char *str, const char *end);
  48. unsigned int str_fnv_hash(const char *str);
  49. char *str_escape_fmt(char *dest, const char *src, size_t n);
  50. char *str_quote_meta(const char *src);
  51. char *str_strip_quotes(char *str);
  52. struct str_crop_info {
  53. int str_bytes;
  54. int max_bytes;
  55. };
  56. int str_width(const char *str);
  57. void str_gen_crop(const char *str, int max_width, struct str_crop_info *crop);
  58. /** @} */
  59. DPKG_END_DECLS
  60. #endif /* LIBDPKG_STRING_H */