Coverage Report

Created: 2026-04-29 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libetonyek/src/lib/KEY1ParserState.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/*
3
 * This file is part of the libetonyek 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 "KEY1ParserState.h"
11
12
#include "IWORKText.h"
13
14
#include "KEY1Parser.h"
15
#include "KEY1Dictionary.h"
16
#include "KEY1Parser.h"
17
#include "KEYCollector.h"
18
19
namespace libetonyek
20
{
21
22
KEY1ParserState::KEY1ParserState(KEY1Parser &parser, KEYCollector &collector, KEY1Dictionary &dict)
23
0
  : IWORKXMLParserState(parser, collector, dict)
24
0
  , m_isPrototype(false)
25
0
  , m_isMasterSlide(false)
26
0
  , m_dict(dict)
27
0
  , m_collector(collector)
28
0
  , m_prototypes()
29
0
  , m_masterSlides()
30
0
  , m_isBulletOpened(false)
31
0
  , m_isBulletsOpened(false)
32
0
  , m_isBodyContentOpened(false)
33
0
  , m_isTitleContentOpened(false)
34
0
  , m_bodyContentFound(false)
35
0
  , m_titleContentFound(false)
36
0
{
37
0
}
38
39
KEY1Dictionary &KEY1ParserState::getDictionary()
40
0
{
41
0
  return m_dict;
42
0
}
43
44
KEYCollector &KEY1ParserState::getCollector()
45
0
{
46
0
  return m_collector;
47
0
}
48
49
void KEY1ParserState::pushIsPrototype(bool isPrototype)
50
0
{
51
0
  m_prototypes.push_back(m_isPrototype);
52
0
  m_isPrototype=isPrototype;
53
0
}
54
55
void KEY1ParserState::popIsPrototype()
56
0
{
57
0
  if (m_prototypes.empty())
58
0
  {
59
0
    ETONYEK_DEBUG_MSG(("KEY1ParserState::popIsPrototype: the stack is empty\n"));
60
0
    return;
61
0
  }
62
0
  m_isPrototype=m_prototypes.back();
63
0
  m_prototypes.pop_back();
64
0
}
65
66
void KEY1ParserState::pushIsMasterSlide(bool isMasterSlide)
67
0
{
68
0
  m_masterSlides.push_back(m_isMasterSlide);
69
0
  m_isMasterSlide=isMasterSlide;
70
0
}
71
72
void KEY1ParserState::popIsMasterSlide()
73
0
{
74
0
  if (m_masterSlides.empty())
75
0
  {
76
0
    ETONYEK_DEBUG_MSG(("KEY1ParserState::popIsMasterSlide: the stack is empty\n"));
77
0
    return;
78
0
  }
79
0
  m_isMasterSlide=m_masterSlides.back();
80
0
  m_masterSlides.pop_back();
81
0
}
82
83
void KEY1ParserState::openBullets()
84
0
{
85
0
  if (m_isBulletsOpened)
86
0
  {
87
0
    ETONYEK_DEBUG_MSG(("KEY1ParserState::openBullets: oops the bullets are already opened\n"));
88
0
    return;
89
0
  }
90
0
  m_isBulletsOpened=true;
91
0
}
92
93
void KEY1ParserState::openBullet(KEY1Bullet const &bullet)
94
0
{
95
0
  if (m_isBulletOpened)
96
0
  {
97
0
    ETONYEK_DEBUG_MSG(("KEY1ParserState::openBullet: oops the bullet are already opened\n"));
98
0
    return;
99
0
  }
100
0
  m_isBulletOpened=true;
101
0
  if (m_isPrototype || m_isMasterSlide || !m_enableCollector)
102
0
    return;
103
104
0
  if (!bullet.m_level)
105
0
  {
106
0
    ETONYEK_DEBUG_MSG(("KEY1ParserState::openBullet: oops can not find the bullet level\n"));
107
0
    return;
108
0
  }
109
0
  bool isTitle=get(bullet.m_level)==0;
110
0
  if (isTitle && !m_isTitleContentOpened && m_titleContentFound)
111
0
  {
112
0
    ETONYEK_DEBUG_MSG(("KEY1ParserState::openBullet: oops find unexpected bullet with level 0\n"));
113
0
    isTitle=false;
114
0
  }
115
0
  if (!isTitle && !m_isBodyContentOpened && m_bodyContentFound)
116
0
  {
117
0
    ETONYEK_DEBUG_MSG(("KEY1ParserState::openBullet: oops find unexpected bullet\n"));
118
0
    return;
119
0
  }
120
0
  if ((isTitle && m_isBodyContentOpened) || (!isTitle && m_isTitleContentOpened))
121
0
    storeCurrentPlaceholder();
122
0
  if (m_isBodyContentOpened || m_isTitleContentOpened)
123
0
    return;
124
0
  if (isTitle)
125
0
    m_isTitleContentOpened=true;
126
0
  else
127
0
    m_isBodyContentOpened=true;
128
0
  if (!m_enableCollector)
129
0
    return;
130
0
  m_currentText = m_collector.createText(m_langManager, false);
131
0
}
132
133
void KEY1ParserState::closeBullet()
134
0
{
135
0
  if (!m_isBulletOpened)
136
0
  {
137
0
    ETONYEK_DEBUG_MSG(("KEY1ParserState::openBullet: oops the bullet are already close\n"));
138
0
    return;
139
0
  }
140
0
  m_isBulletOpened=false;
141
142
0
  if (m_isPrototype || m_isMasterSlide || !m_enableCollector)
143
0
    return;
144
0
  if (m_currentText)
145
0
    m_currentText->flushParagraph();
146
0
}
147
148
void KEY1ParserState::closeBullets()
149
0
{
150
0
  if (!m_isBulletsOpened)
151
0
  {
152
0
    ETONYEK_DEBUG_MSG(("KEY1ParserState::openBullets: oops the bullets are already close\n"));
153
0
    return;
154
0
  }
155
0
  m_isBulletsOpened=false;
156
0
  if (m_isBodyContentOpened || m_isTitleContentOpened)
157
0
    storeCurrentPlaceholder();
158
0
}
159
160
void KEY1ParserState::storeCurrentPlaceholder()
161
0
{
162
0
  if (!m_isBodyContentOpened && !m_isTitleContentOpened)
163
0
    return;
164
0
  bool isTitle=m_isTitleContentOpened;
165
0
  m_isBodyContentOpened = m_isTitleContentOpened = false;
166
0
  if (!m_enableCollector)
167
0
    return;
168
0
  if (m_currentText && !m_currentText->empty())
169
0
  {
170
0
    if (isTitle && getDictionary().getTitlePlaceholder())
171
0
      getDictionary().getTitlePlaceholder()->m_text=m_currentText;
172
0
    else if (!isTitle && getDictionary().getBodyPlaceholder())
173
0
      getDictionary().getBodyPlaceholder()->m_text=m_currentText;
174
0
    else
175
0
    {
176
0
      ETONYEK_DEBUG_MSG(("KEY1ParserState::storeCurrentPlaceholder: oops can not store the text zone\n"));
177
0
    }
178
0
  }
179
0
  m_currentText.reset();
180
0
}
181
182
}
183
184
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */