57 #ifndef __BABEL_BABEL_H__
59 #define __BABEL_BABEL_H__
61 #if !defined(__WITH_BABEL__)
62 # define __WITH_BABEL__
67 #if defined(NDEBUG) && defined(_DEBUG)
80 # if defined(__BORLANDC__)
81 # if !defined(__UNICODE_CHAR_SIZE_2__)
82 # define __UNICODE_CHAR_SIZE_2__
84 # if !defined(__LITTLE_ENDIAN_COMPUTER__)
85 # define __LITTLE_ENDIAN_COMPUTER__
87 # if !(defined(__USING_ANSI__) || defined(__USING_SJIS__) || defined(__USING_EUC__) || defined(__USING_UTF8__) || defined(__USING_UNKNOWN__))
88 # define __USING_SJIS__
93 # if defined(__MWERKS__)
97 # if defined(_MSC_VER)
98 # if !defined(__UNICODE_CHAR_SIZE_2__)
99 # define __UNICODE_CHAR_SIZE_2__
101 # if !defined(__LITTLE_ENDIAN_COMPUTER__)
102 # define __LITTLE_ENDIAN_COMPUTER__
104 # if !(defined(__USING_ANSI__) || defined(__USING_SJIS__) || defined(__USING_EUC__) || defined(__USING_UTF8__) || defined(__USING_UNKNOWN__))
105 # define __USING_SJIS__
110 # if defined(__GNUC__)
126 # if !(defined(__UNICODE_CHAR_SIZE_2__) || defined(__UNICODE_CHAR_SIZE_4__))
127 # define __UNICODE_CHAR_SIZE_UNKNOWN__
143 # if !(defined(__LITTLE_ENDIAN_COMPUTER__) || defined(__BIG_ENDIAN_COMPUTER__))
144 # define __UNKNOWN_ENDIAN_COMPUTER__
162 # if !(defined(__USING_ANSI__) || defined(__USING_SJIS__) || defined(__USING_EUC__) || defined(__USING_UTF8__) || defined(__USING_UNKNOWN__))
163 # define __USING_UNKNOWN__
179 # if !(defined(__BBL_STRING_DEFAULT__) || defined(__BBL_WSTRING_DEFAULT__))
180 # define __BBL_STRING_DEFAULT__
209 # if defined(__BBL_USING_STATIC_TABLE__) && defined(__BBL_USING_STDMAP_TABLE__)
210 # error マッピング実装方法指定マクロはどれか一つにしてください。
213 # if !(defined(__BBL_USING_STATIC_TABLE__) || defined(__BBL_USING_STDMAP_TABLE__))
214 # define __BBL_USING_STATIC_TABLE__
249 # if defined(__BBL_USE_UNICODE_MAP_CP932__) && defined(__BBL_USE_UNICODE_MAP_UTC__) || \
250 defined(__BBL_USE_UNICODE_MAP_CP932__) && defined(__BBL_USE_UNICODE_MAP_APPLE__) || \
251 defined(__BBL_USE_UNICODE_MAP_UTC__) && defined(__BBL_USE_UNICODE_MAP_APPLE__)
252 # error UNICODE⇔Shift_JISマッピングデフォルト指定マクロはどれか一つにしてください。
255 # if !(defined(__BBL_USE_UNICODE_MAP_CP932__) || defined(__BBL_USE_UNICODE_MAP_UTC__) || defined(__BBL_USE_UNICODE_MAP_APPLE__))
256 # define __BBL_USE_UNICODE_MAP_CP932__
261 # if defined(__BBL_USE_UNICODE_MAP_CP932__) && !defined(__BBL_LOAD_UNICODE_MAP_CP932__)
262 # define __BBL_LOAD_UNICODE_MAP_CP932__
265 # if defined(__BBL_USE_UNICODE_MAP_UTC__) && !defined(__BBL_LOAD_UNICODE_MAP_UTC__)
266 # define __BBL_LOAD_UNICODE_MAP_UTC__
269 # if defined(__BBL_USE_UNICODE_MAP_APPLE__) && !defined(__BBL_LOAD_UNICODE_MAP_APPLE__)
270 # define __BBL_LOAD_UNICODE_MAP_APPLE__
299 #define __BBL_DISABLE_UTF32__ // UTF-32 の実装を他では見かけないのでバベルでも(実装してもあまり意味がないので)デフォルトでは off 。
304 # if defined(__BBL_DISABLE_UNICODE__)
305 # if defined(__BBL_LOAD_UNICODE_MAP_CP932__)
306 # undef __BBL_LOAD_UNICODE_MAP_CP932__
308 # if defined(__BBL_LOAD_UNICODE_MAP_UTC__)
309 # undef __BBL_LOAD_UNICODE_MAP_UTC__
311 # if defined(__BBL_LOAD_UNICODE_MAP_APPLE__)
312 # undef __BBL_LOAD_UNICODE_MAP_APPLE__
314 # if defined(__BBL_STRICT_TRANSLATE__)
315 # undef __BBL_STRICT_TRANSLATE__
317 # if !defined(__BBL_DISABLE_BINARY__)
318 # define __BBL_DISABLE_BINARY__
320 # if !defined(__BBL_DISABLE_UTF32__)
321 # define __BBL_DISABLE_UTF32__
325 # if defined(__BBL_DISABLE_BINARY__)
326 # if !defined(__BBL_DISABLE_UTF32__)
327 # define __BBL_DISABLE_UTF32__
333 # if !defined(__BBL_DISABLE_UNICODE__)
334 # if !defined(__BBL_USE_UNICODE__)
335 # define __BBL_USE_UNICODE__
339 # if !defined(__BBL_DISABLE_BINARY__)
340 # if !defined(__BBL_USE_BINARY__)
341 # define __BBL_USE_BINARY__
345 # if !defined(__BBL_DISABLE_UTF32__)
346 # if !defined(__BBL_USE_UTF32__)
347 # define __BBL_USE_UTF32__
351 # if !defined(__BBL_DISABLE_SELECTORS__)
352 # if !defined(__BBL_USE_SELECTORS__)
353 # define __BBL_USE_SELECTORS__
363 #define __BBL_LARGE_BOM_LOGIC__
371 # if defined(__BORLANDC__)
393 bbl_demi(
const T &X_value) :value(X_value) {}
396 operator T& () {
return value; }
397 operator const T& ()
const {
return value; }
399 T * operator & () {
return &value; }
400 const T * operator & ()
const {
return &value; }
402 T & operator () () {
return value; }
403 const T & operator () ()
const {
return value; }
418 #if defined(__BABEL_WITH_BUG__)
422 #define __BUG_STATEMENT_HACK__ // ステートメントハックの指定
423 #include "..\bugbeard\bug.h"
424 #endif // defined(__BABEL_WITH_BUG__)
427 typedef std::string bbl_binary;
428 typedef std::string bbl_string;
429 #if defined(__BBL_USE_UNICODE__)
431 typedef std::basic_string<wchar_t> bbl_wstring;
432 #endif // defined(__BBL_USE_UNICODE__)
434 inline const bbl_string & binary_to_string(
const bbl_binary &X) {
return X; }
435 inline const bbl_binary & string_to_binary(
const bbl_string &X) {
return X; }
437 #if defined(__BBL_STRING_DEFAULT__)
438 typedef bbl_string bbl_default_string;
440 typedef bbl_wstring bbl_default_string;
448 const bbl_string broken_char =
"?";
449 const bbl_string empty =
"";
450 #if defined(__BBL_USE_UNICODE__)
451 const bbl_wstring broken_wchar = L
"?";
452 const bbl_wstring wempty = L
"";
453 #endif // defined(__BBL_USE_UNICODE__)
454 #if defined(__BBL_USE_UNICODE__)
455 const bbl_string utf8_FEFF =
"\xEF\xBB\xBF";
457 const bbl_wstring unicode_bom((bbl_wstring::size_type)1, (bbl_wstring::value_type)0xFEFF);
458 #endif // defined(__BBL_USE_UNICODE__)
459 const bbl_string babel_version =
"information>\n"
460 "\tmodule>\tid=babel\n"
461 "\t\tname=バベル -babel- \n"
462 "\t\turl=http://tricklib.com/cxx/ex/babel/\n"
464 "\tauthor>\tid=wraith\n"
466 "\t\turl=http://www.trickpalace.net/\n"
467 "\t\tmail=wraith@trickpalace.net\n";
470 operator const bbl_string &()
const {
return broken_char; }
471 #if defined(__BBL_USE_UNICODE__)
472 operator const bbl_wstring &()
const {
return broken_wchar; }
473 #endif // defined(__BBL_USE_UNICODE__)
476 #if defined(__BBL_USE_UNICODE__)
478 operator const bbl_string &()
const {
return utf8_FEFF; }
479 operator const bbl_wstring &()
const {
return unicode_bom; }
481 #endif // defined(__BBL_USE_UNICODE__)
484 operator const bbl_string &()
const {
return empty; }
485 #if defined(__BBL_USE_UNICODE__)
486 operator const bbl_wstring &()
const {
return wempty; }
487 #endif // defined(__BBL_USE_UNICODE__)
496 #if defined(__BBL_USE_UNICODE__)
497 inline const int get_base_wstring_size() {
498 return sizeof(bbl_wstring::value_type);
500 #endif // defined(__BBL_USE_UNICODE__)
502 namespace base_endian {
510 inline const int get_base_endian() {
511 using namespace base_endian;
512 #ifdef __LITTLE_ENDIAN_COMPUTER__
513 return little_endian;
515 #ifdef __BIG_ENDIAN_COMPUTER__
518 #ifdef __UNKNOWN_ENDIAN_COMPUTER__
519 const int fingerprint = 0x01;
520 return 0x01 == *((
char*)&fingerprint) ? little_endian: big_endian;
524 namespace base_encoding {
538 #ifdef __LITTLE_ENDIAN_COMPUTER__
542 #ifdef __BIG_ENDIAN_COMPUTER__
546 #ifdef __UNKNOWN_ENDIAN_COMPUTER__
550 #ifdef __UNICODE_CHAR_SIZE_2__
553 #ifdef __UNICODE_CHAR_SIZE_4__
556 #ifdef __UNICODE_CHAR_SIZE_UNKNOWN__
626 namespace profile_for_UI {
629 inline const unsigned int get_list_size_for_UI() {
630 #if defined(__BBL_USE_UNICODE__)
632 #else // defined(__BBL_USE_UNICODE__)
633 # if defined(__BBL_USE_UTF32__)
635 # else // defined(__BBL_USE_UTF32__)
637 # endif // defined(__BBL_USE_UTF32__)
638 #endif // defined(__BBL_USE_UNICODE__)
640 inline const int get_id_for_UI(
unsigned int index) {
641 assert(index < get_list_size_for_UI());
642 using namespace base_encoding;
643 const int id_for_UI[] = {
649 #if defined(__BBL_USE_UNICODE__)
653 # if defined(__BBL_USE_UTF32__)
656 # endif // defined(__BBL_USE_UTF32__)
657 #endif // defined(__BBL_USE_UNICODE__)
659 assert(
sizeof(id_for_UI) /
sizeof(id_for_UI[0]) == get_list_size_for_UI());
660 return id_for_UI[index];
666 inline const bbl_string get_name_for_UI(
unsigned int index) {
667 assert(index < get_list_size_for_UI());
668 const char * name_for_UI[] = {
674 #if defined(__BBL_USE_UNICODE__)
678 # if defined(__BBL_USE_UTF32__)
681 # endif // defined(__BBL_USE_UTF32__)
682 #endif // defined(__BBL_USE_UNICODE__)
684 return name_for_UI[index];
692 inline const bbl_string get_base_encoding_name(
unsigned int index) {
693 const char *base_encoding_name[] = {
709 return base_encoding_name[index];
714 inline const int get_base_encoding() {
715 using namespace base_encoding;
716 #ifdef __USING_ANSI__
719 #ifdef __USING_SJIS__
725 #ifdef __USING_UTF8__
728 #ifdef __USING_UNKNOWN__
729 const int fingerprint = ((
unsigned char*)(
"漢字"))[0];
730 if (0x8A == fingerprint) {
733 if (0x84 == fingerprint) {
736 if (0xE6 == fingerprint) {
744 bbl_binary::size_type get_aspect_position(
const bbl_binary &X);
747 typedef int value_type;
748 const value_type hunch_result;
749 const value_type strict_result;
752 :hunch_result(X_hunch_result), strict_result(X_hunch_result) { }
754 const value_type X_hunch_result,
755 const value_type X_strict_result)
756 :hunch_result(X_hunch_result), strict_result(X_strict_result) { }
757 const int & get_hunch_result()
const {
return hunch_result; }
758 const int & get_strict_result()
const {
return strict_result; }
759 operator const int &()
const {
return get_hunch_result(); }
761 analyze_result analyze_base_encoding(
const bbl_binary &X,
const unsigned int max_scan_size = 8192);
767 volatile int ref_count;
773 void inc_ref()
volatile {
778 void dec_ref()
volatile {
780 if (--ref_count <= 0) {
781 assert(0 == ref_count);
787 template<
class target_
object>
791 typedef target_object target_type;
807 this_type & operator = (target_type *X_value) {
808 if (value != X_value) {
816 if (value != X.value) {
824 bool operator == (
const this_type &X)
const {
825 return value == X.value;
827 bool operator != (
const this_type &X)
const {
828 return value != X.value;
830 bool operator == (
const target_type *X_value)
const {
831 return value == X_value;
833 bool operator != (
const target_type *X_value)
const {
834 return value != X_value;
837 bool operator ! ()
const {
return !value; }
838 operator target_type* () {
return value; }
839 operator const target_type* ()
const {
return value; }
840 target_type& operator*() {
return *value; }
841 const target_type& operator*()
const {
return *value; }
842 target_type* operator->() {
return value; }
843 const target_type* operator->()
const {
return value; }
844 bool is_null()
const {
return NULL == value; }
845 bool is_not_null()
const {
return NULL != value; }
848 template<
class from_
string = bbl_default_
string,
class to_
string = bbl_default_
string>
class bbl_translater;
850 template<
class from_
string = bbl_default_
string,
class to_
string = bbl_default_
string>
855 typedef from_string from_string_type;
856 typedef to_string to_string_type;
860 from_string_type untranslated_buffer;
861 to_string_type translated_buffer;
863 virtual void translate() = 0;
864 virtual void flush() {
865 for(
int i = 0, length = untranslated_buffer.length(); i < length; ++i) {
870 virtual void clear() {
875 const to_string_type & ignite(
const from_string_type &X) {
876 untranslated_buffer = X;
879 return translated_buffer;
886 template<
class from_
string = bbl_default_
string,
class to_
string = bbl_default_
string>
894 typedef from_string from_string_type;
895 typedef to_string to_string_type;
905 static const to_string_type ignite(
const from_string_type &X) {
return bbl_term::get_empty(); }
913 template<
class from_
string,
class to_
string>
919 typedef from_string from_string_type;
920 typedef to_string to_string_type;
927 :engine(X.engine) { }
928 ~bbl_translater() { }
930 bbl_translater & operator = (engine_type *X_engine) {
934 bbl_translater & operator = (
const bbl_translater &X) {
938 bool operator == (
const bbl_translater &X)
const {
939 return engine == X.engine;
941 bool operator != (
const bbl_translater &X)
const {
942 return engine != X.engine;
945 this_type & translate(
const from_string_type &X) {
946 engine->untranslated_buffer += X;
950 this_type & flush() {
955 this_type & clear() {
963 this_type & operator = (
const from_string_type &X) {
return clear().translate(X).flush(); }
964 operator const to_string_type & ()
const {
return get_string(); }
965 const to_string_type & get_string()
const {
return engine->translated_buffer; }
966 const char * c_str()
const {
return get_string().c_str(); }
967 const to_string_type pook_buffer() {
968 to_string_type buffer = engine->translated_buffer;
970 engine->translated_buffer.erase();
974 this_type & operator << (
const from_string_type &X) {
return translate(X); }
975 this_type & operator >> (to_string_type &X) {
976 X = engine->translated_buffer;
978 engine->translated_buffer.erase();
981 const to_string_type & operator () (
const from_string_type &X) {
982 return clear().translate(X).flush().get_string();
986 template<
class target_
string = bbl_default_
string>
992 typedef typename base_type::from_string_type from_string_type;
993 typedef typename base_type::to_string_type to_string_type;
999 base_type::translated_buffer += base_type::untranslated_buffer;
1001 base_type::untranslated_buffer.erase();
1007 static const to_string_type & ignite(
const from_string_type &X) {
return X; }
1010 #if defined(__BBL_USE_UNICODE__)
1016 typedef base_type::from_string_type from_string_type;
1017 typedef base_type::to_string_type to_string_type;
1025 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1033 typedef base_type::from_string_type from_string_type;
1034 typedef base_type::to_string_type to_string_type;
1042 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1044 #endif // defined(__BBL_USE_UNICODE__)
1051 typedef base_type::from_string_type from_string_type;
1052 typedef base_type::to_string_type to_string_type;
1060 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1067 typedef base_type::from_string_type from_string_type;
1068 typedef base_type::to_string_type to_string_type;
1082 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1085 #if defined(__BBL_USE_UNICODE__)
1086 # if defined(__BBL_USE_UNICODE_MAP_CP932__)
1092 # if defined(__BBL_USE_UNICODE_MAP_UTC__)
1093 class unicode_to_sjis_utc_engine;
1094 typedef unicode_to_sjis_utc_engine unicode_to_sjis_engine;
1095 class sjis_utc_to_unicode_engine;
1096 typedef sjis_utc_to_unicode_engine sjis_to_unicode_engine;
1098 # if defined(__BBL_USE_UNICODE_MAP_APPLE__)
1099 class unicode_to_sjis_apple_engine;
1100 typedef unicode_to_sjis_apple_engine unicode_to_sjis_engine;
1101 class sjis_apple_to_unicode_engine
1102 typedef sjis_apple_to_unicode_engine sjis_to_unicode_engine;
1104 #endif // defined(__BBL_USE_UNICODE__)
1106 #if defined(__BBL_STRICT_TRANSLATE__)
1109 #else // defined(__BBL_STRICT_TRANSLATE__);
1115 typedef base_type::from_string_type from_string_type;
1116 typedef base_type::to_string_type to_string_type;
1119 euc_to_sjis_engine() { }
1124 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1126 #endif // defined(__BBL_STRICT_TRANSLATE__);
1132 typedef base_type::from_string_type from_string_type;
1133 typedef base_type::to_string_type to_string_type;
1147 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1150 #if defined(__BBL_USE_UNICODE__)
1156 typedef base_type::from_string_type from_string_type;
1157 typedef base_type::to_string_type to_string_type;
1161 #ifdef __BBL_SMALL_BOM_LOGIC__
1162 translated_buffer = bbl_term::unicode_bom;
1163 #endif // __BBL_SMALL_BOM_LOGIC__
1167 #ifdef __BBL_SMALL_BOM_LOGIC__
1170 translated_buffer = bbl_term::unicode_bom;
1172 #endif // __BBL_SMALL_BOM_LOGIC__
1175 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1182 typedef base_type::from_string_type from_string_type;
1183 typedef base_type::to_string_type to_string_type;
1191 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1193 #endif // defined(__BBL_USE_UNICODE__)
1195 #if defined(__BBL_STRICT_TRANSLATE__)
1198 #else // defined(__BBL_STRICT_TRANSLATE__);
1204 typedef base_type::from_string_type from_string_type;
1205 typedef base_type::to_string_type to_string_type;
1209 jis_to_sjis_engine() :status(0) { }
1219 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1221 #endif // defined(__BBL_STRICT_TRANSLATE__)
1227 typedef base_type::from_string_type from_string_type;
1228 typedef base_type::to_string_type to_string_type;
1242 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1249 typedef base_type::from_string_type from_string_type;
1250 typedef base_type::to_string_type to_string_type;
1266 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1269 #if defined(__BBL_LOAD_UNICODE_MAP_CP932__)
1275 typedef base_type::from_string_type from_string_type;
1276 typedef base_type::to_string_type to_string_type;
1280 #ifdef __BBL_SMALL_BOM_LOGIC__
1281 translated_buffer = bbl_term::unicode_bom;
1282 #endif // __BBL_SMALL_BOM_LOGIC__
1286 #ifdef __BBL_SMALL_BOM_LOGIC__
1289 translated_buffer = bbl_term::unicode_bom;
1291 #endif // __BBL_SMALL_BOM_LOGIC__
1294 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1301 typedef base_type::from_string_type from_string_type;
1302 typedef base_type::to_string_type to_string_type;
1310 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1312 #endif // defined(__BBL_LOAD_UNICODE_MAP_CP932__)
1314 #if defined(__BBL_LOAD_UNICODE_MAP_UTC__)
1317 typedef sjis_utc_to_unicode_engine this_type;
1319 typedef base_type::bbl_translater_type bbl_translater_type;
1320 typedef base_type::from_string_type from_string_type;
1321 typedef base_type::to_string_type to_string_type;
1324 sjis_utc_to_unicode_engine() {
1325 #ifdef __BBL_SMALL_BOM_LOGIC__
1326 translated_buffer = bbl_term::unicode_bom;
1327 #endif // __BBL_SMALL_BOM_LOGIC__
1331 #ifdef __BBL_SMALL_BOM_LOGIC__
1334 translated_buffer = bbl_term::unicode_bom;
1336 #endif // __BBL_SMALL_BOM_LOGIC__
1338 static bbl_translater_type create() {
return new this_type; }
1339 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1341 class unicode_to_sjis_utc_engine :
public bbl_translate_engine<bbl_wstring, bbl_string> {
1343 typedef unicode_to_sjis_utc_engine this_type;
1344 typedef bbl_translate_engine<bbl_wstring, bbl_string> base_type;
1345 typedef base_type::bbl_translater_type bbl_translater_type;
1346 typedef base_type::from_string_type from_string_type;
1347 typedef base_type::to_string_type to_string_type;
1350 unicode_to_sjis_utc_engine() { }
1354 static bbl_translater_type create() {
return new this_type; }
1355 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1357 #endif // defined(__BBL_LOAD_UNICODE_MAP_UTC__)
1359 #if defined(__BBL_LOAD_UNICODE_MAP_APPLE__)
1360 class sjis_apple_to_unicode_engine :
public bbl_translate_engine<bbl_string, bbl_wstring> {
1362 typedef sjis_apple_to_unicode_engine this_type;
1363 typedef bbl_translate_engine<bbl_string, bbl_wstring> base_type;
1364 typedef base_type::bbl_translater_type bbl_translater_type;
1365 typedef base_type::from_string_type from_string_type;
1366 typedef base_type::to_string_type to_string_type;
1369 sjis_apple_to_unicode_engine() {
1370 #ifdef __BBL_SMALL_BOM_LOGIC__
1371 translated_buffer = bbl_term::unicode_bom;
1372 #endif // __BBL_SMALL_BOM_LOGIC__
1376 #ifdef __BBL_SMALL_BOM_LOGIC__
1379 translated_buffer = bbl_term::unicode_bom;
1381 #endif // __BBL_SMALL_BOM_LOGIC__
1383 static bbl_translater_type create() {
return new this_type; }
1384 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1386 class unicode_to_sjis_apple_engine :
public bbl_translate_engine<bbl_wstring, bbl_string> {
1388 typedef unicode_to_sjis_apple_engine this_type;
1389 typedef bbl_translate_engine<bbl_wstring, bbl_string> base_type;
1390 typedef base_type::bbl_translater_type bbl_translater_type;
1391 typedef base_type::from_string_type from_string_type;
1392 typedef base_type::to_string_type to_string_type;
1395 unicode_to_sjis_apple_engine() { }
1400 static bbl_translater_type create() {
return new this_type; }
1401 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1403 #endif // defined(__BBL_LOAD_UNICODE_MAP_APPLE__)
1405 #if defined(__BBL_USE_UNICODE__)
1411 typedef base_type::from_string_type from_string_type;
1412 typedef base_type::to_string_type to_string_type;
1420 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1427 typedef base_type::from_string_type from_string_type;
1428 typedef base_type::to_string_type to_string_type;
1436 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1439 #ifdef __BBL_LARGE_BOM_LOGIC__
1440 template<
class target_
string = bbl_default_
string>
1446 typedef typename base_type::from_string_type from_string_type;
1447 typedef typename base_type::to_string_type to_string_type;
1463 template<
class target_
string = bbl_default_
string>
1469 typedef typename base_type::from_string_type from_string_type;
1470 typedef typename base_type::to_string_type to_string_type;
1475 typename from_string_type::size_type p_bom;
1476 while(from_string_type::npos != (p_bom = base_type::untranslated_buffer.find(
bbl_term::get_bom()))) {
1477 base_type::untranslated_buffer.erase(p_bom, 1);
1479 base_type::translate();
1486 #endif // __BBL_LARGE_BOM_LOGIC__
1489 #endif // defined(__BBL_USE_UNICODE__)
1491 const int translate_buffer_full_size = 1024;
1492 const int translate_buffer_size = 1000;
1499 template<
class first_engine,
class second_engine>
1503 typedef first_engine first_engine_type;
1504 typedef second_engine second_engine_type;
1506 typedef typename base_type::bbl_translater_type bbl_translater_type;
1507 typedef typename base_type::from_string_type from_string_type;
1508 typedef typename base_type::to_string_type to_string_type;
1511 typename first_engine_type::bbl_translater_type engine1;
1512 typename second_engine_type::bbl_translater_type engine2;
1515 :engine1(first_engine_type::create()),
1516 engine2(second_engine_type::create()) { }
1520 engine1.translate(base_type::untranslated_buffer);
1522 base_type::untranslated_buffer.erase();
1523 engine2.translate(engine1.pook_buffer());
1524 base_type::translated_buffer += engine2.pook_buffer();
1530 base_type::untranslated_buffer.erase();
1531 engine2.translate(engine1.pook_buffer()).flush();
1532 base_type::translated_buffer += engine2.pook_buffer();
1540 static bbl_translater_type create() {
return new this_type; }
1541 static const to_string_type ignite(
const from_string_type &X) {
1542 return second_engine_type::ignite(first_engine_type::ignite(X));
1547 #if defined(__BBL_USE_UNICODE__)
1548 typedef twin_translate_engine<jis_to_euc_engine, euc_to_unicode_engine> jis_to_unicode_engine;
1549 typedef twin_translate_engine<unicode_to_euc_engine, euc_to_jis_engine> unicode_to_jis_engine;
1550 typedef twin_translate_engine<sjis_to_unicode_engine, unicode_to_utf8_engine> sjis_to_utf8_engine;
1551 typedef twin_translate_engine<euc_to_unicode_engine, unicode_to_utf8_engine> euc_to_utf8_engine;
1552 typedef twin_translate_engine<jis_to_unicode_engine, unicode_to_utf8_engine> jis_to_utf8_engine;
1553 typedef twin_translate_engine<utf8_to_unicode_engine, unicode_to_sjis_engine> utf8_to_sjis_engine;
1554 typedef twin_translate_engine<utf8_to_unicode_engine, unicode_to_euc_engine> utf8_to_euc_engine;
1555 typedef twin_translate_engine<utf8_to_euc_engine, euc_to_jis_engine> utf8_to_jis_engine;
1558 #endif // defined(__BBL_USE_UNICODE__)
1563 const bbl_string (*
const sjis_to_euc)(
const bbl_string &) = sjis_to_euc_engine::ignite;
1564 const bbl_string (*
const sjis_to_jis)(
const bbl_string &) = sjis_to_jis_engine::ignite;
1565 const bbl_string (*
const euc_to_sjis)(
const bbl_string &) = euc_to_sjis_engine::ignite;
1566 const bbl_string (*
const euc_to_jis)(
const bbl_string &) = euc_to_jis_engine::ignite;
1567 const bbl_string (*
const jis_to_sjis)(
const bbl_string &) = jis_to_sjis_engine::ignite;
1568 const bbl_string (*
const jis_to_euc)(
const bbl_string &) = jis_to_euc_engine::ignite;
1569 const bbl_string (*
const jis_to_iso2022jp)(
const bbl_string &) = jis_to_iso2022jp_engine::ignite;
1570 #if defined(__BBL_USE_UNICODE__)
1571 const bbl_string (*
const sjis_to_utf8)(
const bbl_string &) = sjis_to_utf8_engine::ignite;
1572 const bbl_wstring (*
const sjis_to_unicode)(
const bbl_string &) = sjis_to_unicode_engine::ignite;
1573 const bbl_string (*
const euc_to_utf8)(
const bbl_string &) = euc_to_utf8_engine::ignite;
1574 const bbl_wstring (*
const euc_to_unicode)(
const bbl_string &) = euc_to_unicode_engine::ignite;
1575 const bbl_string (*
const jis_to_utf8)(
const bbl_string &) = jis_to_utf8_engine::ignite;
1576 const bbl_wstring (*
const jis_to_unicode)(
const bbl_string &) = jis_to_unicode_engine::ignite;
1577 const bbl_string (*
const utf8_to_sjis)(
const bbl_string &) = utf8_to_sjis_engine::ignite;
1578 const bbl_string (*
const utf8_to_euc)(
const bbl_string &) = utf8_to_euc_engine::ignite;
1579 const bbl_string (*
const utf8_to_jis)(
const bbl_string &) = utf8_to_jis_engine::ignite;
1580 const bbl_wstring (*
const utf8_to_unicode)(
const bbl_string &) = utf8_to_unicode_engine::ignite;
1581 const bbl_string (*
const unicode_to_sjis)(
const bbl_wstring &) = unicode_to_sjis_engine::ignite;
1582 const bbl_string (*
const unicode_to_euc)(
const bbl_wstring &) = unicode_to_euc_engine::ignite;
1583 const bbl_string (*
const unicode_to_jis)(
const bbl_wstring &) = unicode_to_jis_engine::ignite;
1584 const bbl_string (*
const unicode_to_utf8)(
const bbl_wstring &) = unicode_to_utf8_engine::ignite;
1585 #endif // defined(__BBL_USE_UNICODE__)
1593 #if defined(__BBL_USE_BINARY__)
1599 typedef base_type::from_string_type from_string_type;
1600 typedef base_type::to_string_type to_string_type;
1609 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1616 typedef base_type::from_string_type from_string_type;
1617 typedef base_type::to_string_type to_string_type;
1626 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1633 typedef base_type::from_string_type from_string_type;
1634 typedef base_type::to_string_type to_string_type;
1643 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1650 typedef base_type::from_string_type from_string_type;
1651 typedef base_type::to_string_type to_string_type;
1660 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1663 const bbl_wstring WORD_to_unicode(
const bbl_binary &X);
1664 const bbl_binary unicode_to_WORD(
const bbl_wstring &X);
1665 const bbl_wstring cross_WORD_to_unicode(
const bbl_binary &X);
1666 const bbl_binary unicode_to_cross_WORD(
const bbl_wstring &X);
1668 inline const unsigned int WORD_cross_endian(
const unsigned int &X) {
1669 assert(X <= 0xFFFF);
1670 return ((X &0x00FF) *0x100)
1675 # if defined(__BBL_USE_UTF32__)
1676 class DWORD_to_unicode_engine :
public bbl_translate_engine<bbl_binary, bbl_wstring> {
1678 typedef DWORD_to_unicode_engine this_type;
1679 typedef bbl_translate_engine<bbl_binary, bbl_wstring> base_type;
1680 typedef base_type::bbl_translater_type bbl_translater_type;
1681 typedef base_type::from_string_type from_string_type;
1682 typedef base_type::to_string_type to_string_type;
1685 DWORD_to_unicode_engine() { }
1690 static bbl_translater_type create() {
return new this_type; }
1691 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1693 class unicode_to_DWORD_engine :
public bbl_translate_engine<bbl_wstring, bbl_binary> {
1695 typedef unicode_to_DWORD_engine this_type;
1696 typedef bbl_translate_engine<bbl_wstring, bbl_binary> base_type;
1697 typedef base_type::bbl_translater_type bbl_translater_type;
1698 typedef base_type::from_string_type from_string_type;
1699 typedef base_type::to_string_type to_string_type;
1702 unicode_to_DWORD_engine() { }
1707 static bbl_translater_type create() {
return new this_type; }
1708 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1710 class cross_DWORD_to_unicode_engine :
public bbl_translate_engine<bbl_binary, bbl_wstring> {
1712 typedef cross_DWORD_to_unicode_engine this_type;
1713 typedef bbl_translate_engine<bbl_binary, bbl_wstring> base_type;
1714 typedef base_type::bbl_translater_type bbl_translater_type;
1715 typedef base_type::from_string_type from_string_type;
1716 typedef base_type::to_string_type to_string_type;
1719 cross_DWORD_to_unicode_engine() { }
1724 static bbl_translater_type create() {
return new this_type; }
1725 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1727 class unicode_to_cross_DWORD_engine :
public bbl_translate_engine<bbl_wstring, bbl_binary> {
1729 typedef unicode_to_cross_DWORD_engine this_type;
1730 typedef bbl_translate_engine<bbl_wstring, bbl_binary> base_type;
1731 typedef base_type::bbl_translater_type bbl_translater_type;
1732 typedef base_type::from_string_type from_string_type;
1733 typedef base_type::to_string_type to_string_type;
1736 unicode_to_cross_DWORD_engine() { }
1741 static bbl_translater_type create() {
return new this_type; }
1742 static const to_string_type ignite(
const from_string_type &X) {
return this_type().base_type::ignite(X); }
1745 const bbl_wstring DWORD_to_unicode(
const bbl_binary &X);
1746 const bbl_binary unicode_to_DWORD(
const bbl_wstring &X);
1747 const bbl_wstring cross_DWORD_to_unicode(
const bbl_binary &X);
1748 const bbl_binary unicode_to_cross_DWORD(
const bbl_wstring &X);
1750 inline const unsigned int DWORD_cross_endian(
const unsigned int &X) {
1751 return (X *0x1000000)
1752 |((X &0x0000FF00) *0x100)
1753 |((X &0x00FF0000) /0x100)
1756 # endif //defined(__BBL_USE_UTF32__)
1758 #endif // defined(__BBL_USE_BINARY__)
1761 #if defined(__BBL_USE_SELECTORS__)
1803 template<
class from_
string = bbl_default_
string,
class to_
string = bbl_default_
string>
1809 typedef typename base_type::from_string_type from_string_type;
1810 typedef typename base_type::to_string_type to_string_type;
1815 :engine(this_type::order(from_base_encoding, to_base_encoding)) {}
1816 #ifdef __BBL_LARGE_BOM_LOGIC__
1818 :engine(X_engine) {}
1819 #endif // __BBL_LARGE_BOM_LOGIC__
1822 engine.translate(base_type::untranslated_buffer);
1824 base_type::untranslated_buffer.erase();
1825 base_type::translated_buffer += engine.pook_buffer();
1830 base_type::untranslated_buffer.erase();
1831 base_type::translated_buffer += engine.pook_buffer();
1838 static bbl_translater_type create(
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding()) {
1839 return new this_type(from_base_encoding, to_base_encoding);
1845 static const to_string_type ignite(
const from_string_type &X,
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding());
1846 static bbl_translater_type order(
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding());
1858 # if defined(__BBL_USE_UNICODE__)
1879 # endif // defined(__BBL_USE_UNICODE__)
1882 template<
class string_type = bbl_default_
string>
1895 typedef typename base_type::from_string_type from_string_type;
1896 typedef typename base_type::to_string_type to_string_type;
1899 #ifdef __BBL_LARGE_BOM_LOGIC__
1901 :
parent_type(this_type::order(from_base_encoding, to_base_encoding)) {}
1902 #else // __BBL_LARGE_BOM_LOGIC__
1904 :
parent_type(from_base_encoding, to_base_encoding) {}
1905 #endif // __BBL_LARGE_BOM_LOGIC__
1908 #ifdef __BBL_LARGE_BOM_LOGIC__
1909 static bbl_translater_type create(
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding()) {
1910 return new this_type(from_base_encoding, to_base_encoding);
1912 static const to_string_type ignite(
const from_string_type &X,
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding());
1913 static bbl_translater_type order(
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding());
1914 #endif // __BBL_LARGE_BOM_LOGIC__
1918 template<
class to_
string = bbl_default_
string>
1924 typedef typename base_type::from_string_type from_string_type;
1925 typedef typename base_type::to_string_type to_string_type;
1928 int from_base_encoding, to_base_encoding;
1930 :
base_type(X_to_base_encoding, X_to_base_encoding), from_base_encoding(X_to_base_encoding), to_base_encoding(X_to_base_encoding) {}
1933 int new_from_base_encoding = analyze_base_encoding(base_type::untranslated_buffer);
1934 if (from_base_encoding != new_from_base_encoding) {
1935 from_base_encoding = new_from_base_encoding;
1936 base_type::engine = base_type::order(from_base_encoding, to_base_encoding);
1940 base_type::engine.translate(base_type::untranslated_buffer);
1942 base_type::untranslated_buffer.erase();
1943 base_type::translated_buffer = base_type::engine.pook_buffer();
1947 return new this_type(X_to_base_encoding);
1949 static const to_string_type ignite(
const from_string_type &X,
int X_to_base_encoding = babel::get_base_encoding()) {
1950 #if defined(__BORLANDC__)
1953 return temp.base_type::ignite(X, analyze_base_encoding(X), X_to_base_encoding);
1955 return this_type(X_to_base_encoding).base_type::ignite(X, analyze_base_encoding(X), X_to_base_encoding);
1961 template<
class from_
string = bbl_default_
string,
class to_
string = bbl_default_
string>
1964 manual_translate(
const from_string &X,
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding())
1968 template<
class to_
string = bbl_default_
string>
1971 translate_to_string(
const bbl_binary &X,
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding())
1975 template<
class to_
string = bbl_default_
string>
1978 auto_translate(
const bbl_binary &X,
int to_base_encoding = babel::get_base_encoding())
1983 template<
class string_type = bbl_default_
string>
1997 typedef typename base_type::from_string_type from_string_type;
1998 typedef typename base_type::to_string_type to_string_type;
2001 #ifdef __BBL_LARGE_BOM_LOGIC__
2002 translate_to_binary_engine(
int from_base_encoding = babel::get_base_encoding(),
int to_base_encoding = babel::get_base_encoding())
2003 :
parent_type(this_type::order(from_base_encoding, to_base_encoding)) {}
2004 #else // __BBL_LARGE_BOM_LOGIC__
2005 translate_to_binary_engine(
int from_base_encoding = babel::get_base_encoding(),
int to_base_encoding = babel::get_base_encoding())
2006 :
parent_type(from_base_encoding, to_base_encoding) {}
2007 #endif // __BBL_LARGE_BOM_LOGIC__
2010 #ifdef __BBL_LARGE_BOM_LOGIC__
2011 static bbl_translater_type create(
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding()) {
2012 return new this_type(from_base_encoding, to_base_encoding);
2014 static const to_string_type ignite(
const from_string_type &X,
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding());
2015 static bbl_translater_type order(
int from_base_encoding,
int to_base_encoding = babel::get_base_encoding());
2016 #endif // __BBL_LARGE_BOM_LOGIC__
2019 inline const bbl_binary translate_to_binary(
const bbl_string &X,
int X_to_base_encoding,
int X_from_base_encoding = babel::get_base_encoding()) {
2022 # if defined(__BBL_USE_UNICODE__)
2023 inline const bbl_binary translate_to_binary(
const bbl_wstring &X,
int X_to_base_encoding,
int X_from_base_encoding = babel::base_encoding::unicode) {
2024 return manual_translate_engine<bbl_wstring, bbl_binary>::ignite(X, X_from_base_encoding, X_to_base_encoding);
2026 # endif // defined(__BBL_USE_UNICODE__)
2027 #endif // defined(__BBL_USE_SELECTORS__)
2036 #if defined(__BORLANDC__)
2040 #endif // __BABEL_BBL_H__