[PATCH] Gettext save: be sure that comment lines start with #

Nicolas Goutte <[email protected]> Fri, 28 Oct 2005 19:58:16 +0200
Newsgroups gmane.comp.kde.devel.kbabel
Message-ID <[email protected]>
The attached patch is for kdesdk/kbabel/filters/gettext/gettextexport.cpp 

The change makes sure that, while saving Gettext, each comment line starts 
with a #, even if the user has not taken care about it.

(I do not thing that this bug was reported to KDE Bugs, but I have seen one 
files in SVN where I think that it could have been the problem.)

Have a nice day!

_______________________________________________
kbabel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kbabel
gettext_comment.diff (text/x-diff, 1.1 KB)
Index: gettextexport.cpp
===================================================================
--- gettextexport.cpp	(Revision 475265)
+++ gettextexport.cpp	(Arbeitskopie)
@@ -158,10 +158,23 @@
 	  }
 	  
 	  // write entry
-	  QString comment = catalog->comment(counter);
+	  const QString comment = catalog->comment(counter);
 	  if(!comment.isEmpty())
 	  {
-	      stream << comment << "\n";
+              // We must check that each comment line really starts with a #, to avoid syntax errors
+              uint pos = 0;
+              for(;;)
+              {
+                  const int newpos = comment.find( '\n', pos, false );
+                  const QString span ( ( newpos == -1 ) ? comment.mid( pos ) : comment.mid( pos, newpos-pos ) );
+                  if ( span[0] != '#' )
+                      stream << "# ";
+                  stream << span << "\n";
+                  if ( newpos == -1 )
+                      break;
+                  else
+                      pos = newpos + 1;
+              }
 	  }
 
 	  if(!catalog->msgctxt(counter).isEmpty())