And with the ostream versions this would've been:

+ 
+string const LyXText::selectionAsStringWithLabels(Buffer const * buffer) const
+{
+       if (!selection.set()) return string();
+       string result;
+       
+       // Special handling if the whole selection is within one paragraph
+       if (selection.start.par() == selection.end.par()) {
+               result += selection.start.par()->StringWithLabels(buffer,
+                                                selection.start.pos(),
+                                                selection.end.pos());
+               return result;
+       }
+       
+       // The selection spans more than one paragraph
+
+       // First paragraph in selection
+       result += selection.start.par()->StringWithLabels(buffer,
+                                                selection.start.pos(),
+                                                selection.start.par()->size())
+               + "\n\n";
+       
+       // The paragraphs in between (if any)
+       LyXCursor tmpcur(selection.start);
+       tmpcur.par(tmpcur.par()->next());
+       while (tmpcur.par() != selection.end.par()) {
+               result += tmpcur.par()->StringWithLabels(buffer, 0, 
+                       tmpcur.par()->size()) + "\n\n";
+               tmpcur.par(tmpcur.par()->next()); // Or NextAfterFootnote??
+       }
+
+       // Last paragraph in selection
+       result += selection.end.par()->StringWithLabels(buffer, 0, 
+selection.end.pos());
+       
+       return result;
+}


this:


string const LyXText::selectionAsStringWithLabels(Buffer const * buffer) const
{
        if (!selection.set()) return string();

        std::ostringstream ost;
        
        // Special handling if the whole selection is within one paragraph
        if (selection.start.par() == selection.end.par()) {
                selection.start.par()->StringWithLabels(buffer,
                                                ost,
                                                selection.start.pos(),
                                                selection.end.pos());
                return ost.str().c_str();
        }
        
        // The selection spans more than one paragraph

        // First paragraph in selection
        selection.start.par()->StringWithLabels(buffer,
                                        ost,
                                        selection.start.pos(),
                                        selection.start.par()->size());
        ost << "\n\n";
        
        // The paragraphs in between (if any)
        LyXCursor tmpcur(selection.start);
        tmpcur.par(tmpcur.par()->next());
        while (tmpcur.par() != selection.end.par()) {
                tmpcur.par()->StringWithLabels(buffer, ost, 0, 
                        tmpcur.par()->size());
                ost << "\n\n";
                tmpcur.par(tmpcur.par()->next()); // Or NextAfterFootnote??
        }

        // Last paragraph in selection
        selection.end.par()->StringWithLabels(buffer, ost,
                                        0, selection.end.pos());
        
        return ost.str().c_str();
}
  

This makes the binary quite a bit smaller as well I think...

-- 
        Lgb

Reply via email to