| | 1 | #charset "us-ascii" |
| | 2 | #include <adv3.h> |
| | 3 | #include <en_us.h> |
| | 4 | |
| | 5 | ModuleID |
| | 6 | { |
| | 7 | name = 'GiveTo->AskFor Library Extension' |
| | 8 | byline = 'by Eric Eve' |
| | 9 | htmlByline = 'by <a href="mailto:eric.eve@hmc.ox.ac.uk">Eric Eve</a>' |
| | 10 | version = '2.0' |
| | 11 | listingOrder = 72 |
| | 12 | } |
| | 13 | |
| | 14 | /* Converts X, GIVE ME Y into ASK X FOR Y */ |
| | 15 | |
| | 16 | StringPreParser |
| | 17 | runOrder = 90 |
| | 18 | |
| | 19 | doParsing(str, which) |
| | 20 | { |
| | 21 | local workStr = str.toLower; |
| | 22 | local iGive = workStr.find('give'); |
| | 23 | if(iGive == nil) |
| | 24 | return str; |
| | 25 | |
| | 26 | local iComma = workStr.find(','); |
| | 27 | local iGiveMe = workStr.find('give me'); |
| | 28 | local iToMe = workStr.find('to me'); |
| | 29 | local objectName; |
| | 30 | |
| | 31 | if(iComma == nil || (iGiveMe == nil && iToMe == nil)) |
| | 32 | return str; |
| | 33 | |
| | 34 | local npcName = workStr.substr(1, iComma-1); |
| | 35 | |
| | 36 | if(iGiveMe) |
| | 37 | objectName = workStr.substr(iGiveMe + 8); |
| | 38 | else |
| | 39 | { |
| | 40 | |
| | 41 | if(iGive == nil || iGive > iToMe || iGive < iComma) |
| | 42 | return str; |
| | 43 | |
| | 44 | objectName = workStr.substr(iGive + 5, iToMe - iGive - 6); |
| | 45 | } |
| | 46 | |
| | 47 | str = 'ask ' + npcName + ' for ' + objectName; |
| | 48 | |
| | 49 | str = rexReplace(pat, str, npcName + '\'s', ReplaceAll); |
| | 50 | |
| | 51 | return str; |
| | 52 | } |
| | 53 | |
| | 54 | pat = static new RexPattern('%<your%>') |
| | 55 | ; |
| | 56 | |
| | 57 | |