1/* mbutil.c -- readline multibyte character utility functions */ 2 3/* Copyright (C) 2001 Free Software Foundation, Inc. 4 5 This file is part of the GNU Readline Library, a library for 6 reading lines of text with interactive input and history editing. 7 8 The GNU Readline Library is free software; you can redistribute it --- 191 unchanged lines hidden (view full) --- 200 mbstate_t *ps; 201{ 202 size_t tmp; 203 204 tmp = mbrlen((const char *)src, (size_t)strlen (src), ps); 205 if (tmp == (size_t)(-2)) 206 { 207 /* shorted to compose multibyte char */ |
208 if (ps) 209 memset (ps, 0, sizeof(mbstate_t)); |
210 return -2; 211 } 212 else if (tmp == (size_t)(-1)) 213 { 214 /* invalid to compose multibyte char */ 215 /* initialize the conversion state */ |
216 if (ps) 217 memset (ps, 0, sizeof(mbstate_t)); |
218 return -1; 219 } 220 else if (tmp == (size_t)0) 221 return 0; 222 else 223 return (int)tmp; 224} 225 226/* compare the specified two characters. If the characters matched, 227 return 1. Otherwise return 0. */ 228int 229_rl_compare_chars (buf1, pos1, ps1, buf2, pos2, ps2) |
230 char *buf1; 231 int pos1; 232 mbstate_t *ps1; 233 char *buf2; 234 int pos2; 235 mbstate_t *ps2; |
236{ 237 int i, w1, w2; 238 239 if ((w1 = _rl_get_char_len (&buf1[pos1], ps1)) <= 0 || 240 (w2 = _rl_get_char_len (&buf2[pos2], ps2)) <= 0 || 241 (w1 != w2) || 242 (buf1[pos1] != buf2[pos2])) 243 return 0; --- 32 unchanged lines hidden (view full) --- 276 if((size_t)(tmp) == (size_t)-1 || (size_t)(tmp) == (size_t)-2) 277 { 278 /* in this case, bytes are invalid or shorted to compose 279 multibyte char, so assume that the first byte represents 280 a single character anyway. */ 281 pos++; 282 /* clear the state of the byte sequence, because 283 in this case effect of mbstate is undefined */ |
284 if (ps) 285 memset (ps, 0, sizeof (mbstate_t)); |
286 } |
287 else if (tmp == 0) 288 pos++; |
289 else 290 pos += tmp; 291 } 292 293 return (pos - point); 294} 295 296int --- 49 unchanged lines hidden --- |