A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

85 lignes
2.6 KiB

  1. /*
  2. Copyright (C) 2012-2016 Ben Kurtovic <ben.kurtovic@gmail.com>
  3. Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. this software and associated documentation files (the "Software"), to deal in
  5. the Software without restriction, including without limitation the rights to
  6. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  7. of the Software, and to permit persons to whom the Software is furnished to do
  8. so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.
  18. */
  19. #include "tag_data.h"
  20. #include "contexts.h"
  21. /*
  22. Initialize a new TagData object.
  23. */
  24. TagData *
  25. TagData_new(TokenizerInput *text)
  26. {
  27. #define ALLOC_BUFFER(name) \
  28. name = Textbuffer_new(text); \
  29. if (!name) { \
  30. TagData_dealloc(self); \
  31. return NULL; \
  32. }
  33. TagData *self = malloc(sizeof(TagData));
  34. if (!self) {
  35. PyErr_NoMemory();
  36. return NULL;
  37. }
  38. self->context = TAG_NAME;
  39. ALLOC_BUFFER(self->pad_first)
  40. ALLOC_BUFFER(self->pad_before_eq)
  41. ALLOC_BUFFER(self->pad_after_eq)
  42. self->quoter = 0;
  43. self->reset = 0;
  44. return self;
  45. #undef ALLOC_BUFFER
  46. }
  47. /*
  48. Deallocate the given TagData object.
  49. */
  50. void
  51. TagData_dealloc(TagData *self)
  52. {
  53. if (self->pad_first) {
  54. Textbuffer_dealloc(self->pad_first);
  55. }
  56. if (self->pad_before_eq) {
  57. Textbuffer_dealloc(self->pad_before_eq);
  58. }
  59. if (self->pad_after_eq) {
  60. Textbuffer_dealloc(self->pad_after_eq);
  61. }
  62. free(self);
  63. }
  64. /*
  65. Clear the internal buffers of the given TagData object.
  66. */
  67. int
  68. TagData_reset_buffers(TagData *self)
  69. {
  70. if (Textbuffer_reset(self->pad_first) || Textbuffer_reset(self->pad_before_eq) ||
  71. Textbuffer_reset(self->pad_after_eq)) {
  72. return -1;
  73. }
  74. return 0;
  75. }