util.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #ifdef _MSC_VER
  22. #define _CRT_SECURE_NO_WARNINGS
  23. #endif
  24. #include <stdbool.h>
  25. #include <stddef.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. // Forward declaration since it's passed into some of the functions in this
  30. // header.
  31. struct GumboInternalParser;
  32. // Utility function for allocating & copying a null-terminated string into a
  33. // freshly-allocated buffer. This is necessary for proper memory management; we
  34. // have the convention that all const char* in parse tree structures are
  35. // freshly-allocated, so if we didn't copy, we'd try to delete a literal string
  36. // when the parse tree is destroyed.
  37. char* gumbo_copy_stringz(struct GumboInternalParser* parser, const char* str);
  38. // Allocate a chunk of memory, using the allocator specified in the Parser's
  39. // config options.
  40. void* gumbo_parser_allocate(
  41. struct GumboInternalParser* parser, size_t num_bytes);
  42. // Deallocate a chunk of memory, using the deallocator specified in the Parser's
  43. // config options.
  44. void gumbo_parser_deallocate(struct GumboInternalParser* parser, void* ptr);
  45. // Debug wrapper for printf, to make it easier to turn off debugging info when
  46. // required.
  47. void gumbo_debug(const char* format, ...);
  48. #ifdef __cplusplus
  49. }
  50. #endif
  51. #endif // GUMBO_UTIL_H_