- if (pos < size()) {
- return text[pos];
- }
- /* > because last is the next unused position, and you can
- * use it if you want */
- else if (pos > size()) {
- if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
- return NextAfterFootnote()
- ->GetChar(pos - text.size() - 1);
- else {
- lyxerr << "ERROR (LyXParagraph::GetChar): "
- "position does not exist."
- << pos << " (" << static_cast<int>(pos)
- << ")\n";
- }
- return '\0';
- } else {
- /* we should have a footnote environment */
- if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
- // Notice that LyX does request the
- // last char from time to time. (Asger)
- //lyxerr << "ERROR (LyXParagraph::GetChar): "
- // "expected footnote." << endl;
- return '\0';
- }
- switch (next->footnotekind) {
- case LyXParagraph::FOOTNOTE:
- return LyXParagraph::META_FOOTNOTE;
- case LyXParagraph::MARGIN:
- return LyXParagraph::META_MARGIN;
- case LyXParagraph::FIG:
- case LyXParagraph::WIDE_FIG:
- return LyXParagraph::META_FIG;
- case LyXParagraph::TAB:
- case LyXParagraph::WIDE_TAB:
- return LyXParagraph::META_TAB;
- case LyXParagraph::ALGORITHM:
- return LyXParagraph::META_ALGORITHM;
- }
- return '\0'; // to shut up gcc
- }
-}
-
-
-char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
-{
-#ifdef DEVEL_VERSION
- /* a workaround to 'fix' some bugs in text-class */
- if (pos < 0) {
- // This function is important. It should not work around bugs.
- // Let's find the bugs instead and fix them. (Asger)
- lyxerr << "FATAL ERROR (LyXParagraph::GetChar):"
- " bad position " << pos << endl;
- abort();
- }
-#endif
-
- if (pos < size()) {
- return text[pos];
- }
- /* > because last is the next unused position, and you can
- * use it if you want */
- else if (pos > size()) {
- if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
- return NextAfterFootnote()
- ->GetChar(pos - text.size() - 1);
- else {
- lyxerr << "ERROR (LyXParagraph::GetChar): "
- "position does not exist."
- << pos << " (" << static_cast<int>(pos)
- << ")\n";
- }
- return '\0';
- } else {
- /* we should have a footnote environment */
- if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
- // Notice that LyX does request the
- // last char from time to time. (Asger)
- //lyxerr << "ERROR (LyXParagraph::GetChar): "
- // "expected footnote." << endl;
- return '\0';
- }
- switch (next->footnotekind) {
- case LyXParagraph::FOOTNOTE:
- return LyXParagraph::META_FOOTNOTE;
- case LyXParagraph::MARGIN:
- return LyXParagraph::META_MARGIN;
- case LyXParagraph::FIG:
- case LyXParagraph::WIDE_FIG:
- return LyXParagraph::META_FIG;
- case LyXParagraph::TAB:
- case LyXParagraph::WIDE_TAB:
- return LyXParagraph::META_TAB;
- case LyXParagraph::ALGORITHM:
- return LyXParagraph::META_ALGORITHM;
- }
- return '\0'; // to shut up gcc
- }
-}
-
-
-string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
- //Added 98/9/21 by REH
- // return an string of the current word, and the end of the word
- // in lastpos.
-
- // the current word is defined as starting at the first character from
- // the immediate left of lastpospos which meets the definition of IsLetter(),
- // continuing to the last character to the right of this meeting
- // IsLetter.
-
-
- // i just left this in from GetChar()
-{
-#ifdef DEVEL_VERSION
- /* a workaround to 'fix' some bugs in text-class */
- if (lastpos < 0) {
- // This function is important. It should not work around bugs.
- // Let's find the bugs instead and fix them. (Asger)
- lyxerr << "FATAL ERROR (LyXParagraph::GetWord):"
- " bad position " << lastpos << endl;
- abort();
- }
-#endif
-
- string theword;
-
- // grab a word
-
-
- //i think the devcode aborts before this, but why not be
- // versatile?
- if (lastpos < 0) lastpos= 0;
-
-
- // move back until we have a letter
-
- //there's no real reason to have firstpos & lastpos as
- //separate variables as this is written, but maybe someon
- // will want to return firstpos in the future.
-
- //since someone might have typed a punctuation first
- int firstpos = lastpos;
-
- while ((firstpos >= 0) && !IsLetter(firstpos))
- firstpos--;
-
- // now find the beginning by looking for a nonletter
-
- while ((firstpos>= 0) && IsLetter(firstpos))
- firstpos--;
-
- // the above is now pointing to the preceeding non-letter
- firstpos++;
- lastpos= firstpos;
-
- // so copy characters into theword until we get a nonletter
- // note that this can easily exceed lastpos, wich means
- // that if used in the middle of a word, the whole word
- // is included
-
- while (IsLetter(lastpos)) theword += GetChar(lastpos++);
-
- return theword;
-
-}
-
-
-LyXParagraph::size_type LyXParagraph::Last() const
-{
- if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
- return text.size() + NextAfterFootnote()->Last() + 1;
- /* the 1 is the symbol
- for the footnote */
- else
- return text.size();
-}
-
-
-LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
-{
- /* > because last is the next unused position, and you can
- * use it if you want */
- if (pos > size()) {
- if (next
- && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
- return NextAfterFootnote()
- ->ParFromPos(pos - text.size() - 1);
- else
- lyxerr << "ERROR (LyXParagraph::ParFromPos): "
- "position does not exist." << endl;
- return this;
- }
- else
- return this;
-}
-
-
-int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
-{
- /* > because last is the next unused position, and you can
- * use it if you want */
- if (pos > size()) {
- if (next
- && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
- return NextAfterFootnote()
- ->PositionInParFromPos(pos - text.size() - 1);
- else
- lyxerr <<
- "ERROR (LyXParagraph::PositionInParFromPos): "
- "position does not exist." << endl;
- return pos;