1 ///###////////////////////////////////////////////////////////////////////////
2 //
3 // Burton Computer Corporation
4 // http://www.burton-computer.com
5 // http://www.cooldevtools.com
6 // $Id: MultiLineSubString.cc 272 2007-01-06 19:37:27Z brian $
7 //
8 // Copyright (C) 2007 Burton Computer Corporation
9 // ALL RIGHTS RESERVED
10 //
11 // This program is open source software; you can redistribute it
12 // and/or modify it under the terms of the Q Public License (QPL)
13 // version 1.0. Use of this software in whole or in part, including
14 // linking it (modified or unmodified) into other programs is
15 // subject to the terms of the QPL.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 // Q Public License for more details.
21 //
22 // You should have received a copy of the Q Public License
23 // along with this program; see the file LICENSE.txt.  If not, visit
24 // the Burton Computer Corporation or CoolDevTools web site
25 // QPL pages at:
26 //
27 //    http://www.burton-computer.com/qpl.html
28 //    http://www.cooldevtools.com/qpl.html
29 //
30 
31 #include "MultiLineSubString.h"
32 
MultiLineSubString(const CRef<AbstractMultiLineString> & target,int start_index,int limit_index)33 MultiLineSubString::MultiLineSubString(const CRef<AbstractMultiLineString> &target,
34                                        int start_index,
35                                        int limit_index)
36 : m_target(target)
37 {
38   assert(m_target.isNotNull());
39   assert(start_index >= 0);
40   assert(limit_index >= 0);
41 
42   start_index = max(0, start_index);
43   limit_index = max(0, min(limit_index, m_target->lineCount()));
44 
45   if (m_target->lineCount() == 0 || start_index >= m_target->lineCount() || start_index >= limit_index) {
46     m_startIndex = m_target->lineCount(); // force out_of_range exception if ::line() called
47     m_length = 0;
48   } else {
49     m_startIndex = start_index;
50     m_length = limit_index - start_index;
51   }
52 
53   assert(m_startIndex >= 0);
54   assert(m_startIndex <= m_target->lineCount());
55   assert(m_length >= 0);
56   assert(m_length <= m_target->lineCount());
57 }
58 
~MultiLineSubString()59 MultiLineSubString::~MultiLineSubString()
60 {
61 }
62 
lineCount() const63 int MultiLineSubString::lineCount() const
64 {
65   return m_length;
66 }
67 
line(int index) const68 const string &MultiLineSubString::line(int index) const
69 {
70   assert(index >= 0);
71   assert(index < m_length);
72   return m_target->line(m_startIndex + index);
73 }
74 
75