当前位置: 首页>>代码示例>>C++>>正文


C++ CPLString::Recode方法代码示例

本文整理汇总了C++中CPLString::Recode方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLString::Recode方法的具体用法?C++ CPLString::Recode怎么用?C++ CPLString::Recode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CPLString的用法示例。


在下文中一共展示了CPLString::Recode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ACTextUnescape

CPLString ACTextUnescape( const char *pszRawInput, const char *pszEncoding )

{
    CPLString osResult;
    CPLString osInput = pszRawInput;
    
/* -------------------------------------------------------------------- */
/*      Translate text from Win-1252 to UTF8.  We approximate this      */
/*      by treating Win-1252 as Latin-1.  Note that we likely ought     */
/*      to be consulting the $DWGCODEPAGE header variable which         */
/*      defaults to ANSI_1252 if not set.                               */
/* -------------------------------------------------------------------- */
    osInput.Recode( pszEncoding, CPL_ENC_UTF8 );

    const char *pszInput = osInput.c_str();

/* -------------------------------------------------------------------- */
/*      Now translate escape sequences.  They are all plain ascii       */
/*      characters and won't have been affected by the UTF8             */
/*      recoding.                                                       */
/* -------------------------------------------------------------------- */
    while( *pszInput != '\0' )
    {
        if( pszInput[0] == '\\' && pszInput[1] == 'P' )
        {
            osResult += '\n';
            pszInput++;
        }
        else if( pszInput[0] == '\\' && pszInput[1] == '~' )
        {
            osResult += ' ';
            pszInput++;
        }
        else if( pszInput[0] == '\\' && pszInput[1] == 'U' 
                 && pszInput[2] == '+' )
        {
            CPLString osHex;
            int iChar;

            osHex.assign( pszInput+3, 4 );
            sscanf( osHex.c_str(), "%x", &iChar );

            wchar_t anWCharString[2];
            anWCharString[0] = (wchar_t) iChar;
            anWCharString[1] = 0;
            
            char *pszUTF8Char = CPLRecodeFromWChar( anWCharString,
                                                    CPL_ENC_UCS2, 
                                                    CPL_ENC_UTF8 );

            osResult += pszUTF8Char;
            CPLFree( pszUTF8Char );
            
            pszInput += 6;
        }
        else if( pszInput[0] == '\\'
                 && (pszInput[1] == 'W' 
                     || pszInput[1] == 'T'
                     || pszInput[1] == 'A' ) )
        {
            // eg. \W1.073172x;\T1.099;Bonneuil de Verrines
            // See data/dwg/EP/42002.dwg
            // Not sure what \W and \T do, but we skip them. 
            // According to qcad rs_text.cpp, \A values are vertical
            // alignment, 0=bottom, 1=mid, 2=top but we ignore for now.
            
            while( *pszInput != ';' && *pszInput != '\0' )
                pszInput++;
        }
        else if( pszInput[0] == '\\' && pszInput[1] == '\\' )
        {
            osResult += '\\';
            pszInput++;
        }
        else if( EQUALN(pszInput,"%%c",3) 
                 || EQUALN(pszInput,"%%d",3)
                 || EQUALN(pszInput,"%%p",3) )
        {
            wchar_t anWCharString[2];

            anWCharString[1] = 0;

            // These are especial symbol representations for autocad.
            if( EQUALN(pszInput,"%%c",3) )
                anWCharString[0] = 0x2300; // diameter (0x00F8 is a good approx)
            else if( EQUALN(pszInput,"%%d",3) )
                anWCharString[0] = 0x00B0; // degree
            else if( EQUALN(pszInput,"%%p",3) )
                anWCharString[0] = 0x00B1; // plus/minus

            char *pszUTF8Char = CPLRecodeFromWChar( anWCharString,
                                                    CPL_ENC_UCS2, 
                                                    CPL_ENC_UTF8 );

            osResult += pszUTF8Char;
            CPLFree( pszUTF8Char );
            
            pszInput += 2;
        }
        else 
//.........这里部分代码省略.........
开发者ID:MattLatt,项目名称:GDAL_2.0.x_VC,代码行数:101,代码来源:ogr_autocad_services.cpp


注:本文中的CPLString::Recode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。