Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/ppt/comments.cxx
Line
Count
Source
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
17
namespace oox::ppt
18
{
19
void CommentAuthorList::setValues(const CommentAuthorList& list)
20
53
{
21
53
    for (auto const& author : list.cmAuthorLst)
22
26
    {
23
26
        CommentAuthor commentAuthor;
24
26
        commentAuthor.clrIdx = author.clrIdx;
25
26
        commentAuthor.id = author.id;
26
26
        commentAuthor.initials = author.initials;
27
26
        commentAuthor.lastIdx = author.lastIdx;
28
26
        commentAuthor.name = author.name;
29
26
        cmAuthorLst.push_back(commentAuthor);
30
26
    }
31
53
}
32
33
//DateTime is saved as : 2013-01-10T15:53:26.000
34
void Comment::setDateTime(const OUString& sDateTime)
35
61
{
36
61
    sal_Int32 nIdx{ 0 };
37
61
    aDateTime.Year = o3tl::toInt32(o3tl::getToken(sDateTime, 0, '-', nIdx));
38
61
    aDateTime.Month = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, '-', nIdx));
39
61
    aDateTime.Day = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, 'T', nIdx));
40
61
    aDateTime.Hours = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, ':', nIdx));
41
61
    aDateTime.Minutes = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, ':', nIdx));
42
61
    double seconds = rtl_math_uStringToDouble(sDateTime.getStr() + nIdx,
43
61
                                              sDateTime.getStr() + sDateTime.getLength(), '.', 0,
44
61
                                              nullptr, nullptr);
45
61
    aDateTime.Seconds = floor(seconds);
46
61
    seconds -= aDateTime.Seconds;
47
61
    aDateTime.NanoSeconds = ::rtl::math::round(seconds * 1000000000);
48
61
    const int secondsOverflow = (aDateTime.Seconds == 60) ? 61 : 60;
49
    // normalise time part of aDateTime
50
61
    if (aDateTime.NanoSeconds == 1000000000)
51
0
    {
52
0
        aDateTime.NanoSeconds = 0;
53
0
        ++aDateTime.Seconds;
54
0
    }
55
61
    if (aDateTime.Seconds == secondsOverflow)
56
0
    {
57
0
        aDateTime.Seconds = 0;
58
0
        ++aDateTime.Minutes;
59
0
    }
60
61
    if (aDateTime.Minutes == 60)
61
0
    {
62
0
        aDateTime.Minutes = 0;
63
0
        ++aDateTime.Hours;
64
0
    }
65
    // if overflow goes into date, I give up
66
61
}
67
68
OUString Comment::getAuthor(const CommentAuthorList& list)
69
61
{
70
61
    const sal_Int32 nId = authorId.toInt32();
71
61
    for (auto const& author : list.cmAuthorLst)
72
27
    {
73
27
        if (author.id.toInt32() == nId)
74
26
            return author.name;
75
27
    }
76
35
    return u"Anonymous"_ustr;
77
61
}
78
79
OUString Comment::getInitials(const CommentAuthorList& list)
80
61
{
81
61
    const sal_Int32 nId = authorId.toInt32();
82
61
    for (auto const& author : list.cmAuthorLst)
83
27
    {
84
27
        if (author.id.toInt32() == nId)
85
26
            return author.initials;
86
27
    }
87
35
    return u"A"_ustr;
88
61
}
89
90
const Comment& CommentList::getCommentAtIndex(int index)
91
61
{
92
61
    if (index < 0 || o3tl::make_unsigned(index) >= cmLst.size())
93
0
        throw css::lang::IllegalArgumentException();
94
95
61
    return cmLst.at(index);
96
61
}
97
}
98
99
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */