Source/NFX.Wave/URIPattern.cs
/// <summary>
/// Tries to match the pattern against the URI path section and returns a JSONDataMap match object filled with pattern match or NULL if pattern could not be matched.
/// JSONDataMap may be easily converted to dynamic by calling new JSONDynamicObject(map)
/// </summary>
Tries to match the pattern against the URI path section and returns a JSONDataMap match object filled with pattern match or NULL if pattern could not be matched.
JSONDataMap may be easily converted to dynamic by calling new JSONDynamicObject(map)
Tries to match the pattern against the URI path section and returns a JSONDataMap match object filled with pattern match or NULL if pattern could not be matched . JSONDataMap may be easily converted to dynamic by calling new JSONDynamicObject ( map )
public JSONDataMap MatchURIPath(Uri uri, bool senseCase = false)
    {
      JSONDataMap result = null;
      if (m_MatchChunks.Count==0) return new JSONDataMap(false);
      var segs = uri.LocalPath.Split('/');
      var ichunk = -1;
      chunk chunk = null;
      var wildCard = false;
      foreach(var seg in segs)
      {
           if (seg.Length==0) continue;
           if (!wildCard)
           {
            ichunk++;
            if (ichunk>=m_MatchChunks.Count) return null;
            chunk = m_MatchChunks[ichunk];
           }
           if (chunk.Portion!=chunkPortion.Path) return null;
           if (chunk.IsWildcard)
           {
             wildCard = true;
             if (result==null) result = new JSONDataMap(false);
             if (!result.ContainsKey(chunk.Name))
                result[chunk.Name] = seg;
             else
                result[chunk.Name] = (string)result[chunk.Name] + '/' + seg;
           }
           else
           if (chunk.IsVar)
           {
              if (result==null) result = new JSONDataMap(false);
              result[chunk.Name] = seg;
           }
           else
           if (!chunk.Name.Equals(seg, senseCase ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase)) return null;
      }
      ichunk++;
      while(ichunk<m_MatchChunks.Count)
      {
        chunk=m_MatchChunks[ichunk];
        if (!chunk.IsVar) return null;
        if (result==null)
          result = new JSONDataMap(false);
        if (!result.ContainsKey(chunk.Name))
          result[chunk.Name] = chunk.DefaultValue;
        ichunk++;
      }
      return result ?? new JSONDataMap(false);
    }
public JSONDataMap MatchURIPath ( Uri uri , bool senseCase = false ) { JSONDataMap result = null ; if ( m_MatchChunks . Count == 0 ) return new JSONDataMap ( false ) ; var segs = uri . LocalPath . Split ( ' ' ) ; var ichunk = - 1 ; chunk chunk = null ; var wildCard = false ; foreach ( var seg in segs ) { if ( seg . Length == 0 ) continue ; if ( ! wildCard ) { ichunk ++ ; if ( ichunk >= m_MatchChunks . Count ) return null ; chunk = m_MatchChunks [ ichunk ] ; } if ( chunk . Portion != chunkPortion . Path ) return null ; if ( chunk . IsWildcard ) { wildCard = true ; if ( result == null ) result = new JSONDataMap ( false ) ; if ( ! result . ContainsKey ( chunk . Name ) ) result [ chunk . Name ] = seg ; else result [ chunk . Name ] = ( string ) result [ chunk . Name ] + ' ' + seg ; } else if ( chunk . IsVar ) { if ( result == null ) result = new JSONDataMap ( false ) ; result [ chunk . Name ] = seg ; } else if ( ! chunk . Name . Equals ( seg , senseCase ? StringComparison . InvariantCulture : StringComparison . InvariantCultureIgnoreCase ) ) return null ; } ichunk ++ ; while ( ichunk < m_MatchChunks . Count ) { chunk = m_MatchChunks [ ichunk ] ; if ( ! chunk . IsVar ) return null ; if ( result == null ) result = new JSONDataMap ( false ) ; if ( ! result . ContainsKey ( chunk . Name ) ) result [ chunk . Name ] = chunk . DefaultValue ; ichunk ++ ; } return result ?? new JSONDataMap ( false ) ; }
Tries to match the pattern against the URI path section and returns a JSONDataMap match object filled with pattern match or NULL if pattern could not be matched.
Tries to match the pattern against the URI path section and returns a JSONDataMap match object filled with pattern match or NULL if pattern could not be matched .
//skip empty //// //foreach //some trailing elements that are not vars and  do not match
uri
Uri
senseCase
bool