comparison lib/wstring.c @ 0:92745d501b9a

initial import from kinput2-v3.1
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 08 Mar 2010 04:44:30 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:92745d501b9a
1 /*
2 * wstring.c -- BSD string(3) for wchar
3 */
4
5 /*
6 * Copyright (c) 1989 Software Research Associates, Inc.
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation for any purpose and without fee is hereby granted, provided
10 * that the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of Software Research Associates not be
13 * used in advertising or publicity pertaining to distribution of the
14 * software without specific, written prior permission. Software Research
15 * Associates makes no representations about the suitability of this software
16 * for any purpose. It is provided "as is" without express or implied
17 * warranty.
18 *
19 * Author: Makoto Ishisone, Software Research Associates, Inc., Japan
20 * ishisone@sra.co.jp
21 */
22
23 /* $Id: wstring.c,v 2.2 1994/06/06 05:20:40 ishisone Rel $ */
24
25 #include "WStr.h"
26
27 wchar *
28 wstrcat(s1, s2)
29 wchar *s1, *s2;
30 {
31 wchar *ret = s1;
32
33 while (*s1++)
34 ;
35 s1--;
36
37 while (*s1++ = *s2++)
38 ;
39
40 return ret;
41 }
42
43 wchar *
44 wstrncat(s1, s2, n)
45 wchar *s1, *s2;
46 int n;
47 {
48 wchar *ret = s1;
49
50 while (*s1++)
51 ;
52 s1--;
53
54 while (n-- > 0 && (*s1++ = *s2++))
55 ;
56 if (n < 0)
57 *s1 = 0;
58
59 return ret;
60 }
61
62 int
63 wstrcmp(s1, s2)
64 wchar *s1, *s2;
65 {
66 while (*s1 && *s1 == *s2)
67 s1++, s2++;
68 return (int)(*s1 - *s2);
69 }
70
71 int
72 wstrncmp(s1, s2, n)
73 wchar *s1, *s2;
74 int n;
75 {
76 while (n-- > 0 && *s1 && *s1 == *s2)
77 s1++, s2++;
78 if (n < 0)
79 return 0;
80 return (int)(*s1 - *s2);
81 }
82
83 wchar *
84 wstrcpy(s1, s2)
85 wchar *s1, *s2;
86 {
87 wchar *ret = s1;
88
89 while (*s1++ = *s2++)
90 ;
91
92 return ret;
93 }
94
95 wchar *
96 wstrncpy(s1, s2, n)
97 wchar *s1, *s2;
98 int n;
99 {
100 wchar *ret = s1;
101
102 while (n-- > 0 && (*s1++ = *s2++))
103 ;
104 while (n-- > 0)
105 *s1++ = 0;
106
107 return ret;
108 }
109
110 int
111 wstrlen(s)
112 wchar *s;
113 {
114 int n = 0;
115
116 while (*s++)
117 n++;
118 return n;
119 }
120
121 wchar *
122 #if __STDC__ == 1
123 windex(wchar *s, wchar c)
124 #else
125 windex(s, c)
126 wchar *s, c;
127 #endif
128 {
129 int x;
130
131 while (x = *s++) {
132 if (x == c)
133 return s - 1;
134 }
135
136 return 0;
137 }
138
139 wchar *
140 #if __STDC__ == 1
141 wrindex(wchar *s, wchar c)
142 #else
143 wrindex(s, c)
144 wchar *s, c;
145 #endif
146 {
147 wchar *r = 0;
148 int x;
149
150 while (x = *s++) {
151 if (x == c)
152 r = s - 1;
153 }
154
155 return r;
156 }
157