Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
d42813db
Kaydet (Commit)
d42813db
authored
Eyl 20, 2014
tarafından
Tomaž Vajngerl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Extend HTMLWriter: flush the stack, more values for attribute(..)
Change-Id: I733426ba5f82ee25751387f88942dbc66689821d
üst
0ce8533e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
193 additions
and
11 deletions
+193
-11
HtmlWriter.hxx
include/svtools/HtmlWriter.hxx
+23
-8
testHtmlWriter.cxx
svtools/qa/unit/testHtmlWriter.cxx
+124
-0
HtmlWriter.cxx
svtools/source/svhtml/HtmlWriter.cxx
+46
-3
No files found.
include/svtools/HtmlWriter.hxx
Dosyayı görüntüle @
d42813db
...
...
@@ -12,6 +12,7 @@
#define INCLUDED_SVTOOLS_HTMLWRITER_HXX
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
#include <tools/stream.hxx>
#include <vector>
#include <svtools/svtdllapi.h>
...
...
@@ -20,11 +21,13 @@ class SVT_DLLPUBLIC HtmlWriter
{
private
:
std
::
vector
<
OString
>
maElementStack
;
SvStream
&
mrStream
;
bool
mbElementOpen
;
bool
mbContentWritten
;
bool
mbPrettyPrint
;
SvStream
&
mrStream
;
bool
mbElementOpen
;
bool
mbContentWritten
;
bool
mbPrettyPrint
;
rtl_TextEncoding
maEncoding
;
public
:
HtmlWriter
(
SvStream
&
rStream
);
...
...
@@ -32,11 +35,23 @@ public:
void
prettyPrint
(
bool
bChoice
);
void
start
(
const
OString
&
aElement
);
void
start
(
const
OString
&
aElement
);
void
end
();
void
write
(
const
OString
&
aContent
);
void
attribute
(
const
OString
&
aAttribute
,
const
OString
&
aValue
);
void
single
(
const
OString
&
aContent
);
void
flushStack
();
void
flushStack
(
const
OString
&
aElement
);
void
write
(
const
OString
&
aContent
);
void
attribute
(
const
OString
&
aAttribute
,
const
char
*
aValue
);
void
attribute
(
const
OString
&
aAttribute
,
sal_Int32
aValue
);
void
attribute
(
const
OString
&
aAttribute
,
const
OString
&
aValue
);
void
attribute
(
const
OString
&
aAttribute
,
const
OUString
&
aValue
);
// boolean attribute e.g. <img ismap>
void
attribute
(
const
OString
&
aAttribute
);
void
single
(
const
OString
&
aContent
);
void
endAttribute
();
};
...
...
svtools/qa/unit/testHtmlWriter.cxx
Dosyayı görüntüle @
d42813db
...
...
@@ -40,6 +40,8 @@ public:
void
testSingleElementWithContent
();
void
testSingleElementWithContentAndAttributes
();
void
testNested
();
void
testAttributeValues
();
void
testFlushStack
();
CPPUNIT_TEST_SUITE
(
Test
);
CPPUNIT_TEST
(
testSingleElement
);
...
...
@@ -47,6 +49,8 @@ public:
CPPUNIT_TEST
(
testSingleElementWithContent
);
CPPUNIT_TEST
(
testSingleElementWithContentAndAttributes
);
CPPUNIT_TEST
(
testNested
);
CPPUNIT_TEST
(
testAttributeValues
);
CPPUNIT_TEST
(
testFlushStack
);
CPPUNIT_TEST_SUITE_END
();
};
...
...
@@ -162,6 +166,126 @@ void Test::testNested()
CPPUNIT_ASSERT_EQUAL
(
OString
(
"<abc><xyz>xxx</xyz></abc>"
),
aString
);
}
void
Test
::
testAttributeValues
()
{
SvMemoryStream
aStream
;
HtmlWriter
aHtml
(
aStream
);
aHtml
.
prettyPrint
(
false
);
aHtml
.
start
(
"abc"
);
aHtml
.
attribute
(
"one"
,
OString
(
"one"
));
aHtml
.
attribute
(
"two"
,
OUString
(
"two"
));
aHtml
.
attribute
(
"three"
,
sal_Int32
(
12
));
aHtml
.
end
();
OString
aString
=
extractFromStream
(
aStream
);
CPPUNIT_ASSERT_EQUAL
(
OString
(
"<abc one=
\"
one
\"
two=
\"
two
\"
three=
\"
12
\"
/>"
),
aString
);
}
void
Test
::
testFlushStack
()
{
{
SvMemoryStream
aStream
;
HtmlWriter
aHtml
(
aStream
);
aHtml
.
prettyPrint
(
false
);
aHtml
.
start
(
"a"
);
aHtml
.
flushStack
(
"a"
);
// simple ,end element "a" = like end()
OString
aString
=
extractFromStream
(
aStream
);
CPPUNIT_ASSERT_EQUAL
(
OString
(
"<a/>"
),
aString
);
}
{
SvMemoryStream
aStream
;
HtmlWriter
aHtml
(
aStream
);
aHtml
.
prettyPrint
(
false
);
aHtml
.
start
(
"a"
);
aHtml
.
start
(
"b"
);
aHtml
.
flushStack
(
"b"
);
// end at first element "b", don't output "a" yet
OString
aString
=
extractFromStream
(
aStream
);
CPPUNIT_ASSERT_EQUAL
(
OString
(
"<a><b/>"
),
aString
);
}
{
SvMemoryStream
aStream
;
HtmlWriter
aHtml
(
aStream
);
aHtml
.
prettyPrint
(
false
);
aHtml
.
start
(
"a"
);
aHtml
.
start
(
"b"
);
aHtml
.
flushStack
(
"a"
);
// end at first element "a"
OString
aString
=
extractFromStream
(
aStream
);
CPPUNIT_ASSERT_EQUAL
(
OString
(
"<a><b/></a>"
),
aString
);
}
{
SvMemoryStream
aStream
;
HtmlWriter
aHtml
(
aStream
);
aHtml
.
prettyPrint
(
false
);
aHtml
.
start
(
"a"
);
aHtml
.
start
(
"b"
);
aHtml
.
start
(
"c"
);
aHtml
.
flushStack
(
"a"
);
// end at first element "a"
OString
aString
=
extractFromStream
(
aStream
);
CPPUNIT_ASSERT_EQUAL
(
OString
(
"<a><b><c/></b></a>"
),
aString
);
}
{
SvMemoryStream
aStream
;
HtmlWriter
aHtml
(
aStream
);
aHtml
.
prettyPrint
(
false
);
aHtml
.
start
(
"a"
);
aHtml
.
start
(
"b"
);
aHtml
.
start
(
"c"
);
aHtml
.
flushStack
(
"b"
);
// end at first element "b"
OString
aString
=
extractFromStream
(
aStream
);
CPPUNIT_ASSERT_EQUAL
(
OString
(
"<a><b><c/></b>"
),
aString
);
}
{
SvMemoryStream
aStream
;
HtmlWriter
aHtml
(
aStream
);
aHtml
.
prettyPrint
(
false
);
aHtml
.
start
(
"a"
);
aHtml
.
start
(
"b"
);
aHtml
.
start
(
"c"
);
aHtml
.
flushStack
(
"x"
);
// no known element - ends when stack is empty
OString
aString
=
extractFromStream
(
aStream
);
CPPUNIT_ASSERT_EQUAL
(
OString
(
"<a><b><c/></b></a>"
),
aString
);
}
{
SvMemoryStream
aStream
;
HtmlWriter
aHtml
(
aStream
);
aHtml
.
prettyPrint
(
false
);
aHtml
.
start
(
"a"
);
aHtml
.
start
(
"b"
);
aHtml
.
start
(
"c"
);
aHtml
.
flushStack
();
// flush the whole stack
OString
aString
=
extractFromStream
(
aStream
);
CPPUNIT_ASSERT_EQUAL
(
OString
(
"<a><b><c/></b></a>"
),
aString
);
}
}
CPPUNIT_TEST_SUITE_REGISTRATION
(
Test
);
CPPUNIT_PLUGIN_IMPLEMENT
();
...
...
svtools/source/svhtml/HtmlWriter.cxx
Dosyayı görüntüle @
d42813db
...
...
@@ -14,7 +14,8 @@ HtmlWriter::HtmlWriter(SvStream& rStream) :
mrStream
(
rStream
),
mbElementOpen
(
false
),
mbContentWritten
(
false
),
mbPrettyPrint
(
true
)
mbPrettyPrint
(
true
),
maEncoding
(
RTL_TEXTENCODING_UTF8
)
{}
HtmlWriter
::~
HtmlWriter
()
...
...
@@ -25,7 +26,7 @@ void HtmlWriter::prettyPrint(bool bChoice)
mbPrettyPrint
=
bChoice
;
}
void
HtmlWriter
::
start
(
const
OString
&
aElement
)
void
HtmlWriter
::
start
(
const
OString
&
aElement
)
{
if
(
mbElementOpen
)
{
...
...
@@ -66,6 +67,24 @@ void HtmlWriter::endAttribute()
}
}
void
HtmlWriter
::
flushStack
()
{
while
(
!
maElementStack
.
empty
())
{
end
();
}
}
void
HtmlWriter
::
flushStack
(
const
OString
&
aElement
)
{
OString
sCurrentElement
;
do
{
sCurrentElement
=
maElementStack
.
back
();
end
();
}
while
(
!
maElementStack
.
empty
()
&&
aElement
!=
sCurrentElement
);
}
void
HtmlWriter
::
end
()
{
if
(
mbElementOpen
)
...
...
@@ -105,7 +124,7 @@ void HtmlWriter::write(const OString &aContent)
mrStream
.
WriteOString
(
aContent
);
}
void
HtmlWriter
::
attribute
(
const
OString
&
aAttribute
,
const
OString
&
aValue
)
void
HtmlWriter
::
attribute
(
const
OString
&
aAttribute
,
const
OString
&
aValue
)
{
if
(
mbElementOpen
&&
!
aAttribute
.
isEmpty
()
&&
!
aValue
.
isEmpty
())
{
...
...
@@ -118,5 +137,29 @@ void HtmlWriter::attribute(const OString &aAttribute, const OString &aValue)
}
}
void
HtmlWriter
::
attribute
(
const
OString
&
aAttribute
,
const
sal_Int32
aValue
)
{
attribute
(
aAttribute
,
OString
::
number
(
aValue
));
}
void
HtmlWriter
::
attribute
(
const
OString
&
aAttribute
,
const
char
*
pValue
)
{
attribute
(
aAttribute
,
OString
(
pValue
));
}
void
HtmlWriter
::
attribute
(
const
OString
&
aAttribute
,
const
OUString
&
aValue
)
{
attribute
(
aAttribute
,
OUStringToOString
(
aValue
,
maEncoding
));
}
void
HtmlWriter
::
attribute
(
const
OString
&
aAttribute
)
{
if
(
mbElementOpen
&&
!
aAttribute
.
isEmpty
())
{
mrStream
.
WriteChar
(
' '
);
mrStream
.
WriteOString
(
aAttribute
);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment