You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

acism.h 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. ** Copyright (C) 2009-2014 Mischa Sandberg <mischasan@gmail.com>
  3. ** Copyright (C) 2015 Vsevolod Stakhov <vsevolod@highsecure.ru>
  4. **
  5. ** This program is free software; you can redistribute it and/or modify
  6. ** it under the terms of the GNU Lesser General Public License as
  7. ** published by the Free Software Foundation. You may not use, modify or
  8. ** distribute this program under any other version of the GNU Lesser General
  9. ** Public License.
  10. **
  11. ** This program is distributed in the hope that it will be useful,
  12. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ** GNU Lesser General Public License for more details.
  15. **
  16. ** You should have received a copy of the GNU Lesser General Public License
  17. ** along with this program; if not, write to the Free Software
  18. ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef ACISM_H
  21. #define ACISM_H
  22. #include "config.h"
  23. // "acism" uses MEMREF {ptr,len} bytevec structs for "string" args,
  24. // rather than NUL-terminated "C" strings.
  25. typedef struct { char const *ptr; size_t len; } ac_trie_pat_t;
  26. typedef struct acism ac_trie_t;
  27. ac_trie_t* acism_create(ac_trie_pat_t const *strv, int nstrs);
  28. void acism_destroy(ac_trie_t*);
  29. // For each match, acism_scan calls its ACISM_ACTION fn,
  30. // giving it the strv[] index of the matched string,
  31. // and the text[] offset of the byte PAST the end of the string.
  32. // If ACISM_ACTION returns 0, search continues; otherwise,
  33. // acism_more returns that nonzero value immediately.
  34. typedef int (ACISM_ACTION)(int strnum, int textpos, void *context);
  35. // If sequential blocks of (text) are passed to repeated acism_more calls,
  36. // then search continues where the previous acism_more left off --
  37. // string matches can cross block boundaries.
  38. // *state should initially be (0).
  39. int acism_lookup(ac_trie_t const *psp, const char *text, size_t len,
  40. ACISM_ACTION *cb, void *context, int *statep, bool caseless);
  41. #endif//ACISM_H