unicode.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_UNICODE_H
  3. #define _LINUX_UNICODE_H
  4. #include <linux/init.h>
  5. #include <linux/dcache.h>
  6. struct utf8data;
  7. struct utf8data_table;
  8. #define UNICODE_MAJ_SHIFT 16
  9. #define UNICODE_MIN_SHIFT 8
  10. #define UNICODE_AGE(MAJ, MIN, REV) \
  11. (((unsigned int)(MAJ) << UNICODE_MAJ_SHIFT) | \
  12. ((unsigned int)(MIN) << UNICODE_MIN_SHIFT) | \
  13. ((unsigned int)(REV)))
  14. static inline u8 unicode_major(unsigned int age)
  15. {
  16. return (age >> UNICODE_MAJ_SHIFT) & 0xff;
  17. }
  18. static inline u8 unicode_minor(unsigned int age)
  19. {
  20. return (age >> UNICODE_MIN_SHIFT) & 0xff;
  21. }
  22. static inline u8 unicode_rev(unsigned int age)
  23. {
  24. return age & 0xff;
  25. }
  26. /*
  27. * Two normalization forms are supported:
  28. * 1) NFDI
  29. * - Apply unicode normalization form NFD.
  30. * - Remove any Default_Ignorable_Code_Point.
  31. * 2) NFDICF
  32. * - Apply unicode normalization form NFD.
  33. * - Remove any Default_Ignorable_Code_Point.
  34. * - Apply a full casefold (C + F).
  35. */
  36. enum utf8_normalization {
  37. UTF8_NFDI = 0,
  38. UTF8_NFDICF,
  39. UTF8_NMAX,
  40. };
  41. struct unicode_map {
  42. unsigned int version;
  43. const struct utf8data *ntab[UTF8_NMAX];
  44. const struct utf8data_table *tables;
  45. };
  46. int utf8_validate(const struct unicode_map *um, const struct qstr *str);
  47. int utf8_strncmp(const struct unicode_map *um,
  48. const struct qstr *s1, const struct qstr *s2);
  49. int utf8_strncasecmp(const struct unicode_map *um,
  50. const struct qstr *s1, const struct qstr *s2);
  51. int utf8_strncasecmp_folded(const struct unicode_map *um,
  52. const struct qstr *cf,
  53. const struct qstr *s1);
  54. int utf8_normalize(const struct unicode_map *um, const struct qstr *str,
  55. unsigned char *dest, size_t dlen);
  56. int utf8_casefold(const struct unicode_map *um, const struct qstr *str,
  57. unsigned char *dest, size_t dlen);
  58. int utf8_casefold_hash(const struct unicode_map *um, const void *salt,
  59. struct qstr *str);
  60. struct unicode_map *utf8_load(unsigned int version);
  61. void utf8_unload(struct unicode_map *um);
  62. #endif /* _LINUX_UNICODE_H */