]> git.lyx.org Git - lyx.git/blobdiff - src/support/lyxstring.C
Create a grfx::Loader class and so move large chunks of code out of
[lyx.git] / src / support / lyxstring.C
index 42a9811cf5ea0926c3bee88ab64aea9c5979efb5..c31fd08bde2d03098cb9151aeb569d498a18482e 100644 (file)
@@ -663,10 +663,13 @@ lyxstring & lyxstring::assign(const_iterator first, const_iterator last)
 lyxstring::const_reference lyxstring::operator[](size_type pos) const
 {
 #if 0
+       // This is actually what the standard requires,
        lyx::Assert(pos <= rep->sz); // OURS!
        static char helper = '\0';
        return pos == rep->sz ? helper : rep->s[pos];
 #else
+       // but we use this one since it is stricter
+       // and more according to the real intent of std::string.
        lyx::Assert(pos < rep->sz); // OURS!
        return rep->s[pos];
 #endif
@@ -1729,18 +1732,11 @@ void swap(lyxstring & str1, lyxstring & str2)
 
 #include <iostream>
 
+#if 0
 istream & operator>>(istream & is, lyxstring & s)
 {
-#if 1
-       // very bad solution
-       char * nome = new char[1024];
-       is >> nome;
-       lyxstring tmp(nome);
-       delete [] nome;
-       if (!tmp.empty()) s = tmp;
-#else
        // better solution
-       int w = is.widdth(0);
+       int w = is.width(0);
        s.clear();
        char c = 0;
        while (is.get(c)) {
@@ -1748,10 +1744,52 @@ istream & operator>>(istream & is, lyxstring & s)
                s += c;
                if (--w == 1) break;
        }
-       if (s.empty()) is.setstate(ios::failbit);
+       if (s.empty()) is.setstate(std::ios::failbit);
+       return is;
+}
+#else
+istream & operator>>(istream & is, lyxstring & str)
+{
+       typedef istream            istream_type;
+       typedef int         int_type;
+       typedef std::streambuf streambuf_type;
+       typedef string     string_type;
+       typedef string::size_type         size_type;
+       size_type extracted = 0;
+
+#if 0
+       istream_type::sentry cerb(is, false);
+       if (cerb) {
+#else
+               if (is.ipfx0()) {
+#endif
+               str.erase();
+               std::streamsize w = is.width();
+               size_type n;
+               n = w > 0 ? static_cast<size_type>(w) : str.max_size();
+
+               int_type const eof = EOF;
+               streambuf_type * sb = is.rdbuf();
+               int_type c = sb->sgetc();
+
+               while (extracted < n
+                      && c != eof && !isspace(c)) {
+                       str += c;
+                       ++extracted;
+                       c = sb->snextc();
+               }
+               if (c == eof)
+                       is.setstate(std::ios::eofbit);
+               is.width(0);
+       }
+#if 1
+       is.isfx();
 #endif
+       if (!extracted)
+               is.setstate(std::ios::failbit);
        return is;
 }
+#endif
 
 
 ostream & operator<<(ostream & o, lyxstring const & s)