gettext bugs and inefficiencies

This contribution is centred around a problem encountered building master on both Mint 10 and 12, where the PO Editor was rendered unusable by load times in excess of 20 minutes. This was down to a change in the loading routine to rely on a String.Split(string[] ...) overload that was very inefficient on mono (I believe it has since been improved). My original bug submission is here https://bugzilla.xamarin.com/show_bug.cgi?id=2509

My intention is to work through the inefficiencies and bugs in the current implementation of the gettext project, here is what I've got so far....

*About Commits "Efficient loading of PO files, better newline detection." and "More Efficient Parsing of PO File":*

CatalogParser.cs has been modified, it no longer pre-loads and stores multiple copies of the PO file in memory, both the GetNewLine and Parse methods access the file through a StreamReader.

The new StreamReader doesnt support /n/r newlines, spoke to mhutch and seems this is not needed anyway so removed it. (See Commit 'Remove /n/r check / splitting …')

To test the parse routine I opened files, made a small change and saved them. This results in the entire file being rewritten from the contents in memory (i.e. that came from the parse routine). I compared (using a diff tool) the outputted file with that which resulted from performing the exact same operation using the 2.6 version of MonoDevelop, and they matched up. I also created a few simple reference PO files which were handled fine. I found the following preexisting issues...

If a deleted entry still has a comment proceeding it, the parsing logic reads the whole entry as a comment which then gets added to the next entry in the file (which tends to be a deleted item as they tend to be listed together). When the file is written out, the 2 entries no longer have white space between them and the effect will cascade until the parser only sees a comment and will drop all the deleted items. The fix was simple enough. See commit "Stopped entire deleted entries being treated as comments in PO files."

Plural entries where not being un-escaped during parse, This was leading to text mangling in the po file on each load - save cycle, with an extra \ added to each escape each time. See Commit About Fixed translations on plural entries....

*About commit "Stopped NRE when PO Editor closed before being fully loaded"*

When the user opens a PO file, and proceeds to close it before MonoDevelop has finished its loading process, a NRE occurs. This didn't happen in MD 2.6. 

System.NullReferenceException: Object reference not set to an instance of an object
  at MonoDevelop.Ide.Gui.Workbench.OpenDocument (FilePath fileName, Int32 line, Int32 column, OpenDocumentOptions options, System.String encoding, IViewDisplayBinding binding) [0x00259] 
  in /home/garyb/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Workbench.cs:414 

This is caused by the line 

doc.RunWhenLoaded (() => doc.Window.SelectWindow ()); in Workbench.cs 

added on 29/08/11, in the commit titled "Fixed 'Bug 440 - Can't click buttons without clicking in the text". Wrapping this in a null check resolves the issue.