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/.
10 #include <oox/ppt/comments.hxx>
11 #include <com/sun/star/lang/IllegalArgumentException.hpp>
13 #include <rtl/math.hxx>
14 #include <o3tl/safeint.hxx>
15 #include <o3tl/string_view.hxx>
19 void CommentAuthorList::setValues(const CommentAuthorList
& list
)
21 for (auto const& author
: list
.cmAuthorLst
)
23 CommentAuthor commentAuthor
;
24 commentAuthor
.clrIdx
= author
.clrIdx
;
25 commentAuthor
.id
= author
.id
;
26 commentAuthor
.initials
= author
.initials
;
27 commentAuthor
.lastIdx
= author
.lastIdx
;
28 commentAuthor
.name
= author
.name
;
29 cmAuthorLst
.push_back(commentAuthor
);
33 //DateTime is saved as : 2013-01-10T15:53:26.000
34 void Comment::setDateTime(const OUString
& sDateTime
)
37 aDateTime
.Year
= o3tl::toInt32(o3tl::getToken(sDateTime
, 0, '-', nIdx
));
38 aDateTime
.Month
= o3tl::toUInt32(o3tl::getToken(sDateTime
, 0, '-', nIdx
));
39 aDateTime
.Day
= o3tl::toUInt32(o3tl::getToken(sDateTime
, 0, 'T', nIdx
));
40 aDateTime
.Hours
= o3tl::toUInt32(o3tl::getToken(sDateTime
, 0, ':', nIdx
));
41 aDateTime
.Minutes
= o3tl::toUInt32(o3tl::getToken(sDateTime
, 0, ':', nIdx
));
42 double seconds
= rtl_math_uStringToDouble(sDateTime
.getStr() + nIdx
,
43 sDateTime
.getStr() + sDateTime
.getLength(), '.', 0,
45 aDateTime
.Seconds
= floor(seconds
);
46 seconds
-= aDateTime
.Seconds
;
47 aDateTime
.NanoSeconds
= ::rtl::math::round(seconds
* 1000000000);
48 const int secondsOverflow
= (aDateTime
.Seconds
== 60) ? 61 : 60;
49 // normalise time part of aDateTime
50 if (aDateTime
.NanoSeconds
== 1000000000)
52 aDateTime
.NanoSeconds
= 0;
55 if (aDateTime
.Seconds
== secondsOverflow
)
57 aDateTime
.Seconds
= 0;
60 if (aDateTime
.Minutes
== 60)
62 aDateTime
.Minutes
= 0;
65 // if overflow goes into date, I give up
68 OUString
Comment::getAuthor(const CommentAuthorList
& list
)
70 const sal_Int32 nId
= authorId
.toInt32();
71 for (auto const& author
: list
.cmAuthorLst
)
73 if (author
.id
.toInt32() == nId
)
76 return u
"Anonymous"_ustr
;
79 OUString
Comment::getInitials(const CommentAuthorList
& list
)
81 const sal_Int32 nId
= authorId
.toInt32();
82 for (auto const& author
: list
.cmAuthorLst
)
84 if (author
.id
.toInt32() == nId
)
85 return author
.initials
;
90 const Comment
& CommentList::getCommentAtIndex(int index
)
92 if (index
< 0 || o3tl::make_unsigned(index
) >= cmLst
.size())
93 throw css::lang::IllegalArgumentException();
95 return cmLst
.at(index
);
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */