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.

fastutf8.h 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Yibo Cai
  5. * Copyright (c) 2019 Vsevolod Stakhov
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. #ifndef RSPAMD_FASTUTF8_H
  25. #define RSPAMD_FASTUTF8_H
  26. #include <sys/types.h>
  27. #include <stdbool.h>
  28. #include <stdint.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. enum rspamd_fast_utf8_cpu_flags {
  33. RSPAMD_FAST_UTF8_FLAG_SSE41 = 1u << 0u,
  34. RSPAMD_FAST_UTF8_FLAG_AVX2 = 1u << 1u,
  35. };
  36. /**
  37. * Called to init codecs
  38. * @param flags
  39. */
  40. void rspamd_fast_utf8_library_init(unsigned flags);
  41. /**
  42. * Called to validate input using fast codec
  43. * @param data
  44. * @param len
  45. * @return
  46. */
  47. off_t rspamd_fast_utf8_validate(const unsigned char *data, size_t len);
  48. /**
  49. * Use plain C implementation
  50. * @param data
  51. * @param len
  52. * @return
  53. */
  54. off_t rspamd_fast_utf8_validate_ref(const unsigned char *data, size_t len);
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif