Linux 5.8-rc4
[linux/fpc-iii.git] / fs / jfs / jfs_unicode.h
blob9db62d047daa8ce55896cc5d365e8ac2911b6501
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (C) International Business Machines Corp., 2000-2002
4 * Portions Copyright (C) Christoph Hellwig, 2001-2002
5 */
6 #ifndef _H_JFS_UNICODE
7 #define _H_JFS_UNICODE
9 #include <linux/slab.h>
10 #include <asm/byteorder.h>
11 #include "jfs_types.h"
13 typedef struct {
14 wchar_t start;
15 wchar_t end;
16 signed char *table;
17 } UNICASERANGE;
19 extern signed char UniUpperTable[512];
20 extern UNICASERANGE UniUpperRange[];
21 extern int get_UCSname(struct component_name *, struct dentry *);
22 extern int jfs_strfromUCS_le(char *, const __le16 *, int, struct nls_table *);
24 #define free_UCSname(COMP) kfree((COMP)->name)
27 * UniStrcpy: Copy a string
29 static inline wchar_t *UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2)
31 wchar_t *anchor = ucs1; /* save the start of result string */
33 while ((*ucs1++ = *ucs2++));
34 return anchor;
40 * UniStrncpy: Copy length limited string with pad
42 static inline __le16 *UniStrncpy_le(__le16 * ucs1, const __le16 * ucs2,
43 size_t n)
45 __le16 *anchor = ucs1;
47 while (n-- && *ucs2) /* Copy the strings */
48 *ucs1++ = *ucs2++;
50 n++;
51 while (n--) /* Pad with nulls */
52 *ucs1++ = 0;
53 return anchor;
57 * UniStrncmp_le: Compare length limited string - native to little-endian
59 static inline int UniStrncmp_le(const wchar_t * ucs1, const __le16 * ucs2,
60 size_t n)
62 if (!n)
63 return 0; /* Null strings are equal */
64 while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
65 ucs1++;
66 ucs2++;
68 return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
72 * UniStrncpy_to_le: Copy length limited string with pad to little-endian
74 static inline __le16 *UniStrncpy_to_le(__le16 * ucs1, const wchar_t * ucs2,
75 size_t n)
77 __le16 *anchor = ucs1;
79 while (n-- && *ucs2) /* Copy the strings */
80 *ucs1++ = cpu_to_le16(*ucs2++);
82 n++;
83 while (n--) /* Pad with nulls */
84 *ucs1++ = 0;
85 return anchor;
89 * UniStrncpy_from_le: Copy length limited string with pad from little-endian
91 static inline wchar_t *UniStrncpy_from_le(wchar_t * ucs1, const __le16 * ucs2,
92 size_t n)
94 wchar_t *anchor = ucs1;
96 while (n-- && *ucs2) /* Copy the strings */
97 *ucs1++ = __le16_to_cpu(*ucs2++);
99 n++;
100 while (n--) /* Pad with nulls */
101 *ucs1++ = 0;
102 return anchor;
106 * UniToupper: Convert a unicode character to upper case
108 static inline wchar_t UniToupper(wchar_t uc)
110 UNICASERANGE *rp;
112 if (uc < sizeof(UniUpperTable)) { /* Latin characters */
113 return uc + UniUpperTable[uc]; /* Use base tables */
114 } else {
115 rp = UniUpperRange; /* Use range tables */
116 while (rp->start) {
117 if (uc < rp->start) /* Before start of range */
118 return uc; /* Uppercase = input */
119 if (uc <= rp->end) /* In range */
120 return uc + rp->table[uc - rp->start];
121 rp++; /* Try next range */
124 return uc; /* Past last range */
129 * UniStrupr: Upper case a unicode string
131 static inline wchar_t *UniStrupr(wchar_t * upin)
133 wchar_t *up;
135 up = upin;
136 while (*up) { /* For all characters */
137 *up = UniToupper(*up);
138 up++;
140 return upin; /* Return input pointer */
143 #endif /* !_H_JFS_UNICODE */