jfs_unicode.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (C) International Business Machines Corp., 2000-2002
  3. * Portions Copyright (C) Christoph Hellwig, 2001-2002
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef _H_JFS_UNICODE
  20. #define _H_JFS_UNICODE
  21. #include <linux/slab.h>
  22. #include <asm/byteorder.h>
  23. #include "jfs_types.h"
  24. typedef struct {
  25. wchar_t start;
  26. wchar_t end;
  27. signed char *table;
  28. } UNICASERANGE;
  29. extern signed char UniUpperTable[512];
  30. extern UNICASERANGE UniUpperRange[];
  31. extern int get_UCSname(struct component_name *, struct dentry *);
  32. extern int jfs_strfromUCS_le(char *, const __le16 *, int, struct nls_table *);
  33. #define free_UCSname(COMP) kfree((COMP)->name)
  34. /*
  35. * UniStrcpy: Copy a string
  36. */
  37. static inline wchar_t *UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2)
  38. {
  39. wchar_t *anchor = ucs1; /* save the start of result string */
  40. while ((*ucs1++ = *ucs2++));
  41. return anchor;
  42. }
  43. /*
  44. * UniStrncpy: Copy length limited string with pad
  45. */
  46. static inline __le16 *UniStrncpy_le(__le16 * ucs1, const __le16 * ucs2,
  47. size_t n)
  48. {
  49. __le16 *anchor = ucs1;
  50. while (n-- && *ucs2) /* Copy the strings */
  51. *ucs1++ = *ucs2++;
  52. n++;
  53. while (n--) /* Pad with nulls */
  54. *ucs1++ = 0;
  55. return anchor;
  56. }
  57. /*
  58. * UniStrncmp_le: Compare length limited string - native to little-endian
  59. */
  60. static inline int UniStrncmp_le(const wchar_t * ucs1, const __le16 * ucs2,
  61. size_t n)
  62. {
  63. if (!n)
  64. return 0; /* Null strings are equal */
  65. while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
  66. ucs1++;
  67. ucs2++;
  68. }
  69. return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
  70. }
  71. /*
  72. * UniStrncpy_to_le: Copy length limited string with pad to little-endian
  73. */
  74. static inline __le16 *UniStrncpy_to_le(__le16 * ucs1, const wchar_t * ucs2,
  75. size_t n)
  76. {
  77. __le16 *anchor = ucs1;
  78. while (n-- && *ucs2) /* Copy the strings */
  79. *ucs1++ = cpu_to_le16(*ucs2++);
  80. n++;
  81. while (n--) /* Pad with nulls */
  82. *ucs1++ = 0;
  83. return anchor;
  84. }
  85. /*
  86. * UniStrncpy_from_le: Copy length limited string with pad from little-endian
  87. */
  88. static inline wchar_t *UniStrncpy_from_le(wchar_t * ucs1, const __le16 * ucs2,
  89. size_t n)
  90. {
  91. wchar_t *anchor = ucs1;
  92. while (n-- && *ucs2) /* Copy the strings */
  93. *ucs1++ = __le16_to_cpu(*ucs2++);
  94. n++;
  95. while (n--) /* Pad with nulls */
  96. *ucs1++ = 0;
  97. return anchor;
  98. }
  99. /*
  100. * UniToupper: Convert a unicode character to upper case
  101. */
  102. static inline wchar_t UniToupper(wchar_t uc)
  103. {
  104. UNICASERANGE *rp;
  105. if (uc < sizeof(UniUpperTable)) { /* Latin characters */
  106. return uc + UniUpperTable[uc]; /* Use base tables */
  107. } else {
  108. rp = UniUpperRange; /* Use range tables */
  109. while (rp->start) {
  110. if (uc < rp->start) /* Before start of range */
  111. return uc; /* Uppercase = input */
  112. if (uc <= rp->end) /* In range */
  113. return uc + rp->table[uc - rp->start];
  114. rp++; /* Try next range */
  115. }
  116. }
  117. return uc; /* Past last range */
  118. }
  119. /*
  120. * UniStrupr: Upper case a unicode string
  121. */
  122. static inline wchar_t *UniStrupr(wchar_t * upin)
  123. {
  124. wchar_t *up;
  125. up = upin;
  126. while (*up) { /* For all characters */
  127. *up = UniToupper(*up);
  128. up++;
  129. }
  130. return upin; /* Return input pointer */
  131. }
  132. #endif /* !_H_JFS_UNICODE */