X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=lib%2Freadline%2Fmbutil.c;h=858842e627550024d7f2560380c9714c5e73e03e;hb=3185942a5234e26ab13fa02f9c51d340cec514f8;hp=695845a60f4e5fbc5a765ca2a34ac9a00d2673c9;hpb=eb87367179effbe5f430236db8259006d71438b7;p=platform%2Fupstream%2Fbash.git diff --git a/lib/readline/mbutil.c b/lib/readline/mbutil.c index 695845a..858842e 100644 --- a/lib/readline/mbutil.c +++ b/lib/readline/mbutil.c @@ -1,24 +1,24 @@ /* mbutil.c -- readline multibyte character utility functions */ -/* Copyright (C) 2001-2004 Free Software Foundation, Inc. +/* Copyright (C) 2001-2009 Free Software Foundation, Inc. - This file is part of the GNU Readline Library, a library for - reading lines of text with interactive input and history editing. + This file is part of the GNU Readline Library (Readline), a library + for reading lines of text with interactive input and history editing. - The GNU Readline Library is free software; you can redistribute it - and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2, or + Readline is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - The GNU Readline Library is distributed in the hope that it will be - useful, but WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + Readline is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - The GNU General Public License is often shipped with GNU software, and - is generally kept in a file called COPYING or LICENSE. If you do not - have a copy of the license, write to the Free Software Foundation, - 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Readline. If not, see . +*/ + #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) @@ -77,20 +77,23 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) char *string; int seed, count, find_non_zero; { - size_t tmp = 0; + size_t tmp; mbstate_t ps; - int point = 0; + int point; wchar_t wc; + tmp = 0; + memset(&ps, 0, sizeof (mbstate_t)); if (seed < 0) seed = 0; if (count <= 0) return seed; - point = seed + _rl_adjust_point(string, seed, &ps); - /* if this is true, means that seed was not pointed character - started byte. So correct the point and consume count */ + point = seed + _rl_adjust_point (string, seed, &ps); + /* if this is true, means that seed was not pointing to a byte indicating + the beginning of a multibyte character. Correct the point and consume + one char. */ if (seed < point) count--; @@ -99,7 +102,7 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) tmp = mbrtowc (&wc, string+point, strlen(string + point), &ps); if (MB_INVALIDCH ((size_t)tmp)) { - /* invalid bytes. asume a byte represents a character */ + /* invalid bytes. assume a byte represents a character */ point++; count--; /* reset states. */ @@ -126,15 +129,14 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) if (find_non_zero) { tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps); - while (tmp > 0 && wcwidth (wc) == 0) + while (MB_NULLWCH (tmp) == 0 && MB_INVALIDCH (tmp) == 0 && wcwidth (wc) == 0) { point += tmp; tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps); - if (MB_NULLWCH (tmp) || MB_INVALIDCH (tmp)) - break; } } - return point; + + return point; } static int @@ -313,6 +315,28 @@ _rl_is_mbchar_matched (string, seed, end, mbchar, length) return 0; return 1; } + +wchar_t +_rl_char_value (buf, ind) + char *buf; + int ind; +{ + size_t tmp; + wchar_t wc; + mbstate_t ps; + int l; + + if (MB_LEN_MAX == 1 || rl_byte_oriented) + return ((wchar_t) buf[ind]); + l = strlen (buf); + if (ind >= l - 1) + return ((wchar_t) buf[ind]); + memset (&ps, 0, sizeof (mbstate_t)); + tmp = mbrtowc (&wc, buf + ind, l - ind, &ps); + if (MB_INVALIDCH (tmp) || MB_NULLWCH (tmp)) + return ((wchar_t) buf[ind]); + return wc; +} #endif /* HANDLE_MULTIBYTE */ /* Find next `count' characters started byte point of the specified seed.