\S - one or more spaces \s - zero or more spaces \H - hex number (captures) \I - identifier (captures) \X - anything
| 2696 | // \I - identifier (captures) |
| 2697 | // \X - anything |
| 2698 | bool fmt_match(string fmt, string str, vector<string>& result) |
| 2699 | { |
| 2700 | bool match = false; |
| 2701 | size_t i=0, j=0; |
| 2702 | size_t nfmt=fmt.size(), nstr=str.size(); |
| 2703 | |
| 2704 | result.clear(); |
| 2705 | while(1) { |
| 2706 | string fcode = fmt.substr(i,2); |
| 2707 | |
| 2708 | if(fcode=="\\S") { |
| 2709 | if(!isspace(str[j])) |
| 2710 | goto cleanup; |
| 2711 | while(isspace(str[j])) |
| 2712 | j += 1; |
| 2713 | i += 2; |
| 2714 | } |
| 2715 | else |
| 2716 | if(fcode=="\\s") { |
| 2717 | while(isspace(str[j])) |
| 2718 | j += 1; |
| 2719 | i += 2; |
| 2720 | } |
| 2721 | else |
| 2722 | if(fcode=="\\I") { |
| 2723 | if(!isalpha(str[j])) |
| 2724 | goto cleanup; |
| 2725 | size_t start = j; |
| 2726 | j += 1; |
| 2727 | while(isalnum(str[j]) || str[j]=='_') |
| 2728 | j += 1; |
| 2729 | result.push_back(str.substr(start, j-start)); |
| 2730 | i += 2; |
| 2731 | } |
| 2732 | else |
| 2733 | if(fcode=="\\H") { |
| 2734 | const char *raw = str.c_str(); |
| 2735 | char *endptr; |
| 2736 | strtoul(raw + j, &endptr, 16); |
| 2737 | size_t len = endptr - (raw+j); |
| 2738 | if(!len) goto cleanup; |
| 2739 | result.push_back(str.substr(j, len)); |
| 2740 | i += 2; |
| 2741 | j += len; |
| 2742 | } |
| 2743 | else |
| 2744 | if(fcode=="\\X") { |
| 2745 | i += 2; |
| 2746 | j = nstr; |
| 2747 | } |
| 2748 | else |
| 2749 | if(fmt[i] == str[j]) { |
| 2750 | i += 1; |
| 2751 | j += 1; |
| 2752 | } |
| 2753 | else { |
| 2754 | goto cleanup; |
| 2755 | } |
no test coverage detected