]> git.lyx.org Git - features.git/blobdiff - src/lyxfind.cpp
Findadv: Handle \lettrine{} in initials.module
[features.git] / src / lyxfind.cpp
index 6a4329aed0e7c13561653a1002c8473e9474b4d0..00905d839138bf598187105fd403fd53b6495071 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;
@@ -1037,17 +1037,28 @@ class KeyInfo {
     /* item */
     isList,
     /* tex, latex, ... like isChar */
-    isIgnored
+    isIgnored,
+    /* like \lettrine[lines=5]{}{} */
+    cleanToStart,
+    endArguments
   };
  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) {};
@@ -1073,7 +1084,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];
@@ -1255,7 +1269,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>();
@@ -1343,16 +1357,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())) {
@@ -1754,7 +1758,8 @@ void LatexInfo::buildKeys(bool isPatternString)
   makeKey("par|uldepth|ULdepth|protect|nobreakdash", KeyInfo(KeyInfo::isStandard, 0, true), isPatternString);
   // Remove RTL/LTR marker
   makeKey("l|r|textlr|textfr|textar|beginl|endl", KeyInfo(KeyInfo::isStandard, 0, true), isPatternString);
-
+  makeKey("lettrine", KeyInfo(KeyInfo::cleanToStart, 0, true), isPatternString);
+  makeKey("endarguments", KeyInfo(KeyInfo::endArguments, 0, true), isPatternString);
   if (isPatternString) {
     // Allow the first searched string to rebuild the keys too
     keysBuilt = false;
@@ -1826,8 +1831,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
@@ -1890,6 +1895,35 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual)
   int nextKeyIdx = 0;
   switch (actual.keytype)
   {
+    case KeyInfo::cleanToStart: {
+      actual._dataEnd = actual._dataStart;
+      if (interval.par[actual._dataStart] == '[') {
+        // Discard optional params
+        actual._dataStart = interval.findclosing(actual._dataStart+1, interval.par.length(), '[', ']') + 1;
+      }
+      actual._dataEnd = actual._dataStart;
+      nextKeyIdx = getNextKey();
+      // Search for end of arguments
+      int tmpIdx = nextKeyIdx;
+      while (tmpIdx > 0) {
+        KeyInfo &nextk = entries[tmpIdx];
+        if (nextk.keytype == KeyInfo::endArguments) {
+          actual._dataEnd = nextk._dataEnd;
+          break;
+        }
+        nextk.disabled = true;
+        tmpIdx++;
+        if (tmpIdx >= int(entries.size()))
+          break;
+      }
+      while (interval.par[actual._dataEnd] == ' ')
+        actual._dataEnd++;
+      interval.addIntervall(0, actual._dataEnd+1);
+      interval.actualdeptindex = 0;
+      interval.depts[0] = actual._dataEnd+1;
+      interval.closes[0] = -1;
+      break;
+    }
     case KeyInfo::noContent: {          /* char like "\hspace{2cm}" */
       interval.addIntervall(actual._dataStart, actual._dataEnd);
     }
@@ -1899,17 +1933,23 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual)
       break;
     }
     case KeyInfo::isSize: {
-      if (actual.disabled || (interval.par[actual._dataStart] != '{')) {
+      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 {
-        // Determine the end if used like '{\tiny{}...}'
-        if (interval.par[actual._dataStart+1] == '}') {
-          actual._dataStart += 1;
-          interval.addIntervall(actual._dataStart, actual._dataStart+1);
+        // 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;
-          actual.parenthesiscount = 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);
@@ -1922,6 +1962,11 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual)
       }
       break;
     }
+    case KeyInfo::endArguments:
+      removeHead(actual);
+      processRegion(actual._dataStart, actual._dataStart+1);
+      nextKeyIdx = getNextKey();
+      break;
     case KeyInfo::noMain:
       // fall through
     case KeyInfo::isStandard: {