LibreOffice Module oox (master) 1
comments.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#include <oox/ppt/comments.hxx>
11#include <com/sun/star/lang/IllegalArgumentException.hpp>
12#include <rtl/math.h>
13#include <rtl/math.hxx>
14#include <o3tl/safeint.hxx>
15#include <o3tl/string_view.hxx>
16
17namespace oox::ppt
18{
20{
21 for (auto const& author : list.cmAuthorLst)
22 {
23 CommentAuthor temp;
24 // TODO JNA : why not doing push_back at the end instead of using back()?
25 cmAuthorLst.push_back(temp);
26 cmAuthorLst.back().clrIdx = author.clrIdx;
27 cmAuthorLst.back().id = author.id;
28 cmAuthorLst.back().initials = author.initials;
29 cmAuthorLst.back().lastIdx = author.lastIdx;
30 cmAuthorLst.back().name = author.name;
31 }
32}
33
34//DateTime is saved as : 2013-01-10T15:53:26.000
35void Comment::setDateTime(const OUString& sDateTime)
36{
37 sal_Int32 nIdx{ 0 };
38 aDateTime.Year = o3tl::toInt32(o3tl::getToken(sDateTime, 0, '-', nIdx));
39 aDateTime.Month = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, '-', nIdx));
40 aDateTime.Day = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, 'T', nIdx));
41 aDateTime.Hours = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, ':', nIdx));
42 aDateTime.Minutes = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, ':', nIdx));
43 double seconds = rtl_math_uStringToDouble(sDateTime.getStr() + nIdx,
44 sDateTime.getStr() + sDateTime.getLength(), '.', 0,
45 nullptr, nullptr);
46 aDateTime.Seconds = floor(seconds);
47 seconds -= aDateTime.Seconds;
48 aDateTime.NanoSeconds = ::rtl::math::round(seconds * 1000000000);
49 const int secondsOverflow = (aDateTime.Seconds == 60) ? 61 : 60;
50 // normalise time part of aDateTime
51 if (aDateTime.NanoSeconds == 1000000000)
52 {
53 aDateTime.NanoSeconds = 0;
54 ++aDateTime.Seconds;
55 }
56 if (aDateTime.Seconds == secondsOverflow)
57 {
58 aDateTime.Seconds = 0;
59 ++aDateTime.Minutes;
60 }
61 if (aDateTime.Minutes == 60)
62 {
63 aDateTime.Minutes = 0;
64 ++aDateTime.Hours;
65 }
66 // if overflow goes into date, I give up
67}
68
70{
71 const sal_Int32 nId = authorId.toInt32();
72 for (auto const& author : list.cmAuthorLst)
73 {
74 if (author.id.toInt32() == nId)
75 return author.name;
76 }
77 return "Anonymous";
78}
79
81{
82 if (index < 0 || o3tl::make_unsigned(index) >= cmLst.size())
83 throw css::lang::IllegalArgumentException();
84
85 return cmLst.at(index);
86}
87}
88
89/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setValues(const CommentAuthorList &list)
Definition: comments.cxx:19
std::vector< CommentAuthor > cmAuthorLst
Definition: comments.hxx:34
const Comment & getCommentAtIndex(int index)
Definition: comments.cxx:80
std::vector< Comment > cmLst
Definition: comments.hxx:105
css::util::DateTime aDateTime
Definition: comments.hxx:56
OUString authorId
Definition: comments.hxx:50
void setDateTime(const OUString &datetime)
Definition: comments.cxx:35
OUString getAuthor(const CommentAuthorList &list)
Definition: comments.cxx:69
index
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
sal_uInt32 toUInt32(std::u16string_view str, sal_Int16 radix=10)
sal_Int16 nId
Definition: olehelper.cxx:98