model_server/project_pdf/src/path.h.cxx
//
// Only support one (*) between two '/'s
// "/x(*)y/", "/x(*)/", "/(*)/", "/(*)y/" are legal
// "/x(*)y(*)z/" is ambiguous.
//
// idx is the starting index for the buffer str_buf.
//
// split the physical path into the matched patterns
//
// path: the physical path
//
// cur: contains the rule for this phisical path
//
// cur_len: is the length of the matched path
//
// full_match_flag: will be set to 1 if the full path could be matched; otherwise it is set to 0
//
// idx: is used for selectors because selectors are checked one by one


idx is the starting index for the buffer str_buf.

split the physical path into the matched patterns

the physical path

contains the rule for this phisical path



will be set to 1 if the full path could be matched; otherwise it is set to 0


idx is the starting index for the buffer str_buf . split the physical path into the matched patterns the physical path contains the rule for this phisical path will be set to 1 if the full path could be matched ; otherwise it is set to 0
static bool new_split_ptn_path(char const *path1, wkPtnRule *cur, int *cur_len, int *full_match_flag, int &idx)
{
    Initialize(new_split_ptn_path);
    char *path = strdup(path1);
    {
        WildPair *m = cur->get_multi_match_in_ptnrule();
        *cur_len = 0;
        *full_match_flag = 0;
        int len = m->match(path,MATCH_WITHOUT_END);
        if (len < 0)
            goto FAIL;
        *cur_len = len;
        char const *p = path + *cur_len;
        if (leading_char(path,'/') && *cur_len == 1)
            p = path;
        if (*p && *p != '/') {
            char *q = strchr(p,'/');
            if (q)
                *q = '\0';
            len = m->match(path,MATCH_WITH_END);
            if (q)
                *q = '/';
            if (len <= 0) {
                *cur_len = 0;
                goto FAIL;
            }
            *cur_len = len;
            p = path + *cur_len;
        } else if (!len)
            goto FAIL;
        if (*p && *p == '/')
            tail_portion = p+1;
        else
            tail_portion = 0;
        wkPtnDef *cur_def = cur->get_ptn_strs();
        int s_idx = 1;
        int prev_end = -2;                    
        while(1) {
            while(cur_def) {
                if (cur_def->get_type() == PTN_MATCH_MAPPING || cur_def->get_type() == PTN_IDX ||
                    (cur_def->get_type() == PTN_CONST_STRING && strstr(cur_def->get_str(),"**")))
                    break;
                cur_def = cur_def->get_next();
            }
            if (!cur_def)
                break;
            int start;
            int end;
            while(1) {
                m->range(s_idx, start, end);
                s_idx++;
                if (start >= prev_end)
                    {
                        prev_end = end;
                        break;
                    }
            }
            if (str_buf[idx])
                psetfree(str_buf[idx]); 
            char temp = path[end];
            path[end] = '\0';
            if (cur_def->get_type() == PTN_IDX) {
                if (strcmp(path+start,str_buf[cur_def->get_idx()])) {
                    *cur_len = 0;
                    goto FAIL; 
                }
            }
            else
                str_buf[idx] = strdup(path+start);
            path[end] = temp;
            cur_def = cur_def->get_next();
            idx++;
        }
        *full_match_flag = 1;
        free(path);
        return true;
    }
 FAIL:
    free(path);
    return false;
}
static bool new_split_ptn_path ( char const * path1 , wkPtnRule * cur , int * cur_len , int * full_match_flag , int & idx ) { Initialize ( new_split_ptn_path ) ; char * path = strdup ( path1 ) ; { WildPair * m = cur -> get_multi_match_in_ptnrule ( ) ; * cur_len = 0 ; * full_match_flag = 0 ; int len = m -> match ( path , MATCH_WITHOUT_END ) ; if ( len < 0 ) goto FAIL ; * cur_len = len ; char const * p = path + * cur_len ; if ( leading_char ( path , ' ' ) && * cur_len == 1 ) p = path ; if ( * p && * p != ' ' ) { char * q = strchr ( p , ' ' ) ; if ( q ) * q = ' \0 ' ; len = m -> match ( path , MATCH_WITH_END ) ; if ( q ) * q = ' ' ; if ( len <= 0 ) { * cur_len = 0 ; goto FAIL ; } * cur_len = len ; p = path + * cur_len ; } else if ( ! len ) goto FAIL ; if ( * p && * p == ' ' ) tail_portion = p + 1 ; else tail_portion = 0 ; wkPtnDef * cur_def = cur -> get_ptn_strs ( ) ; int s_idx = 1 ; int prev_end = -2 ; while ( 1 ) { while ( cur_def ) { if ( cur_def -> get_type ( ) == PTN_MATCH_MAPPING || cur_def -> get_type ( ) == PTN_IDX || ( cur_def -> get_type ( ) == PTN_CONST_STRING && strstr ( cur_def -> get_str ( ) , " " ) ) ) break ; cur_def = cur_def -> get_next ( ) ; } if ( ! cur_def ) break ; int start ; int end ; while ( 1 ) { m -> range ( s_idx , start , end ) ; s_idx ++ ; if ( start >= prev_end ) { prev_end = end ; break ; } } if ( str_buf [ idx ] ) psetfree ( str_buf [ idx ] ) ; char temp = path [ end ] ; path [ end ] = ' \0 ' ; if ( cur_def -> get_type ( ) == PTN_IDX ) { if ( strcmp ( path + start , str_buf [ cur_def -> get_idx ( ) ] ) ) { * cur_len = 0 ; goto FAIL ; } } else str_buf [ idx ] = strdup ( path + start ) ; path [ end ] = temp ; cur_def = cur_def -> get_next ( ) ; idx ++ ; } * full_match_flag = 1 ; free ( path ) ; return true ; } FAIL : free ( path ) ; return false ; }
Only support one (*) between two '/'s
"/x(*)y/", "/x(*)/", "/(*)/", "/(*)y/" are legal
"/x(*)y(*)z/" is ambiguous.
Only support one ( * ) between two ' / ' s " / x ( * ) y / " " / x ( * ) / " " / ( * ) / " " / ( * ) y / " are legal " / x ( * ) y ( * ) z / " is ambiguous .
// int prev_start = strlen(path) + 2; //  1 is enough // -1 is enough // prev_start = start; // str_buf is already used as working buffer // fail