• <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
            亚洲中文字幕无码久久2020| 91久久精品视频| 久久人妻少妇嫩草AV无码蜜桃| 国产精品久久久久久影院 | 久久夜色精品国产噜噜亚洲AV| 久久久久久久久无码精品亚洲日韩| 久久九九亚洲精品| 久久久久99这里有精品10| 精品999久久久久久中文字幕| 日本精品一区二区久久久| 久久精品人人做人人爽97| 精品久久久久国产免费| 久久久久亚洲av无码专区导航| 国产91久久综合| 亚洲精品乱码久久久久久蜜桃图片 | 一本色综合久久| av无码久久久久久不卡网站| 色偷偷88欧美精品久久久| 国产精品18久久久久久vr| 久久香综合精品久久伊人| 久久国产视屏| 天天久久狠狠色综合| 五月丁香综合激情六月久久| 香蕉99久久国产综合精品宅男自 | 99精品伊人久久久大香线蕉| 久久精品a亚洲国产v高清不卡| 伊人久久大香线蕉综合热线| 久久国产成人| 久久久精品视频免费观看| AAA级久久久精品无码区| 久久99热国产这有精品| 国内精品久久久久久久97牛牛| 久久大香萑太香蕉av| 伊人久久无码精品中文字幕| 久久久久无码中| 日批日出水久久亚洲精品tv| 久久精品国产亚洲Aⅴ香蕉| 久久久久无码国产精品不卡| 久久精品亚洲精品国产欧美| 久久se精品一区二区影院 | 久久久久人妻一区二区三区|