• <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
            色综合久久天天综合| 久久国产三级无码一区二区| 伊人情人综合成人久久网小说| 欧美日韩精品久久免费| 99久久er这里只有精品18| 亚洲精品美女久久久久99小说| 国产精品久久久久久一区二区三区 | 久久人人爽人人爽人人片AV不| 欧美黑人激情性久久| 久久亚洲精品成人无码网站| 久久精品国产亚洲av麻豆色欲 | 91麻豆国产精品91久久久| 欧美黑人又粗又大久久久| 国内精品久久久久久久亚洲| 亚洲国产精品久久久久久| 国产三级久久久精品麻豆三级 | 日本免费久久久久久久网站| 久久性生大片免费观看性| 久久国产乱子伦精品免费午夜| 久久精品人妻中文系列| 国产免费久久久久久无码| 久久久久亚洲爆乳少妇无| 老色鬼久久亚洲AV综合| 久久久久久午夜精品| 精品久久久久久久久久中文字幕 | 97精品伊人久久久大香线蕉| 久久久久久久久久久| 久久av高潮av无码av喷吹| 久久亚洲精品视频| 国产亚洲综合久久系列| 亚洲αv久久久噜噜噜噜噜| 伊人久久大香线蕉亚洲五月天| 亚洲va中文字幕无码久久不卡| 伊人久久成人成综合网222| 久久久久一本毛久久久| 久久国产精品免费| 精品欧美一区二区三区久久久| 99精品久久久久久久婷婷| 久久精品国产亚洲综合色| 亚洲人成电影网站久久| 久久久久久亚洲精品不卡|