[yast-commit] r39262 - in /branches/tmp/sh/mod-ui/core/libyui/src: YUI.h YUI_util.cc
Author: sh-sh-sh Date: Mon Jul 9 23:53:30 2007 New Revision: 39262 URL: http://svn.opensuse.org/viewcvs/yast?rev=39262&view=rev Log: code readability Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI.h branches/tmp/sh/mod-ui/core/libyui/src/YUI_util.cc Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI.h?rev=39262&r1=39261&r2=39262&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YUI.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YUI.h Mon Jul 9 23:53:30 2007 @@ -51,6 +51,22 @@ class YContainerWidget; +struct YUIBuiltinCallData +{ + void * function; + int argc; + YCPValue * argv; + YCPValue result; + + YUIBuiltinCallData() + : function(0) + , argc(0) + , argv(0) + , result( YCPVoid() ) + {} +}; + + /** * Abstract base class of a YaST2 user interface. * @@ -195,12 +211,12 @@ virtual void internalError( const char *msg ); /** - * Might be handy if you have to recode strings from/to utf-8 + * Recode a string from or to UTF-8. **/ - static int Recode( const string & str, - const string & from, - const string & to, - string & outstr ); + static int Recode( const string & src, + const string & srcEncoding, + const string & destEncoding, + string & dest ); /** * Returns the default function key number for a widget with the specified @@ -955,21 +971,5 @@ }; -struct YUIBuiltinCallData -{ - void * function; - int argc; - YCPValue * argv; - YCPValue result; - - YUIBuiltinCallData() - : function(0) - , argc(0) - , argv(0) - , result( YCPVoid() ) - {} -}; - - #endif // YUI_h Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI_util.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI_util.cc?rev=39262&r1=39261&r2=39262&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YUI_util.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_util.cc Mon Jul 9 23:53:30 2007 @@ -53,105 +53,112 @@ } -static iconv_t fromutf8_cd = ( iconv_t )( -1 ); -static string fromutf8_name = ""; -static iconv_t toutf8_cd = ( iconv_t )( -1 ); -static string toutf8_name = ""; +// FIXME: The following code is ugly +// FIXME: The following code is ugly +// FIXME: The following code is ugly -static iconv_t fromto_cd = ( iconv_t )( -1 ); +static iconv_t fromUtf8_cd = (iconv_t)( -1 ); +static string fromUtf8_name = ""; + +static iconv_t toUtf8_cd = (iconv_t)( -1 ); +static string toUtf8_name = ""; + +static iconv_t fromTo_cd = (iconv_t)( -1 ); static string from_name = ""; static string to_name = ""; static const unsigned recode_buf_size = 1024; static char recode_buf[ recode_buf_size ]; -int YUI::Recode( const string & instr, const string & from, - const string & to, string & outstr ) +int YUI::Recode( const string & src, + const string & srcEncoding, + const string & destEncoding, + string & dest ) { - if ( from == to - || instr.empty()) + if ( srcEncoding == destEncoding + || src.empty()) { - outstr = instr; + dest = src; return 0; } - outstr.clear(); - iconv_t cd = ( iconv_t )( -1 ); + dest.clear(); + iconv_t cd = (iconv_t)( -1 ); - if ( from == "UTF-8" ) + if ( srcEncoding == "UTF-8" ) { - if ( fromutf8_cd == ( iconv_t )( -1 ) - || fromutf8_name != to) + if ( fromUtf8_cd == (iconv_t)( -1 ) + || fromUtf8_name != destEncoding) { - if ( fromutf8_cd != ( iconv_t )( -1 ) ) + if ( fromUtf8_cd != (iconv_t)( -1 ) ) { - iconv_close ( fromutf8_cd ); + iconv_close( fromUtf8_cd ); } - fromutf8_cd = iconv_open ( to.c_str(), from.c_str() ); - fromutf8_name = to; + fromUtf8_cd = iconv_open( destEncoding.c_str(), srcEncoding.c_str() ); + fromUtf8_name = destEncoding; } - cd = fromutf8_cd; + cd = fromUtf8_cd; } - else if ( to == "UTF-8" ) + else if ( destEncoding == "UTF-8" ) { - if ( toutf8_cd == ( iconv_t )( -1 ) - || toutf8_name != from) + if ( toUtf8_cd == (iconv_t)( -1 ) + || toUtf8_name != srcEncoding) { - if ( toutf8_cd != ( iconv_t )( -1 ) ) + if ( toUtf8_cd != (iconv_t)( -1 ) ) { - iconv_close ( toutf8_cd ); + iconv_close( toUtf8_cd ); } - toutf8_cd = iconv_open ( to.c_str(), from.c_str() ); - toutf8_name = from; + toUtf8_cd = iconv_open( destEncoding.c_str(), srcEncoding.c_str() ); + toUtf8_name = srcEncoding; } - cd = toutf8_cd; + cd = toUtf8_cd; } else { - if ( fromto_cd == ( iconv_t )( -1 ) - || from_name != from - || to_name != to) + if ( fromTo_cd == (iconv_t)( -1 ) + || from_name != srcEncoding + || to_name != destEncoding) { - if ( fromto_cd != ( iconv_t )( -1 ) ) + if ( fromTo_cd != (iconv_t)( -1 ) ) { - iconv_close ( fromto_cd ); + iconv_close( fromTo_cd ); } - fromto_cd = iconv_open ( to.c_str(), from.c_str() ); - from_name = from; - to_name = to; + fromTo_cd = iconv_open( destEncoding.c_str(), srcEncoding.c_str() ); + from_name = srcEncoding; + to_name = destEncoding; } - cd = fromto_cd; + cd = fromTo_cd; } - if ( cd == ( iconv_t )( -1 ) ) + if ( cd == (iconv_t)( -1 ) ) { static bool complained = false; if ( ! complained ) { // glibc-locale is not necessarily installed so only complain once - y2error ( "Recode: ( errno %d ) failed conversion '%s' to '%s'", errno, from.c_str(), to.c_str() ); + y2error( "Recode: ( errno %d ) failed conversion '%s' to '%s'", errno, srcEncoding.c_str(), destEncoding.c_str() ); complained = true; } - outstr = instr; + dest = src; return 1; } - size_t inbuf_len = instr.length(); + size_t inbuf_len = src.length(); size_t outbuf_len = recode_buf_size-1; char * outbuf = recode_buf; - char * inptr = (char *) instr.c_str(); + char * inptr = (char *) src.c_str(); char * outptr = outbuf; char * l = NULL; - size_t iconv_ret = ( size_t )( -1 ); + size_t iconv_ret = (size_t)( -1 ); do { - iconv_ret = iconv ( cd, ( & inptr ), & inbuf_len, & outptr, & outbuf_len ); + iconv_ret = iconv( cd, &inptr, &inbuf_len, &outptr, &outbuf_len ); - if ( iconv_ret == ( size_t )( -1 ) ) + if ( iconv_ret == (size_t)( -1 ) ) { if ( errno == EILSEQ ) // Illegal multibyte sequence? @@ -173,7 +180,7 @@ else if ( errno == E2BIG ) // Buffer overflow? { *outptr = '\0'; // Terminate converted buffer contents - outstr += recode_buf; // Append buffer to output string + dest += recode_buf; // Append buffer to destination string // Set up buffer for the next chunk and start over outptr = recode_buf; @@ -182,10 +189,10 @@ } } - } while ( inbuf_len != ( size_t )(0) ); + } while ( inbuf_len != (size_t)(0) ); - *outptr = '\0'; // Terminate converted buffer contents - outstr += recode_buf; // Append buffer to output string + *outptr = '\0'; // Terminate converted buffer contents + dest += recode_buf; // Append buffer to destination string return 0; } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org