]> git.lyx.org Git - lyx.git/blob - src/support/LSubstring.C
various changes
[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-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #ifdef HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "LSubstring.h"
20
21 #ifndef CXX_GLOBAL_CSTD
22 using std::strlen;
23 #endif
24
25
26
27 LSubstring::LSubstring(string & s, size_type i, size_type l)
28         : ps(&s), pos(i), n(l)
29 {
30 }
31
32
33 LSubstring::LSubstring(string & s, string const & s2)
34         : ps(&s), n(s2.length())
35 {
36         pos = s.find(s2);
37 }
38
39
40 LSubstring::LSubstring(string & s, string::value_type const * p)
41         : ps(&s)
42 {
43         n = strlen(p);
44         pos = s.find(p);
45 }
46
47
48 LSubstring::LSubstring(string & s, LRegex const & r)
49         : ps(&s)
50 {
51         LRegex::MatchPair const res = r.first_match(s);
52         if (res.first != string::npos) {
53                 n = res.second;
54                 pos = res.first;
55         } else {
56                 n = 0;
57                 pos = string::npos;
58         }
59 }
60
61
62 LSubstring & LSubstring::operator=(string const & s)
63 {
64         ps->replace(pos, n, s); // write through to *ps
65         return *this;
66 }
67
68
69 LSubstring & LSubstring::operator=(LSubstring const & s)
70 {
71         ps->replace(pos, n, s);
72         return *this;
73 }
74
75
76 LSubstring & LSubstring::operator=(string::value_type const * p)
77 {
78         ps->replace(pos, n, p);
79         return *this;
80 }
81
82
83 LSubstring & LSubstring::operator=(string::value_type c)
84 {
85         ps->replace(pos, n, 1, c);
86         return *this;
87 }
88
89
90 LSubstring::operator string() const
91 {
92         return string(*ps, pos, n); // copy from *ps
93 }