469,644 Members | 2,030 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,644 developers. It's quick & easy.

Collating multi-byte strings

Assuming my locale has enough info about codepage and multi-byte
charecters, how should I compare (collate) multi-byte strings (strings
of multi-byte charecters with zero-byte at the end) in ISO C99?

Thanks in advance
Vir

Nov 14 '05 #1
2 1934
In <bv***********@av9195.comtv.ru> Victor Nazarov <vv*****@mail.ru> writes:
Assuming my locale has enough info about codepage and multi-byte
charecters, how should I compare (collate) multi-byte strings (strings
of multi-byte charecters with zero-byte at the end) in ISO C99?


strcoll(), being declared in <string.h>, doesn't seem to be appropriate
for what you want. But I could be wrong on that, the standard being less
than clear on the issue.

In the absence of a mbscoll() function, it seems that your only
alternative is to use mbstowcs() to convert your strings to wide
character strings and then use wcscoll() to compare them.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #2
Dan Pop –…ŘŇ‘:
In <bv***********@av9195.comtv.ru> Victor Nazarov <vv*****@mail.ru> writes:

Assuming my locale has enough info about codepage and multi-byte
charecters, how should I compare (collate) multi-byte strings (strings
of multi-byte charecters with zero-byte at the end) in ISO C99?

strcoll(), being declared in <string.h>, doesn't seem to be appropriate
for what you want. But I could be wrong on that, the standard being less
than clear on the issue.

In the absence of a mbscoll() function, it seems that your only
alternative is to use mbstowcs() to convert your strings to wide
character strings and then use wcscoll() to compare them.

Dan


what about:
#include <stdlib.h>
#include <wchar.h>

int my_mbscoll (const char *s, const char *t)
{
wchar_t ws[2], wt[2];
int res;

do {
s += mbtowc (&ws[0], s, MB_CUR_MAX);
t += mbtowc (&wt[0], t, MB_CUR_MAX);
ws[1] = wt[1] = 0;
res = wcscoll (ws, wt);
} while (ws[0] && res == 0);
return res;
}
Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Yaro | last post: by
3 posts views Thread by s_subbarayan | last post: by
5 posts views Thread by bobwansink | last post: by
reply views Thread by HelmutStoneCorner | last post: by
17 posts views Thread by Ron Adam | last post: by
reply views Thread by Frank Swarbrick | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.