//----------------------------------------------------------------------------// String IconvStringTranscoder::stringFromUTF16(const uint16* input) const { #if CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_UNICODE IconvHelper ich("UTF-8", "UTF-16"); return iconvTranscode<String, utf8>( ich, reinterpret_cast<const char*>(input), getStringLength(input) * sizeof(uint16)); #else IconvHelper ich("WCHAR_T", "UTF-16"); return stringFromStdWString(iconvTranscode<std::wstring, wchar_t>( ich, reinterpret_cast<const char*>(input), getStringLength(input))); #endif }
int tst_insdel(MENU_ARGS) { /* Test of: SM/RM(4) (= IRM (Insertion/replacement mode)) ICH (Insert Character) DCH (Delete character) IL (Insert line) DL (Delete line) */ int i, row, col, sw, dblchr, scr132; for (scr132 = 0; scr132 <= 1; scr132++) { if (scr132) { deccolm(TRUE); sw = max_cols; } else { deccolm(FALSE); sw = min_cols; } ed(2); cup(1, 1); for (row = 1; row <= max_lines; row++) { cup(row, 1); for (col = 1; col <= sw; col++) printf("%c", 'A' - 1 + row); } cup(4, 1); printf("Screen accordion test (Insert & Delete Line). "); holdit(); ri(); el(2); decstbm(2, max_lines - 1); decom(TRUE); cup(1, 1); for (row = 1; row <= max_lines; row++) { il(row); dl(row); } decom(FALSE); decstbm(0, 0); cup(2, 1); printf("Top line: A's, bottom line: %c's, this line, nothing more. ", 'A' - 1 + max_lines); holdit(); cup(2, 1); ed(0); cup(1, 2); printf("B"); cub(1); sm("4"); for (col = 2; col <= sw - 1; col++) printf("*"); rm("4"); cup(4, 1); printf("Test of 'Insert Mode'. The top line should be 'A*** ... ***B'. "); holdit(); ri(); el(2); cup(1, 2); dch(sw - 2); cup(4, 1); printf("Test of 'Delete Character'. The top line should be 'AB'. "); holdit(); for (dblchr = 1; dblchr <= 2; dblchr++) { ed(2); for (row = 1; row <= max_lines; row++) { cup(row, 1); if (dblchr == 2) decdwl(); for (col = 1; col <= sw / dblchr; col++) printf("%c", 'A' - 1 + row); cup(row, sw / dblchr - row); dch(row); } cup(4, 1); println("The right column should be staggered "); printf("by one. "); holdit(); } ed(2); cup(1, 1); println("If your terminal has the ANSI 'Insert Character' function"); println("(the VT102 does not), then you should see a line like this"); println(" A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"); println("below:"); println(""); for (i = 'Z'; i >= 'A'; i--) { printf("%c%c", i, BS); ich(2); } cup(10, 1); holdit(); if (sw == max_cols) deccolm(FALSE); } return MENU_NOHOLD; }
//----------------------------------------------------------------------------// String IconvStringTranscoder::stringFromStdWString(const std::wstring& input) const { #if CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_UNICODE IconvHelper ich("UTF-8", "WCHAR_T"); return iconvTranscode<String, utf8>( ich, reinterpret_cast<const char*>(input.c_str()), input.length() * sizeof(wchar_t)); #else /* * WTF is this shit - a short story by CrazyEddie * * One of the following implementations are for use when CEGUI::String is * not the unicode capable versions. Neither of these implementations * perform ideally, which is why I left both here - as it is intended * that eventually we may come back here and improve this. * * The codecvt version (1st one) overall does a better job, because when * the locale is mbcs compliant, it is able to produce encoded output * that will likely match what client code is using elsewhere. The * problem with it is that when using a non-mbcs locale (such as the * basic C or maybe an ISO8859-1 locale, a source character that will * not fit causes the conversion to fail (and we throw an exception). * * The ctype version (2nd one) provides us the facility to use a 'default' * character for those codes that can not be represented by a single * character in the target locale - and the conversion will always * succeed, though some data may be lost in translation. The 'bad' * part about using ctype for conversion is that it is a single code * unit mapping, which means when the user has a mbcs locale, characters * that should be correcly represented (i.e they would be converted by * the codecvt version) are instead replaced by the default character. * * The ideal scenario for us would be able to use the codecvt approach but * also have a default character for use when conversion is impossible. This * would be the closest match to what is done on the Win32 implementation * that uses WideCharToMultiByte passing the CP_ACP value. */ std::locale conv_locale(""); std::vector<String::value_type> buf(input.length() * 6 + 1); #if 0 typedef std::codecvt<wchar_t, char, mbstate_t> Converter; const Converter& facet = std::use_facet<Converter>(conv_locale); mbstate_t conv_state; const wchar_t* from_next; String::value_type* to_next; const Converter::result result = facet.out(conv_state, &input[0], &input[input.length()], from_next, &buf[0], &buf[buf.size()], to_next); if (result == Converter::error || result == Converter::partial) CEGUI_THROW(InvalidRequestException("conversion failed.")); #else const std::ctype<wchar_t>& facet = std::use_facet<std::ctype<wchar_t> >(conv_locale); facet.narrow(&input[0], &input[input.length()], '?', &buf[0]); #endif return String(&buf[0]); #endif }
//----------------------------------------------------------------------------// std::wstring IconvStringTranscoder::stringToStdWString(const String& input) const { IconvHelper ich("WCHAR_T", "UTF-8"); return iconvTranscode<std::wstring, wchar_t>( ich, input.c_str(), getStringLength(input.c_str())); }
//----------------------------------------------------------------------------// uint16* IconvStringTranscoder::stringToUTF16(const String& input) const { IconvHelper ich("UTF-16", "UTF-8"); return iconvTranscode<uint16>( ich, input.c_str(), getStringLength(input.c_str())); }