]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
Beamer: autonest column in columns
[lyx.git] / src / lyxfind.cpp
index f4b3858df48f4fc81c589dee0120910a161da16a..6d5abe78814df15e9586c5c1c24dc96c504e8b52 100644 (file)
@@ -951,7 +951,7 @@ static size_t identifyLeading(string const & s)
        // @TODO Support \item[text]
        // Kornel: Added textsl, textsf, textit, texttt and noun
        // + allow to search for colored text too
-       while (regex_replace(t, t, REGEX_BOS "\\\\(((emph|noun|minisec|text(bf|md|sl|sf|it|tt))|((textcolor|foreignlanguage)\\{[a-z]+\\})|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)\\{", "")
+       while (regex_replace(t, t, REGEX_BOS "\\\\(((footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge|emph|noun|minisec|text(bf|md|sl|sf|it|tt))|((textcolor|foreignlanguage)\\{[a-z]+\\})|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)\\{", "")
               || regex_replace(t, t, REGEX_BOS "\\$", "")
               || regex_replace(t, t, REGEX_BOS "\\\\\\[ ", "")
               || regex_replace(t, t, REGEX_BOS " ?\\\\item\\{[a-z]+\\}", "")
@@ -973,7 +973,7 @@ typedef map<string, bool> Features;
 static Features identifyFeatures(string const & s)
 {
        static regex const feature("\\\\(([a-z]+(\\{([a-z]+)\\}|\\*)?))\\{");
-       static regex const valid("^(((emph|noun|text(bf|md|sl|sf|it|tt)|(textcolor|foreignlanguage|item)\\{[a-z]+\\})|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)$");
+       static regex const valid("^(((footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge|emph|noun|text(bf|md|sl|sf|it|tt)|(textcolor|foreignlanguage|item)\\{[a-z]+\\})|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)$");
        smatch sub;
        bool displ = true;
        Features info;
@@ -1010,29 +1010,52 @@ static Features identifyFeatures(string const & s)
 class KeyInfo {
  public:
   enum KeyType {
+    /* Char type with content discarded
+     * like \hspace{1cm} */
+    noContent,
+    /* Char, like \backslash */
     isChar,
+    /* \part, \section*, ... */
     isSectioning,
-    isMain,                             /* for \\foreignlanguage */
-    noMain,                             /* to discard language in content */
+    /* \foreignlanguage{ngerman}, ... */
+    isMain,
+    /* inside \code{} or \footnote{}
+     * to discard language in content */
+    noMain,
     isRegex,
+    /* \begin{eqnarray}...\end{eqnarray}, ... $...$ */
     isMath,
+    /* fonts, colors, markups, ... */
     isStandard,
-    noContent,                          /* discard content */
+    /* footnotesize, ... large, ...
+     * Ignore all of them */
     isSize,
     invalid,
+    /* inputencoding, shortcut, ...
+     * Discard also content, because they do not help in search */
     doRemove,
+    /* item */
     isList,
-    isIgnored                           /* to be ignored by creating infos */
+    /* tex, latex, ... like isChar */
+    isIgnored
   };
  KeyInfo()
    : keytype(invalid),
     head(""),
+    _tokensize(-1),
+    _tokenstart(-1),
+    _dataStart(-1),
+    _dataEnd(-1),
     parenthesiscount(1),
     disabled(false),
     used(false)
   {};
  KeyInfo(KeyType type, int parcount, bool disable)
    : keytype(type),
+    _tokensize(-1),
+    _tokenstart(-1),
+    _dataStart(-1),
+    _dataEnd(-1),
     parenthesiscount(parcount),
     disabled(disable),
     used(false) {};
@@ -1058,7 +1081,10 @@ class Border {
 class Intervall {
   bool isPatternString;
  public:
- Intervall(bool isPattern) : isPatternString(isPattern), ignoreidx(-1), actualdeptindex(0) { depts[0] = 0;};
+ explicit Intervall(bool isPattern) :
+  isPatternString(isPattern),
+    ignoreidx(-1),
+    actualdeptindex(0) { depts[0] = 0; closes[0] = 0;};
   string par;
   int ignoreidx;
   int depts[MAXOPENED];
@@ -1240,7 +1266,7 @@ class LatexInfo {
   void removeHead(KeyInfo&, int count=0);
 
  public:
- LatexInfo(string par, bool isPatternString) : interval(isPatternString) {
+ LatexInfo(string par, bool isPatternString) : entidx(-1), interval(isPatternString) {
     interval.par = par;
     buildKeys(isPatternString);
     entries = vector<KeyInfo>();
@@ -1328,16 +1354,6 @@ class MathInfo {
     m.mathSize = end - start;
     entries.push_back(m);
   }
-  bool evaluating(size_t pos) {
-    while (actualIdx < entries.size()) {
-      if (pos < entries[actualIdx].mathStart)
-        return false;
-      if (pos < entries[actualIdx].mathEnd)
-        return true;
-      actualIdx++;
-    }
-    return false;
-  }
   bool empty() { return entries.empty(); };
   size_t getEndPos() {
     if (entries.empty() || (actualIdx >= entries.size())) {
@@ -1571,7 +1587,8 @@ void LatexInfo::buildEntries(bool isPatternString)
       found._tokenstart = sub.position(size_t(0));
       if (found.parenthesiscount == 0) {
         // Probably to be discarded
-        char following = interval.par[sub.position(size_t(0)) + sub.str(3).length() + 1];
+        size_t following_pos = sub.position(size_t(0)) + sub.str(3).length() + 1;
+        char following = interval.par[following_pos];
         if (following == ' ')
           found.head = "\\" + sub.str(3) + " ";
         else if (following == '=') {
@@ -1626,9 +1643,9 @@ void LatexInfo::buildEntries(bool isPatternString)
         }
         else
           found._dataEnd = endpos;
-        if (isPatternString) {
-          keys[key].used = true;
-        }
+      }
+      if (isPatternString) {
+        keys[key].used = true;
       }
     }
     entries.push_back(found);
@@ -1725,7 +1742,7 @@ void LatexInfo::buildKeys(bool isPatternString)
   makeKey("triangleuppar|triangledownpar|droppar", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
   makeKey("triangleleftpar|shapepar|dropuppar",    KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
   // like ('tiny{}' or '\tiny ' ... )
-  makeKey("footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge", KeyInfo(KeyInfo::isSize, 0, true), isPatternString);
+  makeKey("footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge", KeyInfo(KeyInfo::isSize, 0, false), isPatternString);
 
   // Survives, like known character
   makeKey("lyx|latex|latexe|tex", KeyInfo(KeyInfo::isIgnored, 0, false), isPatternString);
@@ -1810,8 +1827,8 @@ void Intervall::output(ostringstream &os, int lastpos)
   int i = 0;
   for (idx = 0; idx <= ignoreidx; idx++) {
     if (i < lastpos) {
-      int printsize;
       if (i <= borders[idx].low) {
+        int printsize;
         if (borders[idx].low > lastpos)
           printsize = lastpos - i;
         else
@@ -1874,17 +1891,33 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual)
   int nextKeyIdx = 0;
   switch (actual.keytype)
   {
+    case KeyInfo::noContent: {          /* char like "\hspace{2cm}" */
+      interval.addIntervall(actual._dataStart, actual._dataEnd);
+    }
+      // fall through
     case KeyInfo::isChar: {
       nextKeyIdx = getNextKey();
       break;
     }
     case KeyInfo::isSize: {
-      if (actual.disabled) {
-        // Allways disabled
+      if (actual.disabled || (interval.par[actual._dataStart] != '{') || (interval.par[actual._dataStart-1] == ' ')) {
         processRegion(actual._dataEnd, actual._dataEnd+1); /* remove possibly following {} */
         interval.addIntervall(actual._tokenstart, actual._dataEnd+1);
         nextKeyIdx = getNextKey();
       } else {
+        // Here _dataStart points to '{', so correct it
+        actual._dataStart += 1;
+        actual._tokensize += 1;
+        actual.parenthesiscount = 1;
+        if (interval.par[actual._dataStart] == '}') {
+          // Determine the end if used like '{\tiny{}...}'
+          actual._dataEnd = interval.findclosing(actual._dataStart+1, interval.par.length()) + 1;
+          interval.addIntervall(actual._dataStart, actual._dataStart+1);
+        }
+        else {
+          // Determine the end if used like '\tiny{...}'
+          actual._dataEnd = interval.findclosing(actual._dataStart, interval.par.length()) + 1;
+        }
         // Split on this key if not at start
         int start = interval.nextNotIgnored(previousStart);
         if (start < actual._tokenstart) {
@@ -1896,10 +1929,6 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual)
       }
       break;
     }
-    case KeyInfo::noContent: {
-      interval.addIntervall(actual._dataStart, actual._dataEnd);
-    }
-      // fall through
     case KeyInfo::noMain:
       // fall through
     case KeyInfo::isStandard: {
@@ -2081,7 +2110,15 @@ int LatexInfo::process(ostringstream &os, KeyInfo &actual )
   if ((actual.keytype == KeyInfo::isMain) && actual.disabled) {
     interval.addIntervall(actual._tokenstart, actual._tokenstart+actual._tokensize);
   }
-  if (interval.nextNotIgnored(actual._dataStart) < output_end)
+  // Remove possible empty data
+  int dstart = interval.nextNotIgnored(actual._dataStart);
+  while ((dstart < output_end) && (interval.par[dstart] == '{')) {
+    interval.addIntervall(dstart, dstart+1);
+    int dend = interval.findclosing(dstart+1, output_end);
+    interval.addIntervall(dend, dend+1);
+    dstart = interval.nextNotIgnored(dstart+1);
+  }
+  if (dstart < output_end)
     interval.output(os, output_end);
   interval.addIntervall(actual._tokenstart, end);
   return nextKeyIdx;