| 736 | } |
| 737 | |
| 738 | static string _query_database(TextDB &db, string key, bool canonicalise_key, |
| 739 | bool run_lua, bool untranslated) |
| 740 | { |
| 741 | if (canonicalise_key) |
| 742 | { |
| 743 | // We have to canonicalise the key (in case the user typed it |
| 744 | // in and got the case wrong.) |
| 745 | lowercase(key); |
| 746 | } |
| 747 | |
| 748 | // Query the DB. |
| 749 | datum result; |
| 750 | |
| 751 | if (db.translation && !untranslated) |
| 752 | result = _database_fetch(db.translation->get(), key); |
| 753 | if (result.dsize <= 0) |
| 754 | result = _database_fetch(db.get(), key); |
| 755 | |
| 756 | if (result.dsize <= 0) |
| 757 | return ""; |
| 758 | |
| 759 | string str((const char *)result.dptr, result.dsize); |
| 760 | |
| 761 | // <foo> is an alias to key foo |
| 762 | if (str[0] == '<' && str[str.size() - 2] == '>' |
| 763 | && str.find('<', 1) == str.npos |
| 764 | && str.find('\n') == str.size() - 1) |
| 765 | { |
| 766 | return _query_database(db, str.substr(1, str.size() - 3), |
| 767 | canonicalise_key, run_lua, untranslated); |
| 768 | } |
| 769 | |
| 770 | _substitute_descriptions(db, str, canonicalise_key, run_lua, untranslated); |
| 771 | |
| 772 | if (run_lua) |
| 773 | _execute_embedded_lua(str); |
| 774 | |
| 775 | return str; |
| 776 | } |
| 777 | |
| 778 | ///////////////////////////////////////////////////////////////////////////// |
| 779 | // Quote DB specific functions. |
no test coverage detected