jfs_unicode.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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.        struct nls_table *);
  32. extern int jfs_strfromUCS_le(char *, const wchar_t *, 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 wchar_t *UniStrncpy(wchar_t * ucs1, const wchar_t * ucs2,
  47.   size_t n)
  48. {
  49. wchar_t *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 wchar_t * 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_le:  Copy length limited string with pad to little-endian
  73.  */
  74. static inline wchar_t *UniStrncpy_le(wchar_t * ucs1, const wchar_t * ucs2,
  75.      size_t n)
  76. {
  77. wchar_t *anchor = ucs1;
  78. while (n-- && *ucs2) /* Copy the strings */
  79. *ucs1++ = __le16_to_cpu(*ucs2++);
  80. n++;
  81. while (n--) /* Pad with nulls */
  82. *ucs1++ = 0;
  83. return anchor;
  84. }
  85. /*
  86.  * UniToupper:  Convert a unicode character to upper case
  87.  */
  88. static inline wchar_t UniToupper(wchar_t uc)
  89. {
  90. UNICASERANGE *rp;
  91. if (uc < sizeof(UniUpperTable)) { /* Latin characters */
  92. return uc + UniUpperTable[uc]; /* Use base tables */
  93. } else {
  94. rp = UniUpperRange; /* Use range tables */
  95. while (rp->start) {
  96. if (uc < rp->start) /* Before start of range */
  97. return uc; /* Uppercase = input */
  98. if (uc <= rp->end) /* In range */
  99. return uc + rp->table[uc - rp->start];
  100. rp++; /* Try next range */
  101. }
  102. }
  103. return uc; /* Past last range */
  104. }
  105. /*
  106.  * UniStrupr:  Upper case a unicode string
  107.  */
  108. static inline wchar_t *UniStrupr(wchar_t * upin)
  109. {
  110. wchar_t *up;
  111. up = upin;
  112. while (*up) { /* For all characters */
  113. *up = UniToupper(*up);
  114. up++;
  115. }
  116. return upin; /* Return input pointer */
  117. }
  118. #endif /* !_H_JFS_UNICODE */