• <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伊人久久综合密臀性色| 国产亚洲精久久久久久无码| 狠狠色婷婷综合天天久久丁香| 国产精品va久久久久久久| 久久久久一本毛久久久| 久久久午夜精品| 久久99精品国产麻豆宅宅| 久久综合久久伊人| 狠狠色婷婷久久一区二区三区 | 国产精品美女久久久久| 久久精品国产一区二区电影| 综合久久国产九一剧情麻豆 | 国产69精品久久久久9999APGF| 996久久国产精品线观看| 久久夜色精品国产亚洲| 精品久久久久中文字| 国内精品久久久人妻中文字幕| 污污内射久久一区二区欧美日韩 | 99久久精品免费看国产| 国内精品伊人久久久久av一坑 | 日韩久久久久久中文人妻| 久久人人爽人人爽人人片AV麻豆 | 中文字幕无码免费久久| 亚洲伊人久久成综合人影院| 亚洲国产精品久久久久婷婷软件 | 久久精品人人做人人爽电影蜜月| 久久精品成人欧美大片| 亚洲一本综合久久| 久久精品嫩草影院| 久久99国产亚洲高清观看首页 | 亚洲精品乱码久久久久久自慰| 色偷偷88欧美精品久久久| 国产999精品久久久久久| 精品999久久久久久中文字幕| 狠狠久久亚洲欧美专区| 狠狠色丁香久久综合五月| 国产精品美女久久久久久2018| 久久久久久亚洲精品成人| 99久久精品日本一区二区免费| 91精品国产综合久久久久久|