[Aptitude-devel] r3022 - in branches/aptitude-0.3/aptitude: . src
Daniel Burrows
dburrows@costa.debian.org
Thu, 21 Apr 2005 02:40:31 +0000
Author: dburrows
Date: Thu Apr 21 02:40:28 2005
New Revision: 3022
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/desc_parse.cc
Log:
Refactor make_desc_fragment.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Thu Apr 21 02:40:28 2005
@@ -2,6 +2,12 @@
* src/desc_parse.cc:
+ Rework make_desc_fragment to add theoretical support for
+ indentation levels in the input description. No change should
+ occur in the resulting text as a result of this modification.
+
+ * src/desc_parse.cc:
+
Include comments on how lists ought to be handled, and hardwrap
preformatted lines as per Policy.
Modified: branches/aptitude-0.3/aptitude/src/desc_parse.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/desc_parse.cc (original)
+++ branches/aptitude-0.3/aptitude/src/desc_parse.cc Thu Apr 21 02:40:28 2005
@@ -26,30 +26,38 @@
// frontend may render them literally or modify their appearence as it
// deems appropriate.
-fragment *make_desc_fragment(string desc)
+/** Scans for text at a single indent level and returns a fragment
+ * corresponding to it.
+ *
+ * \param desc the string from which the description should be built.
+ * \param indent the number of spaces to strip from the left-hand
+ * side of each line. If a line with less than this many spaces is
+ * encountered, start is placed at the beginning of the line and we
+ * return.
+ *
+ * \param start the current location in the string; will be updated
+ * to reflect how many characters were consumed.
+ */
+static fragment *make_level_fragment(string desc,
+ string::size_type indent,
+ string::size_type &start)
{
- string::size_type loc=0;
vector<fragment*> fragments;
- // Skip the short description
- while(loc<desc.size() && desc[loc]!='\n')
- ++loc;
+ while(start<desc.size())
+ {
+ string::size_type loc=start;
+ unsigned int nspaces=0;
- if(loc<desc.size()) // Skip the '\n'
- ++loc;
+ while(loc<desc.size() && desc[loc]==' ' && nspaces<indent)
+ {
+ ++loc;
+ ++nspaces;
+ }
- while(loc<desc.size())
- {
- // We're at the beginning of a line here.
- //
- // Find out what type of line it is first. (be liberal -- lines
- // not starting with ' ' are formatted as part of the current
- // paragraph)
- if(desc[loc]==' ')
- ++loc;
+ if(nspaces<indent)
+ break;
- // Now check whether it's part of a paragraph, a blank line,
- // or a preformatted line.
switch(desc[loc])
{
case ' ':
@@ -66,10 +74,12 @@
loc+=amt;
if(loc<desc.size())
++loc;
+
+ start=loc;
break;
}
case '.':
- // blank.
+ // Add a blank line (ignore the rest of the line)
{
fragments.push_back(newline_fragment());
@@ -78,6 +88,8 @@
if(loc<desc.size())
++loc;
+
+ start=loc;
break;
}
default:
@@ -105,16 +117,26 @@
if(loc<desc.size())
++loc;
- // Use 'loc+1' here because we have to preserve the
- // leading ' ' if we're exiting the loop. This means
- // that packages whose descriptions end with '\nX'
- // where X!=' ' will be displayed oddly, but such
- // descriptions are noncompliant anyway.
- if(!(loc+1<desc.size() && desc[loc+1]!=' ' && desc[loc+1]!='.'))
+ // Update start.
+ start=loc;
+
+ // Find how much indentation this line has.
+ nspaces=0;
+ while(loc<desc.size() && desc[loc]==' ')
+ {
+ ++loc;
+ ++nspaces;
+ }
+
+ // Check if we should continue (if not, we back up and
+ // start parsing again from "start")
+ if(nspaces<indent)
cont=false;
- else
- ++loc;
- } while(cont && loc+1<desc.size());
+ else if(loc>=desc.size())
+ cont=false;
+ else if(desc[loc]=='.')
+ cont=false;
+ } while(cont);
fragments.push_back(wrapbox(text_fragment(par)));
}
@@ -123,3 +145,19 @@
return sequence_fragment(fragments);
}
+
+fragment *make_desc_fragment(string desc)
+{
+ string::size_type loc=0;
+ vector<fragment*> fragments;
+
+ // Skip the short description
+ while(loc<desc.size() && desc[loc]!='\n')
+ ++loc;
+
+ if(loc<desc.size()) // Skip the '\n'
+ ++loc;
+
+ // Note that the starting indentation level is 1...
+ return make_level_fragment(desc, 1, loc);
+}