Coverage Report

Created: 2026-08-14 10:22

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