Class ItemLines
(item, quantity) pairs, and the parser that reads one from user text.
Extracted from BuyPlan once withdrawing needed the same thing. Both a shop purchase and
a bank withdrawal are "get me N of each of these", and the awkward part — deciding where the name
ends and the quantity begins — is worth having exactly one tested copy of.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic List<ItemLines.Line> Parses a free-form item list.static intremaining(ItemLines.Line line, int have) Units still needed to reach a line's target.
-
Method Details
-
parse
Parses a free-form item list. Entries are separated by newlines or commas; a missing quantity defaults to 1.A quantity is a run of digits marked with an x, on either side of the name and either way round:
Shark x10,Shark 10x,10x Shark. The x may be capital and may have spaces around it.Only
Name x10used to be understood.Larupia fur 20xleft nothing after the final x, so no quantity was split off and the whole entry became the item name; the shop sold nothing called that, every attempt ended NOT_SOLD_HERE, and a buy flow retried it for minutes next to a shop that sold Larupia fur to a hand click. Every form someone would naturally type is read now, and anything else still falls back to "the whole entry is the name".Names are protected by requiring the digits and the x to stand together as their own token:
Rune axe,Box trapand3rd age amuletstay whole.- Returns:
- never null; blank entries are dropped
-
remaining
Units still needed to reach a line's target. Never negative.
-