util.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2010 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // Author: [email protected] (Jonathan Tang)
  16. //
  17. // This contains some utility functions that didn't fit into any of the other
  18. // headers.
  19. #ifndef GUMBO_UTIL_H_
  20. #define GUMBO_UTIL_H_
  21. #include <stdbool.h>
  22. #include <stddef.h>
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. // Forward declaration since it's passed into some of the functions in this
  27. // header.
  28. struct GumboInternalParser;
  29. // Utility function for allocating & copying a null-terminated string into a
  30. // freshly-allocated buffer. This is necessary for proper memory management; we
  31. // have the convention that all const char* in parse tree structures are
  32. // freshly-allocated, so if we didn't copy, we'd try to delete a literal string
  33. // when the parse tree is destroyed.
  34. char* gumbo_copy_stringz(struct GumboInternalParser* parser, const char* str);
  35. // Allocate a chunk of memory, using the allocator specified in the Parser's
  36. // config options.
  37. void* gumbo_parser_allocate(
  38. struct GumboInternalParser* parser, size_t num_bytes);
  39. // Deallocate a chunk of memory, using the deallocator specified in the Parser's
  40. // config options.
  41. void gumbo_parser_deallocate(struct GumboInternalParser* parser, void* ptr);
  42. // Debug wrapper for printf, to make it easier to turn off debugging info when
  43. // required.
  44. void gumbo_debug(const char* format, ...);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #endif // GUMBO_UTIL_H_