• <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++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(28)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            在用vs開發(fā)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 冬瓜 閱讀(1271) 評論(0)  編輯 收藏 引用 所屬分類: 原創(chuàng) 、cocos2dx
            久久久久久A亚洲欧洲AV冫 | 国产呻吟久久久久久久92| 99麻豆久久久国产精品免费| 久久国产精品免费一区二区三区| 久久伊人五月丁香狠狠色| 五月丁香综合激情六月久久| 久久综合五月丁香久久激情| 国产69精品久久久久APP下载| 99久久国产综合精品五月天喷水| 欧美丰满熟妇BBB久久久| 久久精品国产一区二区| 国产三级久久久精品麻豆三级 | 日本精品久久久久影院日本| 青草国产精品久久久久久| 亚洲欧洲久久av| 久久er热视频在这里精品| 99久久99久久精品国产片果冻 | 亚洲AV无码久久精品狠狠爱浪潮 | 久久偷看各类wc女厕嘘嘘 | 久久er国产精品免费观看8| 久久综合亚洲色HEZYO社区| 99久久精品免费| 国内精品伊人久久久久AV影院| 午夜精品久久久久久中宇| 欧美亚洲日本久久精品| 国产亚洲美女精品久久久| 久久er国产精品免费观看2| 国产午夜福利精品久久2021| 午夜天堂精品久久久久| 久久久久亚洲AV无码观看| 日韩欧美亚洲国产精品字幕久久久| 久久精品18| 国内精品久久久久国产盗摄| 久久国产精品久久| 久久er国产精品免费观看8| 色成年激情久久综合| 99久久人妻无码精品系列| 久久超碰97人人做人人爱| 88久久精品无码一区二区毛片| 国产精品成人99久久久久 | 久久综合给合久久国产免费|