ALT Linux Team development discussions
 help / color / mirror / Atom feed
* [devel] codecvt + UTF-8 - не работает преобразование.
@ 2006-06-14 14:35 Anriy Stepanov
  0 siblings, 0 replies; only message in thread
From: Anriy Stepanov @ 2006-06-14 14:35 UTC (permalink / raw)
  To: devel

Написал програмку для тестирования:

#include <iostream>
#include <locale>
#include <clocale>
#include <string>
#include <limits>
#include <climits>

using namespace std;

int main()
{
         setlocale(LC_ALL, "");
locale const loc = locale(""); // System locale (ru_RU.UTF-8)

typedef codecvt_base::result res;
typedef codecvt<wchar_t, char, mbstate_t> my_codecvt; // internal,
external, state
locale const new_locale(loc, new my_codecvt); // locale with codecvt facet
const my_codecvt& cdcvt = use_facet<my_codecvt>(new_locale);
mbstate_t state;
res r;

const char *in_next = 0;
wchar_t *out_next = 0;

string s("Строка!");
// string s("String!");
const int bytes = s.length();
const int symbols = 7;

wstring ws(L'.', symbols);
cout << "Bytes: " << bytes << endl;
cout << "Symbols: " << symbols << endl;

r = cdcvt.in(state, s.c_str(), s.c_str()+s.size(), in_next,
&ws[0], &ws[0] + ws.size(), out_next);

cout << "Encoding result: ";
cout << (r == codecvt_base::ok ? "Succes!" : "Fail!") << endl;
 
cout << "Was: " << s << endl;  
wcout << "Is: " << ws << endl;

return 0;
}

Если роскоментировать string s("String!"); то все работает как надо.
Создаестся строка с wide char.
И результат:
Bytes: 7
Symbols: 7
Encoding result: Succes!
Was: String!
Is: String!
Т.е. преобразование работает.

Но если раскоментировать string s("Строка!"); то оно не может
преобразовать multi byte symbols в wide chars....

Результат выполнения:
Bytes: 13
Symbols: 7
Encoding result: Fail!
Was: Строка!
Is:

Вот.

локаль UTF-8

Почему оно не может string c multi bytes characters (где один символ
занимает несколько байт, но не каждый) UTF-8 перенести в whar_t ?


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-06-14 14:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-14 14:35 [devel] codecvt + UTF-8 - не работает преобразование Anriy Stepanov

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git