1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "EditLine.hxx"
26 #include <sal/types.h>
27 #include <tools/debug.hxx>
31 typedef std::vector
<std::unique_ptr
<EditLine
>> LinesType
;
35 EditLineList() = default;
37 void Reset() { maLines
.clear(); }
39 void DeleteFromLine(sal_Int32 nDelFrom
)
41 assert(nDelFrom
<= (static_cast<sal_Int32
>(maLines
.size()) - 1));
42 LinesType::iterator it
= maLines
.begin();
43 std::advance(it
, nDelFrom
);
44 maLines
.erase(it
, maLines
.end());
47 sal_Int32
FindLine(sal_Int32 nChar
, bool bInclEnd
)
49 sal_Int32 n
= maLines
.size();
50 for (sal_Int32 i
= 0; i
< n
; ++i
)
52 const EditLine
& rLine
= *maLines
[i
];
53 if ((bInclEnd
&& (rLine
.GetEnd() >= nChar
)) || (rLine
.GetEnd() > nChar
))
59 DBG_ASSERT(!bInclEnd
, "Line not found: FindLine");
63 sal_Int32
Count() const { return maLines
.size(); }
64 const EditLine
& operator[](sal_Int32 nPos
) const { return *maLines
[nPos
]; }
65 EditLine
& operator[](sal_Int32 nPos
) { return *maLines
[nPos
]; }
67 void Append(EditLine
* p
) { maLines
.push_back(std::unique_ptr
<EditLine
>(p
)); }
68 void Insert(sal_Int32 nPos
, EditLine
* p
)
70 maLines
.insert(maLines
.begin() + nPos
, std::unique_ptr
<EditLine
>(p
));
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */