This library will convert a fully-formatted text string to its original arguments given a format string.
It is essentially the opposite of string.format.
local LibDeformat = LibStub("LibDeformat-3.0") LibDeformat("Hello, friend", "Hello, %s") => "friend" LibDeformat("Hello, friend", "Hello, %1$s") => "friend" LibDeformat("Cost: $100", "Cost: $%d") => 100 -- note that it converted it back to a number LibDeformat("Cost: $100", "Cost: $%1$d") => 100 LibDeformat("Alpha, Bravo", "%s, %s") => "Alpha", "Bravo" LibDeformat("Alpha, Bravo", "%1$s, %2$s") => "Alpha", "Bravo" LibDeformat("Alpha, Bravo", "%2$s, %1$s") => "Bravo", "Alpha" -- this can happen in foreign languages LibDeformat("Hello, friend", "Cost: $%d") => nil -- nil is returned when there is no match
LibDeformat-3.0 API
- 1 comment
- 1 comment
Facts
- Date created
- Jan 04, 2010
- Category
- Last update
- Jan 04, 2010
- Development stage
- Abandoned
- Language
- enUS
- License
- MIT License
- Reverse relationships
- 1
- Downloads
- 3,438
- Recent files
- R: v1 for 3.3.0 Jan 04, 2010
- A: r20100104174927 for 3.3.0 Jan 04, 2010
- A: r20100104172157 for 3.3.0 Jan 04, 2010
- A: r20100104164853 for 3.3.0 Jan 04, 2010
- A: r20100104145730 for 3.3.0 Jan 04, 2010
- Reply
- #1
jerry Jan 05, 2010 at 10:13 UTC - 0 likesAs http://www.lua.org/pil/17.html (look at the last paragraph), you can't have a table with strings as weak keys.
When I adapted LibItemBonus to LibStub, I had to drop Deformat and use my own solution. After some refinement, I finally got a working solution (GetPattern) which does pretty much what LibDeformat-3.0 does, except without caching. (The API returns a callable that can be reused to check new strings). i.e:
Look at the GetPattern implementation from the Core.lua file in LibItemBonus-2.0 for details.