Page 1 of 1

Address Reformatting Plugin 1.0

Posted: 09 Feb 2012 22:49
by tatewise
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

Posted: 11 Feb 2012 15:59
by PeterR
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.

Address Reformatting Plugin 1.0

Posted: 12 Feb 2012 17:41
by tatewise
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

Address Reformatting Plugin 1.0

Posted: 13 Feb 2012 14:26
by tatewise
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.

Address Reformatting Plugin 1.0

Posted: 13 Feb 2012 15:34
by PeterR
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.