2 * Copyright (c) International Business Machines Corp., 2000-2002
3 * Portions Copyright (c) Christoph Hellwig, 2001-2002
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.
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.
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
19 #ifndef _H_JFS_UNICODE
20 #define _H_JFS_UNICODE
22 #include <asm/byteorder.h>
23 #include "jfs_types.h"
31 extern signed char UniUpperTable
[512];
32 extern UNICASERANGE UniUpperRange
[];
33 extern int get_UCSname(struct component_name
*, struct dentry
*);
34 extern int jfs_strfromUCS_le(char *, const __le16
*, int, struct nls_table
*);
36 #define free_UCSname(COMP) kfree((COMP)->name)
39 * UniStrcpy: Copy a string
41 static inline wchar_t *UniStrcpy(wchar_t * ucs1
, const wchar_t * ucs2
)
43 wchar_t *anchor
= ucs1
; /* save the start of result string */
45 while ((*ucs1
++ = *ucs2
++));
52 * UniStrncpy: Copy length limited string with pad
54 static inline __le16
*UniStrncpy_le(__le16
* ucs1
, const __le16
* ucs2
,
57 __le16
*anchor
= ucs1
;
59 while (n
-- && *ucs2
) /* Copy the strings */
63 while (n
--) /* Pad with nulls */
69 * UniStrncmp_le: Compare length limited string - native to little-endian
71 static inline int UniStrncmp_le(const wchar_t * ucs1
, const __le16
* ucs2
,
75 return 0; /* Null strings are equal */
76 while ((*ucs1
== __le16_to_cpu(*ucs2
)) && *ucs1
&& --n
) {
80 return (int) *ucs1
- (int) __le16_to_cpu(*ucs2
);
84 * UniStrncpy_to_le: Copy length limited string with pad to little-endian
86 static inline __le16
*UniStrncpy_to_le(__le16
* ucs1
, const wchar_t * ucs2
,
89 __le16
*anchor
= ucs1
;
91 while (n
-- && *ucs2
) /* Copy the strings */
92 *ucs1
++ = cpu_to_le16(*ucs2
++);
95 while (n
--) /* Pad with nulls */
101 * UniStrncpy_from_le: Copy length limited string with pad from little-endian
103 static inline wchar_t *UniStrncpy_from_le(wchar_t * ucs1
, const __le16
* ucs2
,
106 wchar_t *anchor
= ucs1
;
108 while (n
-- && *ucs2
) /* Copy the strings */
109 *ucs1
++ = __le16_to_cpu(*ucs2
++);
112 while (n
--) /* Pad with nulls */
118 * UniToupper: Convert a unicode character to upper case
120 static inline wchar_t UniToupper(wchar_t uc
)
124 if (uc
< sizeof(UniUpperTable
)) { /* Latin characters */
125 return uc
+ UniUpperTable
[uc
]; /* Use base tables */
127 rp
= UniUpperRange
; /* Use range tables */
129 if (uc
< rp
->start
) /* Before start of range */
130 return uc
; /* Uppercase = input */
131 if (uc
<= rp
->end
) /* In range */
132 return uc
+ rp
->table
[uc
- rp
->start
];
133 rp
++; /* Try next range */
136 return uc
; /* Past last range */
141 * UniStrupr: Upper case a unicode string
143 static inline wchar_t *UniStrupr(wchar_t * upin
)
148 while (*up
) { /* For all characters */
149 *up
= UniToupper(*up
);
152 return upin
; /* Return input pointer */
155 #endif /* !_H_JFS_UNICODE */