woaidongmao

文章均收录自他人博客,但不喜标题前加-[转贴],因其丑陋,见谅!~
随笔 - 1469, 文章 - 0, 评论 - 661, 引用 - 0
数据加载中……

让ragel可以使用扩展ascii码

%%{
    machine decode_object;
    write data;
    alphtype unsigned char;
}%%

bool decode_object(unsigned char *decode_data, int len)
{
    int content_type = 0;
    unsigned char *p = str, *pe = decode_data + len, *eof = pe;
    unsigned char* p_code_beg = decode_data;
    int cs;
    %%{
    action     lc{p_code_beg = p;}
    action  lv_atomic_code{}
    action  lv_object_open{}
    action  lv_object_close{}
    action  lv_escape_254{}
    action  lv_field_begin{}
    action  lv_escape_255{}
    atomic_code =   (0..253)                    %lv_atomic_code %lc;
    object_index =     (0..254 0..255)
                    |(255 0..253);
    object_open =  (254 object_index)            %lv_object_open %lc;
    object_close = (254 255 254)                %lv_object_close %lc;
    escape_254 =   (254 255 255)                %lv_escape_254 %lc;
    field_index = 0..254;
    field_begin = (255 field_index)                %lv_field_begin %lc;
    escape_255 =  (255 255)                        %lv_escape_255 %lc;
    main := (atomic_code | object_open | object_close | escape_254 | field_begin | escape_255)+;
        # Initialize and execute.
        write init;
        write exec;
    }%%
    if(cs < decode_object_first_final)
        return false;
    return true;
}

posted on 2009-09-16 10:33 肥仔 阅读(307) 评论(0)  编辑 收藏 引用 所属分类: 状态机 & 自动机 & 形式语言


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理