]> git.lyx.org Git - lyx.git/blob - src/support/LSubstring.C
fixes because of SUN CC warnings, bmtable now compiled with C compilator, countChar...
[lyx.git] / src / support / LSubstring.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-1999 The LyX Team.
8  *
9  * ====================================================== */
10
11 #ifdef HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14
15 #include "LSubstring.h"
16
17
18 LSubstring::LSubstring(string & s, size_type i, size_type l)
19         : ps(&s), pos(i), n(l)
20 {
21 }
22
23
24 LSubstring::LSubstring(string & s, string const & s2)
25         : ps(&s), n(s2.length())
26 {
27         pos = s.find(s2);
28 }
29
30
31 LSubstring::LSubstring(string & s, string::value_type const * p)
32         : ps(&s)
33 {
34         n = strlen(p);
35         pos = s.find(p);
36 }
37
38
39 LSubstring::LSubstring(string & s, LRegex const & r)
40         : ps(&s)
41 {
42         LRegex::MatchPair res = r.first_match(s);
43         if (res.first != string::npos) {
44                 n = res.second;
45                 pos = res.first;
46         } else {
47                 n = 0;
48                 pos = 0;
49         }
50 }
51
52
53 LSubstring & LSubstring::operator=(string const & s)
54 {
55         ps->replace(pos, n, s); // write through to *ps
56         return *this;
57 }
58
59
60 LSubstring & LSubstring::operator=(LSubstring const & s)
61 {
62         ps->replace(pos, n, string(s, 0, string::npos));
63         return *this;
64 }
65
66
67 LSubstring & LSubstring::operator=(char const * p)
68 {
69         ps->replace(pos, n, p);
70         return *this;
71 }
72
73
74 LSubstring & LSubstring::operator=(char c)
75 {
76         ps->replace(pos, n, 1, c);
77         return *this;
78 }
79
80
81 LSubstring::operator string() const
82 {
83         return string(*ps, pos, n); // copy from *ps
84 }