From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22187 invoked by alias); 27 Oct 2015 09:10:34 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36973 Received: (qmail 7844 invoked from network); 27 Oct 2015 09:10:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f5-f794b6d000001495-fe-562f3f84e0d6 Date: Tue, 27 Oct 2015 09:10:26 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Question about mb_metastrlen Message-id: <20151027091026.5197b79f@pwslap01u.europe.root.pri> In-reply-to: References: Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMLMWRmVeSWpSXmKPExsVy+t/xq7ot9vphBl0d/BYHmx8yOTB6rDr4 gSmAMYrLJiU1J7MstUjfLoEr49u6D0wFDzkr2mctZ2tg3MbexcjJISFgInH03zFWCFtM4sK9 9WxdjFwcQgJLGSU2H3sM5cxgkrja94URwtnGKHF69xwWkBYWAVWJCd3tYDabgKHE1E2zGUFs EQFxibNrz4PFhQU0JXpWXgeL8wrYS3w8+YEZxOYUCJaY8fUdUJwDaGiAxL0JciBhfgF9iat/ PzFBXGQvMfPKGahWQYkfk++BjWQW0JLYvK2JFcKWl9i85i3YSCEBdYkbd3ezT2AUmoWkZRaS lllIWhYwMq9iFE0tTS4oTkrPNdIrTswtLs1L10vOz93ECAnarzsYlx6zOsQowMGoxMNrUKEX JsSaWFZcmXuIUYKDWUmEV1BHP0yINyWxsiq1KD++qDQntfgQozQHi5I478xd70OEBNITS1Kz U1MLUotgskwcnFINjLnfFn3uZvLr3zrXj+W+VuG8mnW/l1zi1LU9Er/FbDu7g4xqUu4EZcmQ Den5p64ZswlKfOTMS926MGUj7+eSucmPvRzPHQ2KaU2ufC2hU/OSU13tTeiiCn4XlhlrN0zQ dut5ve+1+b5ZmkfuJ2/4fcic+dUM4RtvJm+59OGf6Dumiw2ukTu445VYijMSDbWYi4oTAQhV 9uBWAgAA On Tue, 27 Oct 2015 09:31:02 +0100 Sebastian Gniazdowski wrote: > Hello, > the function counts bytes in last incomplete wide character: > > ret = mbrtowc(&wc, &inchar, 1, &mb_shiftstate); > if (ret == MB_INCOMPLETE) { > num_in_char++; > } else { > > When returning, it makes use of the count: > > /* If incomplete, treat remainder as trailing single bytes */ > return num + num_in_char; > > Strings are stored in wchar_t arrays. The incomplete character will > occupy single index, correct? So maybe the return should be: > > return num + ( num_in_char > 0 ? 1 : 0 ); The function you're talking about is for a string length, not a character length. num_in_char counts the number of trailing bytes that didn't form a wide character. Each will be treated as a single byte. So each counts 1 for the length of the string. I think your answer would be correct for a function that counts just the next character (i.e. mb_metacharlenconv()), but I think that's already doing what you'd expect in that case. That's the intention of the function, anyway, but if you can see a use that's inconsistent with it there could be a bug there. pws