ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Anriy Stepanov <stanv@altlinux.ru>
To: devel@lists.altlinux.org
Subject: [devel] codecvt + UTF-8 - не работает преобразование.
Date: Wed, 14 Jun 2006 18:35:39 +0400
Message-ID: <44901EBB.4040703@altlinux.ru> (raw)

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

#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 ?


                 reply	other threads:[~2006-06-14 14:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44901EBB.4040703@altlinux.ru \
    --to=stanv@altlinux.ru \
    --cc=devel@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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