]> git.lyx.org Git - features.git/commitdiff
Fix lyxstring::rfind
authorDekel Tsur <dekelts@tau.ac.il>
Sat, 20 Jan 2001 15:37:54 +0000 (15:37 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Sat, 20 Jan 2001 15:37:54 +0000 (15:37 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1355 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/languages
src/support/ChangeLog
src/support/lyxstring.C

index ca346dbaf8a2be8b91fd71f588655b49d6d1954c..1a137b5fb7f5d06be8f247f7ddbbfe6ef6f1a2a3 100644 (file)
@@ -1,5 +1,6 @@
 2001-01-20  Dekel Tsur  <dekelts@tau.ac.il>
 
-       * languages: Add extra_options field.
-
+       * languages: Add extra_options field. It is used to fix the ~n
+        problem with Spanish.
+       
 
index 15095b328e37fe4d507a8dd98e103cd0c7c5d165..6f5c099428ab361f3352c51167d9fd1c1deec350 100644 (file)
@@ -39,7 +39,7 @@ polish      polish    "Polish"        false  iso8859-2  pl     ""
 portuges    portuges   "Portuges"      false  iso8859-1  pt     ""
 romanian    romanian   "Romanian"      false  iso8859-2  ro     ""
 russian     russian    "Russian"       false  koi8       ru     ""
-scottish    scottish   "Scottish"      false  iso8859-1  gd_GB  "
+scottish    scottish   "Scottish"      false  iso8859-1  gd_GB  ""
 spanish     spanish    "Spanish"       false  iso8859-1  es     "\addto\extrasspanish{\bbl@deactivate{~}}"
 slovak      slovak     "Slovak"        false  iso8859-2  sk_SL  ""
 slovene     slovene    "Slovene"       false  iso8859-2  sl_SI  ""
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..4bf2aec6879128f17e0e904da9f038c1ec6e42d2 100644 (file)
@@ -0,0 +1,4 @@
+2001-01-20  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * lyxstring.C (rfind): Fix broken functions.
+       (find): Few optimizations.
index 515e90533b9b18905d9f69ec9a82b8599f8cf15b..ff25d6fba9060330e9e037e858d805578b629a7e 100644 (file)
@@ -888,12 +888,14 @@ lyxstring::size_type lyxstring::find(lyxstring const & a, size_type i) const
        
        TestlyxstringInvariant(this);
 
-       for (size_type t = i; rep->sz - t >= a.length(); ++t) {
+       size_type n = a.length();
+       if (!n) return npos;
+       for (size_type t = i; rep->sz - t >= n; ++t) {
                // search until (*this)[i] == a[0]
                if (rep->s[t] == a[0]) {
                        // check if the rest of the value_types match
                        bool equal = true;
-                       for (size_type j = 0; j < a.length(); ++j) {
+                       for (size_type j = 1; j < n; ++j) {
                                if (rep->s[t + j] != a[j]) {
                                        equal = false;
                                        break;
@@ -919,12 +921,13 @@ lyxstring::size_type lyxstring::find(value_type const * ptr, size_type i,
        // for ptr in? For now I will assume that "n" tells the length
        // of ptr. (Lgb)
        n = min(n, strlen(ptr));
+       if (!n) return npos;
        for (size_type t = i; rep->sz - t >= n; ++t) {
                // search until (*this)[i] == a[0]
                if (rep->s[t] == ptr[0]) {
                        // check if the rest of the value_types match
                        bool equal = true;
-                       for (size_type j = 0; j < n; ++j) {
+                       for (size_type j = 1; j < n; ++j) {
                                if (rep->s[t + j] != ptr[j]) {
                                        equal = false;
                                        break;
@@ -966,17 +969,24 @@ lyxstring::size_type lyxstring::rfind(lyxstring const & a, size_type i) const
 {
        TestlyxstringInvariant(this);
 
-       size_type ii = min(rep->sz - 1, i);
+       size_type n = a.length();
+       if (!n || rep->sz < n)
+               return npos;
+
+       size_type t = min(rep->sz - n, i);
        do {
-               if (a[a.length() - 1] == rep->s[ii]) {
-                       int t = rep->sz - 2;
-                       size_type l = ii - 1;
-                       for (; t >= 0; --t, --l) {
-                               if (a[t] != rep->s[l]) break;
+               if (rep->s[t] == a[0]) {
+                       // check if the rest of the value_types match
+                       bool equal = true;
+                       for (size_type j = 1; j < n; ++j) {
+                               if (rep->s[t + j] != a[j]) {
+                                       equal = false;
+                                       break;
+                               }
                        }
-                       if (a[t] == rep->s[l]) return l;
+                       if (equal) return t;
                }
-       } while(ii-- > 0);
+       } while(t-- > 0);
        return npos;
 }
 
@@ -986,19 +996,25 @@ lyxstring::size_type lyxstring::rfind(value_type const * ptr, size_type i,
 {
        Assert(ptr); // OURS!
        TestlyxstringInvariant(this);
-       if (!*ptr) return npos;
 
-       size_type ii = min(rep->sz - 1, i);
+       n = min(n, strlen(ptr));
+       if (!n || rep->sz < n)
+               return npos;
+
+       size_type t = min(rep->sz - n, i);
        do {
-               if (ptr[n - 1] == rep->s[ii]) {
-                       int t = n - 2;
-                       size_type l = ii - 1;
-                       for (; t >= 0; --t, --l) {
-                               if (ptr[t] != rep->s[l]) break;
+               if (rep->s[t] == ptr[0]) {
+                       // check if the rest of the value_types match
+                       bool equal = true;
+                       for (size_type j = 1; j < n; ++j) {
+                               if (rep->s[t + j] != ptr[j]) {
+                                       equal = false;
+                                       break;
+                               }
                        }
-                       if (ptr[t] == rep->s[l]) return l;
+                       if (equal) return t;
                }
-       } while (ii-- > 0);
+       } while (t-- > 0);
        return npos;
 }
 
@@ -1007,21 +1023,9 @@ lyxstring::size_type lyxstring::rfind(value_type const * ptr,
                                      size_type i) const
 {
        Assert(ptr); // OURS!
-       TestlyxstringInvariant(this);
-       if (!*ptr) return npos;
 
-       size_type ii = min(rep->sz - 1, i);
-       do {
-               if (ptr[strlen(ptr) - 1] == rep->s[ii]) {
-                       int t = strlen(ptr) - 2;
-                       size_type l = ii - 1;
-                       for (; t >= 0; --t, --l) {
-                               if (ptr[t] != rep->s[l]) break;
-                       }
-                       if (ptr[t] == rep->s[l]) return l;
-               }
-       } while (ii-- > 0);
-       return npos;
+       if (!ptr || !*ptr) return npos;
+       return rfind(ptr, i, strlen(ptr));
 }
 
 
@@ -1755,3 +1759,12 @@ istream & getline(istream & is, lyxstring & s,
        }
        return is;
 }
+
+#ifdef TEST_MAIN
+int main() {
+       lyxstring a = "abcac";
+       cout << a.rfind("ab") << endl;
+       cout << a.rfind("c") << endl;
+       cout << a.rfind("d") << endl;
+}
+#endif