157 }
158
159 /*
160 * Determine whether or not a character is an lowercase character.
161 * This function operates on the current codepage table. Returns
162 * non-zero if the character is lowercase. Otherwise returns zero.
163 */
164 int
165 smb_islower(int c)
166 {
167 uint16_t mask = is_unicode ? 0xffff : 0xff;
168
169 return (current_codepage[c & mask].ctype & CODEPAGE_ISLOWER);
170 }
171
172 /*
173 * Convert individual characters to their uppercase equivalent value.
174 * If the specified character is lowercase, the uppercase value will
175 * be returned. Otherwise the original value will be returned.
176 */
177 int
178 smb_toupper(int c)
179 {
180 uint16_t mask = is_unicode ? 0xffff : 0xff;
181
182 return (current_codepage[c & mask].upper);
183 }
184
185 /*
186 * Convert individual characters to their lowercase equivalent value.
187 * If the specified character is uppercase, the lowercase value will
188 * be returned. Otherwise the original value will be returned.
189 */
190 int
191 smb_tolower(int c)
192 {
193 uint16_t mask = is_unicode ? 0xffff : 0xff;
194
195 return (current_codepage[c & mask].lower);
196 }
197
198 /*
199 * Convert a string to uppercase using the appropriate codepage. The
200 * string is converted in place. A pointer to the string is returned.
201 * There is an assumption here that uppercase and lowercase values
202 * always result encode to the same length.
203 */
204 char *
205 smb_strupr(char *s)
206 {
207 smb_wchar_t c;
208 char *p = s;
209
210 while (*p) {
211 if (smb_isascii(*p)) {
212 *p = smb_toupper(*p);
213 p++;
214 } else {
215 if (smb_mbtowc(&c, p, MTS_MB_CHAR_MAX) < 0)
216 return (0);
217
218 if (c == 0)
219 break;
220
221 c = smb_toupper(c);
222 p += smb_wctomb(p, c);
223 }
224 }
225
226 return (s);
227 }
228
229 /*
230 * Convert a string to lowercase using the appropriate codepage. The
231 * string is converted in place. A pointer to the string is returned.
232 * There is an assumption here that uppercase and lowercase values
233 * always result encode to the same length.
234 */
235 char *
236 smb_strlwr(char *s)
237 {
238 smb_wchar_t c;
239 char *p = s;
240
241 while (*p) {
242 if (smb_isascii(*p)) {
243 *p = smb_tolower(*p);
244 p++;
245 } else {
246 if (smb_mbtowc(&c, p, MTS_MB_CHAR_MAX) < 0)
247 return (0);
248
249 if (c == 0)
250 break;
251
252 c = smb_tolower(c);
253 p += smb_wctomb(p, c);
254 }
255 }
256
257 return (s);
258 }
259
260 /*
261 * Returns 1 if string contains NO uppercase chars 0 otherwise. However,
262 * -1 is returned if "s" is not a valid multi-byte string.
263 */
264 int
265 smb_isstrlwr(const char *s)
266 {
267 smb_wchar_t c;
268 int n;
269 const char *p = s;
270
271 while (*p) {
272 if (smb_isascii(*p) && smb_isupper(*p))
273 return (0);
274 else {
275 if ((n = smb_mbtowc(&c, p, MTS_MB_CHAR_MAX)) < 0)
276 return (-1);
277
278 if (c == 0)
279 break;
280
281 if (smb_isupper(c))
282 return (0);
283
284 p += n;
285 }
286 }
287
288 return (1);
289 }
290
291 /*
292 * Returns 1 if string contains NO lowercase chars 0 otherwise. However,
293 * -1 is returned if "s" is not a valid multi-byte string.
294 */
295 int
296 smb_isstrupr(const char *s)
297 {
298 smb_wchar_t c;
299 int n;
300 const char *p = s;
301
302 while (*p) {
303 if (smb_isascii(*p) && smb_islower(*p))
304 return (0);
305 else {
306 if ((n = smb_mbtowc(&c, p, MTS_MB_CHAR_MAX)) < 0)
307 return (-1);
308
309 if (c == 0)
310 break;
311
312 if (smb_islower(c))
313 return (0);
314
315 p += n;
316 }
317 }
318
|
157 }
158
159 /*
160 * Determine whether or not a character is an lowercase character.
161 * This function operates on the current codepage table. Returns
162 * non-zero if the character is lowercase. Otherwise returns zero.
163 */
164 int
165 smb_islower(int c)
166 {
167 uint16_t mask = is_unicode ? 0xffff : 0xff;
168
169 return (current_codepage[c & mask].ctype & CODEPAGE_ISLOWER);
170 }
171
172 /*
173 * Convert individual characters to their uppercase equivalent value.
174 * If the specified character is lowercase, the uppercase value will
175 * be returned. Otherwise the original value will be returned.
176 */
177 uint32_t
178 smb_toupper(uint32_t c)
179 {
180 uint16_t mask = is_unicode ? 0xffff : 0xff;
181
182 return (current_codepage[c & mask].upper);
183 }
184
185 /*
186 * Convert individual characters to their lowercase equivalent value.
187 * If the specified character is uppercase, the lowercase value will
188 * be returned. Otherwise the original value will be returned.
189 */
190 uint32_t
191 smb_tolower(uint32_t c)
192 {
193 uint16_t mask = is_unicode ? 0xffff : 0xff;
194
195 return (current_codepage[c & mask].lower);
196 }
197
198 /*
199 * Convert a string to uppercase using the appropriate codepage. The
200 * string is converted in place. A pointer to the string is returned.
201 * There is an assumption here that uppercase and lowercase values
202 * always result encode to the same length.
203 */
204 char *
205 smb_strupr(char *s)
206 {
207 uint32_t c;
208 char *p = s;
209
210 while (*p) {
211 if (smb_isascii(*p)) {
212 *p = smb_toupper(*p);
213 p++;
214 } else {
215 if (smb_mbtowc(&c, p, MTS_MB_CHAR_MAX) < 0)
216 return (0);
217
218 if (c == 0)
219 break;
220
221 c = smb_toupper(c);
222 p += smb_wctomb(p, c);
223 }
224 }
225
226 return (s);
227 }
228
229 /*
230 * Convert a string to lowercase using the appropriate codepage. The
231 * string is converted in place. A pointer to the string is returned.
232 * There is an assumption here that uppercase and lowercase values
233 * always result encode to the same length.
234 */
235 char *
236 smb_strlwr(char *s)
237 {
238 uint32_t c;
239 char *p = s;
240
241 while (*p) {
242 if (smb_isascii(*p)) {
243 *p = smb_tolower(*p);
244 p++;
245 } else {
246 if (smb_mbtowc(&c, p, MTS_MB_CHAR_MAX) < 0)
247 return (0);
248
249 if (c == 0)
250 break;
251
252 c = smb_tolower(c);
253 p += smb_wctomb(p, c);
254 }
255 }
256
257 return (s);
258 }
259
260 /*
261 * Returns 1 if string contains NO uppercase chars 0 otherwise. However,
262 * -1 is returned if "s" is not a valid multi-byte string.
263 */
264 int
265 smb_isstrlwr(const char *s)
266 {
267 uint32_t c;
268 int n;
269 const char *p = s;
270
271 while (*p) {
272 if (smb_isascii(*p) && smb_isupper(*p))
273 return (0);
274 else {
275 if ((n = smb_mbtowc(&c, p, MTS_MB_CHAR_MAX)) < 0)
276 return (-1);
277
278 if (c == 0)
279 break;
280
281 if (smb_isupper(c))
282 return (0);
283
284 p += n;
285 }
286 }
287
288 return (1);
289 }
290
291 /*
292 * Returns 1 if string contains NO lowercase chars 0 otherwise. However,
293 * -1 is returned if "s" is not a valid multi-byte string.
294 */
295 int
296 smb_isstrupr(const char *s)
297 {
298 uint32_t c;
299 int n;
300 const char *p = s;
301
302 while (*p) {
303 if (smb_isascii(*p) && smb_islower(*p))
304 return (0);
305 else {
306 if ((n = smb_mbtowc(&c, p, MTS_MB_CHAR_MAX)) < 0)
307 return (-1);
308
309 if (c == 0)
310 break;
311
312 if (smb_islower(c))
313 return (0);
314
315 p += n;
316 }
317 }
318
|