Exemple #1
0
const NString& NStringBundleImpl::GetString(const NString& name)
{
    if(name.GetLength() < 1 || name[0] != _T('@'))
        return NString::EmptyString;

    // Find BundleName and stringId
    int pos = name.IndexOf(_T(':'));
    if(pos <= 1 || pos >= name.GetLength() - 1)
        return NString::EmptyString;

    NString bundleName = name.SubString(1, pos - 1);
    NString stringId = name.SubString(pos + 1);

    // Find if existed
    BundleMap::const_iterator iteBundle = bundleMap_.find(bundleName);
    if(iteBundle != bundleMap_.end())
    {
        // existed
        const StringBundle& stringBundle = iteBundle->second;
        StringBundle::const_iterator iteString = stringBundle.find(stringId);
        if(iteString == stringBundle.end())
            return NString::EmptyString;
        return iteString->second;
    }

    // Load Bundle Data
    NString bundlePath = nui::Util::File::CombinePath(basePath_, bundleName);
    bundlePath += _T(".xml");
    NAutoPtr<NDataReader> reader = CreateDataReader(ReaderXml);
    if(!reader->ParseFile(bundlePath.GetData()))
        return NString::EmptyString;

    StringBundle tmpBundle;
    std::pair<BundleMap::iterator, bool> result = bundleMap_.insert(std::make_pair(bundleName, tmpBundle));
    if(!result.second)
        return NString::EmptyString;

    StringBundle& bundleData = result.first->second;

    NString id;
    NString value;
    bool hasId = false;
    NAutoPtr<NDataReader> node;
    for(int i=0; reader->ReadNode(i, node); ++ i)
    {
        if(node->ReadValue(_T("id"), id)
            && node->ReadValue(_T("value"), value))
        {
            if(id == stringId)
                hasId = true;
            bundleData.insert(std::make_pair(id, value));
        }
    }

    if(hasId)
        return bundleData[stringId];
    return NString::EmptyString;
}
Exemple #2
0
NAutoPtr<NDataReader> NParserImpl::FindStyleNode(Base::NAutoPtr<Data::NDataReader> dataReader, LPCTSTR styleName)
{
    NAutoPtr<NDataReader> styleNode;
    for(int i=0;; ++i)
    {
        if(!dataReader->ReadNode(i, styleNode))
            return NULL;
        Base::NString name;
        if(styleNode->ReadValue(_T("name"), name) && name == styleName)
            break;
        styleNode = NULL;
    }
    return styleNode;
}