mirror of
https://github.com/joncampbell123/dosbox-x.git
synced 2025-05-09 03:41:10 +08:00
more
This commit is contained in:
parent
6862682447
commit
e465fc0b8a
@ -1,4 +1,4 @@
|
|||||||
all: ic1 ic2 ic3 ic4
|
all: ic1 ic2 ic3 ic4 ic5
|
||||||
|
|
||||||
ic1: ic1.cpp iconvpp.o
|
ic1: ic1.cpp iconvpp.o
|
||||||
g++ -Wall -Wextra -pedantic -std=c++11 -o $@ $< iconvpp.o -liconv
|
g++ -Wall -Wextra -pedantic -std=c++11 -o $@ $< iconvpp.o -liconv
|
||||||
@ -12,9 +12,12 @@ ic3: ic3.cpp iconvpp.o
|
|||||||
ic4: ic4.cpp iconvpp.o
|
ic4: ic4.cpp iconvpp.o
|
||||||
g++ -Wall -Wextra -pedantic -std=c++11 -o $@ $< iconvpp.o -liconv
|
g++ -Wall -Wextra -pedantic -std=c++11 -o $@ $< iconvpp.o -liconv
|
||||||
|
|
||||||
|
ic5: ic5.cpp iconvpp.o
|
||||||
|
g++ -Wall -Wextra -pedantic -std=c++11 -o $@ $< iconvpp.o -liconv
|
||||||
|
|
||||||
iconvpp.o: iconvpp.cpp
|
iconvpp.o: iconvpp.cpp
|
||||||
g++ -Wall -Wextra -pedantic -std=c++11 -c -o $@ $<
|
g++ -Wall -Wextra -pedantic -std=c++11 -c -o $@ $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ic1 ic2 ic3 ic4 *.o
|
rm -f ic1 ic2 ic3 ic4 ic5 *.o
|
||||||
|
|
||||||
|
134
experiments/iconv/ic5.cpp
Normal file
134
experiments/iconv/ic5.cpp
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
|
||||||
|
#include "iconvpp.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// borrowed from DOSLIB
|
||||||
|
#define THIS_IS_JAPANESE "\x82\xb1\x82\xea\x82\xcd\x93\xfa\x96\x7b\x8c\xea\x82\xc5\x82\xb7"/* UTF-8 to Shift-JIS of "これは日本語です" */
|
||||||
|
|
||||||
|
typedef std::basic_string<uint16_t> test_string;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
_Iconv<char,uint16_t> *x = _Iconv<char,uint16_t>::create(/*FROM*/"SHIFT-JIS");
|
||||||
|
if (x == NULL) {
|
||||||
|
cerr << "Failed to create context" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_Iconv<uint16_t,char> *fx = _Iconv<uint16_t,char>::create("UTF-8");
|
||||||
|
if (fx == NULL) {
|
||||||
|
cerr << "Failed to create context" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint16_t tmp[512];
|
||||||
|
const char *src = THIS_IS_JAPANESE;
|
||||||
|
|
||||||
|
x->set_src(src);
|
||||||
|
x->set_dest(tmp,sizeof(tmp)/sizeof(tmp[0]));
|
||||||
|
|
||||||
|
int err = x->string_convert();
|
||||||
|
|
||||||
|
if (err < 0) {
|
||||||
|
cerr << "Conversion failed, " << Iconv::errstring(err) << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Test 1: " << src << endl;
|
||||||
|
cout << " Res: " << fx->string_convert(tmp) << endl;
|
||||||
|
cout << " Read: " << x->get_src_last_read() << endl;
|
||||||
|
cout << " Wrote: " << x->get_dest_last_written() << endl;
|
||||||
|
|
||||||
|
x->finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
test_string dst;
|
||||||
|
const char *src = THIS_IS_JAPANESE;
|
||||||
|
|
||||||
|
x->set_src(src);
|
||||||
|
|
||||||
|
int err = x->string_convert_dest(dst);
|
||||||
|
|
||||||
|
if (err < 0) {
|
||||||
|
cerr << "Conversion failed, " << Iconv::errstring(err) << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Test 1: " << src << endl;
|
||||||
|
cout << " Res: " << fx->string_convert(dst) << endl;
|
||||||
|
cout << " Read: " << x->get_src_last_read() << endl;
|
||||||
|
cout << " Wrote: " << x->get_dest_last_written() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint16_t tmp[512];
|
||||||
|
const char *src = THIS_IS_JAPANESE;
|
||||||
|
|
||||||
|
x->set_dest(tmp,sizeof(tmp)/sizeof(tmp[0]));
|
||||||
|
|
||||||
|
int err = x->string_convert_src(src);
|
||||||
|
|
||||||
|
if (err < 0) {
|
||||||
|
cerr << "Conversion failed, " << Iconv::errstring(err) << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Test 1: " << src << endl;
|
||||||
|
cout << " Res: " << fx->string_convert(tmp) << endl;
|
||||||
|
cout << " Read: " << x->get_src_last_read() << endl;
|
||||||
|
cout << " Wrote: " << x->get_dest_last_written() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint16_t tmp[512];
|
||||||
|
const std::string src = THIS_IS_JAPANESE;
|
||||||
|
|
||||||
|
x->set_dest(tmp,sizeof(tmp)/sizeof(tmp[0]));
|
||||||
|
|
||||||
|
int err = x->string_convert_src(src);
|
||||||
|
|
||||||
|
if (err < 0) {
|
||||||
|
cerr << "Conversion failed, " << Iconv::errstring(err) << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Test 1: " << src << endl;
|
||||||
|
cout << " Res: " << fx->string_convert(tmp) << endl;
|
||||||
|
cout << " Read: " << x->get_src_last_read() << endl;
|
||||||
|
cout << " Wrote: " << x->get_dest_last_written() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
test_string dst;
|
||||||
|
const std::string src = THIS_IS_JAPANESE;
|
||||||
|
|
||||||
|
int err = x->string_convert(dst,src);
|
||||||
|
|
||||||
|
if (err < 0) {
|
||||||
|
cerr << "Conversion failed, " << Iconv::errstring(err) << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Test 1: " << src << endl;
|
||||||
|
cout << " Res: " << fx->string_convert(dst) << endl;
|
||||||
|
cout << " Read: " << x->get_src_last_read() << endl;
|
||||||
|
cout << " Wrote: " << x->get_dest_last_written() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const std::string src = THIS_IS_JAPANESE;
|
||||||
|
test_string dst = x->string_convert(src);
|
||||||
|
|
||||||
|
cout << "Test 1: " << src << endl;
|
||||||
|
cout << " Res: " << fx->string_convert(dst) << endl;
|
||||||
|
cout << " Read: " << x->get_src_last_read() << endl;
|
||||||
|
cout << " Wrote: " << x->get_dest_last_written() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete fx;
|
||||||
|
delete x;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user