~ubuntu-branches/debian/stretch/jfsutils/stretch

« back to all changes in this revision

Viewing changes to include/jfs_unicode.h

  • Committer: Bazaar Package Importer
  • Author(s): Christopher L Cheney
  • Date: 2002-02-10 01:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20020210010000-v63g4150dcpnehzq
Tags: upstream-1.0.14
ImportĀ upstreamĀ versionĀ 1.0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (c) International Business Machines  Corp., 2000
 
3
 *
 
4
 *   This program is free software;  you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU General Public License as published by
 
6
 *   the Free Software Foundation; either version 2 of the License, or 
 
7
 *   (at your option) any later version.
 
8
 * 
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 
12
 *   the GNU General Public License for more details.
 
13
 *
 
14
 *   You should have received a copy of the GNU General Public License
 
15
 *   along with this program;  if not, write to the Free Software 
 
16
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
17
 *
 
18
 *
 
19
 * Notes:
 
20
 *     These APIs are based on the C library functions.  The semantics
 
21
 *     should match the C functions but with expanded size operands.
 
22
 *
 
23
 *     The upper/lower functions are based on a table created by mkupr.
 
24
 *     This is a compressed table of upper and lower case conversion.
 
25
 *
 
26
 */
 
27
 
 
28
 
 
29
typedef struct {
 
30
        UniChar start;
 
31
        UniChar end;
 
32
        signed char *table;
 
33
} UNICASERANGE;
 
34
 
 
35
extern signed char UniUpperTable[512];
 
36
extern UNICASERANGE UniUpperRange[];
 
37
 
 
38
/*
 
39
 * UniStrcpy:  Copy a string
 
40
 */
 
41
static inline UniChar *UniStrcpy(UniChar * ucs1, const UniChar * ucs2)
 
42
{
 
43
        UniChar *anchor = ucs1; /* save the start of result string */
 
44
 
 
45
        while ((*ucs1++ = *ucs2++));
 
46
        return anchor;
 
47
}
 
48
 
 
49
 
 
50
/*
 
51
 * UniStrlen:  Return the length of a string
 
52
 */
 
53
static inline size_t UniStrlen(const UniChar * ucs1)
 
54
{
 
55
        int i = 0;
 
56
 
 
57
        while (*ucs1++)
 
58
                i++;
 
59
        return i;
 
60
}
 
61
 
 
62
 
 
63
/*
 
64
 * UniStrncmp:  Compare length limited string
 
65
 */
 
66
static inline int UniStrncmp(const UniChar * ucs1, const UniChar * ucs2,
 
67
                             size_t n)
 
68
{
 
69
        if (!n)
 
70
                return 0;       /* Null strings are equal */
 
71
        while ((*ucs1 == *ucs2) && *ucs1 && --n) {
 
72
                ucs1++;
 
73
                ucs2++;
 
74
        }
 
75
        return (int) *ucs1 - (int) *ucs2;
 
76
}
 
77
 
 
78
 
 
79
/*
 
80
 * UniStrncpy:  Copy length limited string with pad
 
81
 */
 
82
static inline UniChar *UniStrncpy(UniChar * ucs1, const UniChar * ucs2,
 
83
                                  size_t n)
 
84
{
 
85
        UniChar *anchor = ucs1;
 
86
 
 
87
        while (n-- && *ucs2)    /* Copy the strings */
 
88
                *ucs1++ = *ucs2++;
 
89
 
 
90
        n++;
 
91
        while (n--)             /* Pad with nulls */
 
92
                *ucs1++ = 0;
 
93
        return anchor;
 
94
}
 
95
 
 
96
 
 
97
/*
 
98
 * UniToupper:  Convert a unicode character to upper case
 
99
 */
 
100
static inline UniChar UniToupper(register UniChar uc)
 
101
{
 
102
        register UNICASERANGE *rp;
 
103
 
 
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
 
 
120
/*
 
121
 * UniStrupr:  Upper case a unicode string
 
122
 */
 
123
static inline UniChar *UniStrupr(register UniChar * upin)
 
124
{
 
125
        register UniChar *up;
 
126
 
 
127
        up = upin;
 
128
        while (*up) {           /* For all characters */
 
129
                *up = UniToupper(*up);
 
130
                up++;
 
131
        }
 
132
        return upin;            /* Return input pointer */
 
133
}
 
134