jfs_unicode.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <asm/byteorder.h>
  22. #include "jfs_types.h"
  23. typedef struct {
  24. wchar_t start;
  25. wchar_t end;
  26. signed char *table;
  27. } UNICASERANGE;
  28. extern signed char UniUpperTable[512];
  29. extern UNICASERANGE UniUpperRange[];
  30. extern int get_UCSname(struct component_name *, struct dentry *);
  31. extern int jfs_strfromUCS_le(char *, const __le16 *, int, struct nls_table *);
  32. #define free_UCSname(COMP) kfree((COMP)->name)
  33. /*
  34. * UniStrcpy: Copy a string
  35. */
  36. static inline wchar_t *UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2)
  37. {
  38. wchar_t *anchor = ucs1; /* save the start of result string */
  39. while ((*ucs1++ = *ucs2++));
  40. return anchor;
  41. }
  42. /*
  43. * UniStrncpy: Copy length limited string with pad
  44. */
  45. static inline __le16 *UniStrncpy_le(__le16 * ucs1, const __le16 * ucs2,
  46. size_t n)
  47. {
  48. __le16 *anchor = ucs1;
  49. while (n-- && *ucs2) /* Copy the strings */
  50. *ucs1++ = *ucs2++;
  51. n++;
  52. while (n--) /* Pad with nulls */
  53. *ucs1++ = 0;
  54. return anchor;
  55. }
  56. /*
  57. * UniStrncmp_le: Compare length limited string - native to little-endian
  58. */
  59. static inline int UniStrncmp_le(const wchar_t * ucs1, const __le16 * ucs2,
  60. size_t n)
  61. {
  62. if (!n)
  63. return 0; /* Null strings are equal */
  64. while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
  65. ucs1++;
  66. ucs2++;
  67. }
  68. return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
  69. }
  70. /*
  71. * UniStrncpy_to_le: Copy length limited string with pad to little-endian
  72. */
  73. static inline __le16 *UniStrncpy_to_le(__le16 * ucs1, const wchar_t * ucs2,
  74. size_t n)
  75. {
  76. __le16 *anchor = ucs1;
  77. while (n-- && *ucs2) /* Copy the strings */
  78. *ucs1++ = cpu_to_le16(*ucs2++);
  79. n++;
  80. while (n--) /* Pad with nulls */
  81. *ucs1++ = 0;
  82. return anchor;
  83. }
  84. /*
  85. * UniStrncpy_from_le: Copy length limited string with pad from little-endian
  86. */
  87. static inline wchar_t *UniStrncpy_from_le(wchar_t * ucs1, const __le16 * ucs2,
  88. size_t n)
  89. {
  90. wchar_t *anchor = ucs1;
  91. while (n-- && *ucs2) /* Copy the strings */
  92. *ucs1++ = __le16_to_cpu(*ucs2++);
  93. n++;
  94. while (n--) /* Pad with nulls */
  95. *ucs1++ = 0;
  96. return anchor;
  97. }
  98. /*
  99. * UniToupper: Convert a unicode character to upper case
  100. */
  101. static inline wchar_t UniToupper(wchar_t uc)
  102. {
  103. UNICASERANGE *rp;
  104. if (uc < sizeof(UniUpperTable)) { /* Latin characters */
  105. return uc + UniUpperTable[uc]; /* Use base tables */
  106. } else {
  107. rp = UniUpperRange; /* Use range tables */
  108. while (rp->start) {
  109. if (uc < rp->start) /* Before start of range */
  110. return uc; /* Uppercase = input */
  111. if (uc <= rp->end) /* In range */
  112. return uc + rp->table[uc - rp->start];
  113. rp++; /* Try next range */
  114. }
  115. }
  116. return uc; /* Past last range */
  117. }
  118. /*
  119. * UniStrupr: Upper case a unicode string
  120. */
  121. static inline wchar_t *UniStrupr(wchar_t * upin)
  122. {
  123. wchar_t *up;
  124. up = upin;
  125. while (*up) { /* For all characters */
  126. *up = UniToupper(*up);
  127. up++;
  128. }
  129. return upin; /* Return input pointer */
  130. }
  131. #endif /* !_H_JFS_UNICODE */