Handy plugin PeterR and generally works well.
May I suggest a couple of minor amendments.
(1) Reformatting to Single-Line (with commas)
FH V5 now treats an optional comma, preceding optional white-space layout chars, preceding a newline as a single Column Part separator.
Therefore the Find pattern should be ',?%s-n' to detect these possibilities.
,? detect an optional comma.
%s- detects optional white-space layout chars such as spaces and tabs.
n detects the necessary newline.
[Edit] It might also be useful to add %s* after n to remove leading white-space layout chars from the start of the next line.
(2) Reformatting to Multi-Line
Personally I think each newline looks better with a preceding comma, whether viewed in single-line Address fields, or multi-line Edit and Report fields.
For this the Replace pattern would be ',n'.
ID:5902
* Address Reformatting Plugin 1.0
- tatewise
- Megastar
- Posts: 27080
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Address Reformatting Plugin 1.0
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- PeterR
- Megastar
- Posts: 1129
- Joined: 10 Jul 2006 16:55
- Family Historian: V7
- Location: Northumberland, UK
Address Reformatting Plugin 1.0
Thanks for comments.
(1) Easily done.
(2) Quite a bit trickier. I had to learn about iup.GetParam in order to handle the option for an added comma, and I wanted to ensure a uniform end result, whatever mixture of initial address formats is present.
I will not be surprised if you can suggest further improvements or simplifications, but at least version 1.1 seems to work OK.
(1) Easily done.
(2) Quite a bit trickier. I had to learn about iup.GetParam in order to handle the option for an added comma, and I wanted to ensure a uniform end result, whatever mixture of initial address formats is present.
I will not be surprised if you can suggest further improvements or simplifications, but at least version 1.1 seems to work OK.
Peter Richmond (researching Richmond, Bulman, Martin, Driscoll, Baxter, Hall, Dales, Tyrer)
- tatewise
- Megastar
- Posts: 27080
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Address Reformatting Plugin 1.0
I have given this a bit more thought, and some experimentation.
My objective has been to cope with all likely Column Part separators, and tidy them all to the same desired format.
So if the desired format is comma & space, then every separator should be changed to this format.
My first realisation is that Column Part separators can have the following format.
(1) white-space chars
(2) single comma (,)
(3) white-space chars
(4) single newline (n)
(5) white-space chars
where white-space can be any layout chars such as space &/or tab.
Each item is optional, except that the comma (,) or newline (n) must exist.
The second realisation is that the %s* pattern consumes not only spaces & tabs, but also newlines.
Thus [ t]* should be used instead, assuming that only spaces & tabs are likely to appear in Address fields.
The third realisation is that to tidy all Column Part separators, they must all be detected, not just the ones needing comma or newline changed.
This requires a two stage substitution.
Finally the code needed to achieve this is as follows.
For Single-Line (with commas)
sFind1 = '[ t]*,?[ t]*n[ t]*'
sFind2 = '[ t]*,[ t]*'
sReplace = ', '
For Multi-Line (with commas)
sFind1 = '[ t]*,[ t]*n?[ t]*'
sFind2 = '[ t^,]*n[ t]*'
sReplace = ',n'
For Multi-Line (without commas)
sFind1 = '[ t]*,[ t]*n?[ t]*'
sFind2 = '[ t]*n[ t]*'
sReplace = 'n'
The substitution code becomes:
if string.find(strAddr, sFind1) or string.find(strAddr, sFind2) then -- Only Addresses with something to change
strResult = string.gsub(strAddr, sFind1, sReplace) -- Make 1st change
strResult = string.gsub(strResult, sFind2, sReplace) -- Make 2nd change
My objective has been to cope with all likely Column Part separators, and tidy them all to the same desired format.
So if the desired format is comma & space, then every separator should be changed to this format.
My first realisation is that Column Part separators can have the following format.
(1) white-space chars
(2) single comma (,)
(3) white-space chars
(4) single newline (n)
(5) white-space chars
where white-space can be any layout chars such as space &/or tab.
Each item is optional, except that the comma (,) or newline (n) must exist.
The second realisation is that the %s* pattern consumes not only spaces & tabs, but also newlines.
Thus [ t]* should be used instead, assuming that only spaces & tabs are likely to appear in Address fields.
The third realisation is that to tidy all Column Part separators, they must all be detected, not just the ones needing comma or newline changed.
This requires a two stage substitution.
Finally the code needed to achieve this is as follows.
For Single-Line (with commas)
sFind1 = '[ t]*,?[ t]*n[ t]*'
sFind2 = '[ t]*,[ t]*'
sReplace = ', '
For Multi-Line (with commas)
sFind1 = '[ t]*,[ t]*n?[ t]*'
sFind2 = '[ t^,]*n[ t]*'
sReplace = ',n'
For Multi-Line (without commas)
sFind1 = '[ t]*,[ t]*n?[ t]*'
sFind2 = '[ t]*n[ t]*'
sReplace = 'n'
The substitution code becomes:
if string.find(strAddr, sFind1) or string.find(strAddr, sFind2) then -- Only Addresses with something to change
strResult = string.gsub(strAddr, sFind1, sReplace) -- Make 1st change
strResult = string.gsub(strResult, sFind2, sReplace) -- Make 2nd change
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- tatewise
- Megastar
- Posts: 27080
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Address Reformatting Plugin 1.0
Peter, when you want to update your Plugin, do not use Submit a Plugin to the Store
Instead, use View your Plugins, then Login and use the tiny Edit link between Downloads 99 and Delete.
Instead, use View your Plugins, then Login and use the tiny Edit link between Downloads 99 and Delete.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- PeterR
- Megastar
- Posts: 1129
- Joined: 10 Jul 2006 16:55
- Family Historian: V7
- Location: Northumberland, UK
Address Reformatting Plugin 1.0
Mike, many thanks. I did eventually spot the tiny Edit link, but only after I'd done it the wrong way.
Yes, it's surprising just how tricky this apparently simple job turns out to be, given all the possible starting conditions. My version 1.1 (after much thought and experimentation, and not a little head-scratching) achieves most, but not all of the desired aims, but I will, in due course, incorporate the fruits of your deliberations in v1.2, resulting in a complete and more elegant solution, albeit with more complex Find expressions.
Yes, it's surprising just how tricky this apparently simple job turns out to be, given all the possible starting conditions. My version 1.1 (after much thought and experimentation, and not a little head-scratching) achieves most, but not all of the desired aims, but I will, in due course, incorporate the fruits of your deliberations in v1.2, resulting in a complete and more elegant solution, albeit with more complex Find expressions.
Peter Richmond (researching Richmond, Bulman, Martin, Driscoll, Baxter, Hall, Dales, Tyrer)