• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            專職C++

            不能停止的腳步

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(28)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            在用vs開發cocos2dx過程中,要顯示的中文,要求是UTF-8格式的才能正常顯示出來,但VS一般是ANSI格式保存,這樣,在代碼中寫入的中文字符串,運行后,顯示的就是亂碼。
            為了正確顯示中文,或支持多語言,我這里定義一個簡單的字符串管理類,來滿足上述要求。
            這個類使用了我的開源代碼中的XAnsiString和XMap,TextIni這幾個類,可以在我的開放代碼找到下載。
            下面是代碼://字符串資源管理器
            #ifndef _X_STRING_MANAGER_H_
            #define _X_STRING_MANAGER_H_
            #include <xstring.h>
            #include <xini.h>
            #include <xmap.h>
            #include <xset.h>
            #include <xsingleton.h>
            namespace zdh
            {
                typedef XMap<XAnsiString, XAnsiString> TStringKeyValue;
                typedef XMap<XAnsiString, TStringKeyValue> TStringSection;

                class XStringMgr
                {
                public:
                    XStringMgr()
                    {}
                    ~XStringMgr()
                    {
                        m_Map.Clear();
                    }
                    XInt Load(const XAnsiString & paramFileName, bool paramClear = true)
                    {
                        if (paramClear) m_Map.Clear();
                        XIniText stIni;
                        if (!stIni.Load(paramFileName)) return ERR_FAIL;
                        for (int i = 0; i < stIni.getSectionCount(); i++)
                        {
                            XIniText::TSection * pSection = stIni.getSection(i);
                            
                            TStringKeyValue & stKeyValue = m_Map[pSection->getSectionName()];
                            for (int j = 0; j < pSection->getLength(); j++)
                            {
                                XIniText::TEntry * pEntry = pSection->getEntry(j);
                                if (isNULL(pEntry)) continue;
                                if (pEntry->getEntryType() != EIET_COMMON_ENTRY) continue;
                                XIniText::TEntryCommon * pCommonEntry = dynamic_cast<XIniText::TEntryCommon *>(pEntry);
                                if (isNULL(pCommonEntry)) continue;
                                stKeyValue[pCommonEntry->getKey().getField()] = pCommonEntry->getValue().getField();
                            }
                        }
                        return ERR_OK;
                    }
                    //取指定字符串對象,如果不存在,返回NULL
                    const XAnsiString * getStringEx(const XAnsiString & paramSection, const XAnsiString & paramKey)
                    {
                        int iSectionIndex = m_Map.getIndexBykey(paramSection);
                        if (!m_Map.isValidIndex(iSectionIndex)) return NULL;
                        const TStringKeyValue & stKeyValue = m_Map.getValue(iSectionIndex);
                        int iValueIndex = stKeyValue.getIndexBykey(paramKey);
                        if (!stKeyValue.isValidIndex(iValueIndex)) return NULL;
                        return &stKeyValue.getValue(iValueIndex);
                    }
                    //取指定的字符串,如果不存在,則返回空串
                    const char * getString(const XAnsiString & paramSection, const XAnsiString & paramKey)
                    {
                        const XAnsiString * pRet = getStringEx(paramSection, paramKey);
                        if (isNULL(pRet)) return "";
                        else return pRet->c_str();
                    }

                    const TStringSection & getMap() const
                    {
                        return m_Map;
                    }

                private:
                    TStringSection m_Map;
                };
            }
                #define STRING_MGR zdh::XSingletonSample<zdh::XStringMgr, 0>::getInstance()
                #define STRING_SECTION_MAIN "main"
                #define STRING_PLAY (STRING_MGR->getString(STRING_SECTION_MAIN, "play"))
                #define STRING_FONT (STRING_MGR->getString(STRING_SECTION_MAIN, "font"))
            #endif
            使用例子
                XAnsiString strStringMgrFileName("string_zh.ini");
                if (zdh::isNotOK(STRING_MGR->Load(strStringMgrFileName)))
                {
                    STREAM_INFO << "load "<<strStringMgrFileName << "Fail!";
                    return false;
                }
                else
                {
                    STREAM_INFO << "Load String:" << STRING_PLAY;
                }
            posted on 2014-06-30 14:59 冬瓜 閱讀(1276) 評論(0)  編輯 收藏 引用 所屬分類: 原創cocos2dx
            久久久中文字幕日本| 日韩人妻无码精品久久免费一 | 久久综合九色综合欧美就去吻| 亚洲一区二区三区日本久久九| 久久一区二区免费播放| 国产精品久久久久久久久软件 | 久久精品成人免费看| 伊人色综合久久天天网| 蜜臀av性久久久久蜜臀aⅴ| 久久久久久久尹人综合网亚洲| 亚洲人成无码网站久久99热国产| 亚洲狠狠婷婷综合久久蜜芽| 久久精品成人一区二区三区| 久久精品中文无码资源站| 欧美亚洲国产精品久久高清| 成人久久久观看免费毛片| 人人狠狠综合久久88成人| 一本久久久久久久| 久久精品aⅴ无码中文字字幕重口| 国产三级精品久久| 亚洲国产成人精品无码久久久久久综合| 狠色狠色狠狠色综合久久| 伊人色综合九久久天天蜜桃| 国产精品久久永久免费| 欧美熟妇另类久久久久久不卡| 亚洲国产日韩欧美久久| 久久精品中文字幕有码| 久久香蕉国产线看观看99| 久久久国产精品亚洲一区| 人妻少妇久久中文字幕一区二区 | 免费精品久久天干天干| 久久综合色之久久综合| 久久国产精品免费| 7777精品伊人久久久大香线蕉| 国产激情久久久久影院| 一级做a爱片久久毛片| 国产精品九九九久久九九| 久久国产色AV免费看| 狠狠色丁香婷综合久久| 久久国产精品国产自线拍免费 | 亚洲第一永久AV网站久久精品男人的天堂AV |