grefstring.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* grefstring.h: Reference counted strings
  2. *
  3. * Copyright 2018 Emmanuele Bassi
  4. *
  5. * SPDX-License-Identifier: LGPL-2.1-or-later
  6. *
  7. * This library 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. * This library 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 this library; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #pragma once
  21. #include "gmem.h"
  22. #include "gmacros.h"
  23. G_BEGIN_DECLS
  24. GLIB_AVAILABLE_IN_2_58
  25. char * g_ref_string_new (const char *str);
  26. GLIB_AVAILABLE_IN_2_58
  27. char * g_ref_string_new_len (const char *str,
  28. gssize len);
  29. GLIB_AVAILABLE_IN_2_58
  30. char * g_ref_string_new_intern (const char *str);
  31. GLIB_AVAILABLE_IN_2_58
  32. char * g_ref_string_acquire (char *str);
  33. GLIB_AVAILABLE_IN_2_58
  34. void g_ref_string_release (char *str);
  35. GLIB_AVAILABLE_IN_2_58
  36. gsize g_ref_string_length (char *str);
  37. /**
  38. * GRefString:
  39. *
  40. * A typedef for a reference-counted string. A pointer to a #GRefString can be
  41. * treated like a standard `char*` array by all code, but can additionally have
  42. * `g_ref_string_*()` methods called on it. `g_ref_string_*()` methods cannot be
  43. * called on `char*` arrays not allocated using g_ref_string_new().
  44. *
  45. * If using #GRefString with autocleanups, g_autoptr() must be used rather than
  46. * g_autofree(), so that the reference counting metadata is also freed.
  47. *
  48. * Since: 2.58
  49. */
  50. typedef char GRefString;
  51. G_END_DECLS