Exemple #1
0
void DictProducer::build_dict()
{
    for(std::size_t idx = 0; idx != _files.size(); ++idx){
        //从文件流中读入
        std::ifstream ifs(_files[idx].c_str());
        if(!ifs){
            std::cout << "stream error, file does not exist or other" << std::endl;
            continue;
        }
        //字符串流
        std::stringstream ss;
        std::string line;
        while(getline(ifs, line)){
            //从 line 中读取一个字符串
            ss << line;
            std::string word;
            while(ss >> word){
                //只存储小写字母
                //并对不是字符的操作进行过滤
                word = ::upper_to_lower(word);
                //上一步操作对含有非字母的单词进行赋值空字符的操作
                if(word == std::string())
                    continue;
                push_dict(word);
            }
            ss.clear();
        }
    }
}
Exemple #2
0
    PyObject * next()
    {
        auto obj = read_next();

        if( is_array( obj ) )
        {
            if( obj.as.array_size )
            {
                push_list( obj.as.array_size );

                return nullptr;
            }

            return PyList_New( 0 );
        }
        
        if( is_map( obj ) )
        {
            if( obj.as.map_size )
            {
                push_dict( obj.as.map_size );

                return nullptr;
            }

            return PyDict_New();
        }
            
        return read_simple( obj );
    }
Exemple #3
0
void func_dict_union(void) {
    cData * args;
    cDict * dict1, * dict2, *d;

    if (!func_init_2(&args, DICT, DICT))
        return;

    dict1 = dict_dup(DICT1);
    dict2 = dict_dup(DICT2);
    pop(2);

    /* dict_union will discard the dicts */
    d = dict_union(dict1, dict2);

    push_dict(d);
    dict_discard(d);
}