Method code for $db.match_begin()

[Turn off line numbering]
  1: arg key;
  2: var matches, entry;
  3: 
  4: // First check if we're using $trie frob
  5: if (type(database) == 'frob) {
  6:     matches = (| (database.match_begin(key))[2] |);
  7:     if (matches == ~keynf)
  8:         throw(~matchnf, "No entries in the database match that key.");
  9:     if (matches == ~ambig)
 10:         throw(~ambig, "More than one object matches that key.");
 11:     return matches;
 12: }
 13: 
 14: // use match_begin of the key, return the value
 15: matches = [(| .exact_match(key) |)];
 16: if (!matches[1]) {
 17:     matches = [];
 18:     for entry in (database) {
 19:         if (match_begin(entry[1], key))
 20:             matches = setadd(matches, entry[2]);
 21:     }
 22: }
 23: if (matches) {
 24:     if (matches.length() == 1)
 25:         return matches[1];
 26:     else
 27:         throw(~ambig, "More than one object matches that key.", matches);
 28: } else {
 29:     throw(~matchnf, "No entries in the database match that key.");
 30: }

// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit

Tlon