Match path

来自MudWiki
Ivy讨论 | 贡献2021年5月24日 (一) 14:47的版本 DESCRIPTION
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

NAME

   match_path() - search a mapping for a path

SYNOPSIS

   mixed match_path( mapping m, string str );

DESCRIPTION

   match_path()  searches a mapping for a path.  Each key is assumed to be a string.  The value is  completely  arbitrary.   The  efun  finds the largest matching path in the mapping.  Keys ended in '/' are assumed to match paths with character that follow the '/', i.e. / is  a wildcard for anything below this directory.

示例

   void do_tests()
   {
       mapping m = (["foo/":1, "bar":2, "bazz/foo":3, "foo/bar/bazz":4]);
 
       ASSERT(!match_path(m, "kajdfj"));
       ASSERT(match_path(m, "bar") == 2);
       ASSERT(match_path(m, "bar/") == 2);
       ASSERT(match_path(m, "bazz//foo") == 3);
       ASSERT(match_path(m, "bazz/foo//") == 3);
       ASSERT(match_path(m, "foo/bar") == 1);
       ASSERT(match_path(m, "foo/bar/bazz") == 4);
   }

AUTHOR

   Cygnus