Пример #1
0
void SemVersion::set(const std::string &version)
{
    // regex to capture semantic version
    // the regex matches case insensitive
    // (1) major version 0 or unlimited number
    // (2) . minor version (0 or unlimited number)
    // (3) . patch version (0 or unlimited number)
    // (4) optional pre-release following a dash consisting of a alphanumeric letters
    //     and hyphens using a non-capture subclause to exclude the dash from the 
    //     pre-release string
    // (5) optional build following a plus consisting of alphanumeric letters and
    //     hyphens using a non-capture subclause to exclude the plus from the build string
    auto semver_regex = std::regex("^(0|[1-9][0-9]*)"   // (1)
                                   "\\.(0|[1-9][0-9]*)" // (2)
                                   "\\.(0|[1-9][0-9]*)" // (3)
                                   "(?:\\-([0-9a-z-]+[\\.0-9a-z-]*))?" // (4)
                                   "(?:\\+([0-9a-z-]+[\\.0-9a-z-]*))?" // (5)
                                   ,
                                   std::regex_constants::ECMAScript |
                                   std::regex_constants::icase);

    auto pieces_match = std::smatch();
    if(std::regex_match(version, pieces_match, semver_regex))
    {
      set(std::atoi(pieces_match[1].str().c_str()),
          std::atoi(pieces_match[2].str().c_str()),
          std::atoi(pieces_match[3].str().c_str()),
          pieces_match[4],
          pieces_match[5]);
    }
    else
    {
      throw bad_format_exception();
    }
}
Пример #2
0
BMP_Parser::BMP_Parser(BeyeContext& b,binary_stream& h,CodeGuider& code_guider,udn& u)
	    :Binary_Parser(b,h,code_guider,u)
	    ,bctx(b)
	    ,main_handle(h)
	    ,_udn(u)
{
    main_handle.seek(0,binary_stream::Seek_Set);
    if(!(main_handle.read(type_byte) == 'B' &&
	main_handle.read(type_byte) == 'M')) throw bad_format_exception();
}
Пример #3
0
SisX_Parser::SisX_Parser(BeyeContext& b,binary_stream& h,CodeGuider& code_guider,udn& u)
	    :Binary_Parser(b,h,code_guider,u)
	    ,bctx(b)
	    ,main_handle(h)
	    ,_udn(u)
{
    unsigned char sign[4];
    unsigned long id;
    main_handle.seek(0,binary_stream::Seek_Set);
    id=main_handle.read(type_dword);
    main_handle.seek(16L,binary_stream::Seek_Set);
    binary_packet bp=main_handle.read(sizeof(sign)); memcpy(sign,bp.data(),bp.size());
    if(!((id&0x10000000UL)==0x10000000UL && memcmp(sign,"EPOC",4)==0)) throw bad_format_exception();
}
Пример #4
0
PharLap_Parser::PharLap_Parser(BeyeContext& b,binary_stream& h,CodeGuider& code_guider,udn& u)
	    :Binary_Parser(b,h,code_guider,u)
	    ,bctx(b)
	    ,main_handle(h)
	    ,_udn(u)
	    ,pl_cache(&h)
{
    char sign[2];
    main_handle.seek(0,binary_stream::Seek_Set);
    binary_packet bp=main_handle.read(2); memcpy(sign,bp.data(),bp.size());
    if(!(sign[0] == 'P' && (sign[1] == '2' || sign[1] == '3'))) throw bad_format_exception();

    main_handle.seek(0,binary_stream::Seek_Set);
    bp=main_handle.read(sizeof(nph)); memcpy(&nph,bp.data(),bp.size());
    pl_cache = main_handle.dup();
}