Kaydet (Commit) df18d587 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Some string literal clean up

Change-Id: I108882af13fa97fa094547ec4efb468f988f337d
üst 09269acd
......@@ -30,7 +30,6 @@
#include "comphelper/sequenceasvector.hxx"
#include "rtl/string.h"
#include "rtl/string.hxx"
#include "rtl/ustring.h"
#include "rtl/ustring.hxx"
#include "sal/types.h"
#include "xmlreader/span.hxx"
......@@ -68,15 +67,11 @@ bool parseHexDigit(char c, int * value) {
bool parseValue(xmlreader::Span const & text, sal_Bool * value) {
assert(text.is() && value != 0);
if (text.equals(RTL_CONSTASCII_STRINGPARAM("true")) ||
text.equals(RTL_CONSTASCII_STRINGPARAM("1")))
{
if (text.equals("true") || text.equals("1")) {
*value = true;
return true;
}
if (text.equals(RTL_CONSTASCII_STRINGPARAM("false")) ||
text.equals(RTL_CONSTASCII_STRINGPARAM("0")))
{
if (text.equals("false") || text.equals("0")) {
*value = false;
return true;
}
......@@ -293,8 +288,7 @@ bool ValueParser::startElement(
}
switch (state_) {
case STATE_TEXT:
if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
name.equals(RTL_CONSTASCII_STRINGPARAM("it")) &&
if (nsId == xmlreader::XmlReader::NAMESPACE_NONE && name.equals("it") &&
isListType(type_) && separator_.isEmpty())
{
pad_.clear();
......@@ -306,7 +300,7 @@ bool ValueParser::startElement(
// fall through
case STATE_IT:
if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
name.equals(RTL_CONSTASCII_STRINGPARAM("unicode")) &&
name.equals("unicode") &&
(type_ == TYPE_STRING || type_ == TYPE_STRING_LIST))
{
sal_Int32 scalar = -1;
......@@ -317,7 +311,7 @@ bool ValueParser::startElement(
break;
}
if (attrNsId == ParseManager::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("scalar")))
attrLn.equals("scalar"))
{
if (!parseValue(reader.getAttributeValue(true), &scalar)) {
scalar = -1;
......
......@@ -26,8 +26,6 @@
#include "com/sun/star/uno/Reference.hxx"
#include "com/sun/star/uno/RuntimeException.hpp"
#include "com/sun/star/uno/XInterface.hpp"
#include "rtl/string.h"
#include "rtl/ustring.h"
#include "rtl/ustring.hxx"
#include "xmlreader/span.hxx"
#include "xmlreader/xmlreader.hxx"
......@@ -65,16 +63,14 @@ bool XcdParser::startElement(
}
switch (state_) {
case STATE_START:
if (nsId == ParseManager::NAMESPACE_OOR &&
name.equals(RTL_CONSTASCII_STRINGPARAM("data")))
{
if (nsId == ParseManager::NAMESPACE_OOR && name.equals("data")) {
state_ = STATE_DEPENDENCIES;
return true;
}
break;
case STATE_DEPENDENCIES:
if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
name.equals(RTL_CONSTASCII_STRINGPARAM("dependency")))
name.equals("dependency"))
{
if (dependencyFile_.isEmpty()) {
dependencyOptional_ = false;
......@@ -87,13 +83,12 @@ bool XcdParser::startElement(
}
if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE &&
//TODO: _OOR
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("file")))
attrLn.equals("file"))
{
attrFile = reader.getAttributeValue(false);
} else if ((attrNsId ==
xmlreader::XmlReader::NAMESPACE_NONE) &&
attrLn.equals(
RTL_CONSTASCII_STRINGPARAM("optional")))
attrLn.equals("optional"))
{
dependencyOptional_ = xmldata::parseBoolean(
reader.getAttributeValue(true));
......@@ -129,7 +124,7 @@ bool XcdParser::startElement(
// fall through
case STATE_COMPONENTS:
if (nsId == ParseManager::NAMESPACE_OOR &&
name.equals(RTL_CONSTASCII_STRINGPARAM("component-schema")))
name.equals("component-schema"))
{
nestedParser_ = new XcsParser(layer_, data_);
nesting_ = 1;
......@@ -137,7 +132,7 @@ bool XcdParser::startElement(
reader, nsId, name, existingDependencies);
}
if (nsId == ParseManager::NAMESPACE_OOR &&
name.equals(RTL_CONSTASCII_STRINGPARAM("component-data")))
name.equals("component-data"))
{
nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0);
nesting_ = 1;
......
This diff is collapsed.
This diff is collapsed.
......@@ -29,10 +29,7 @@
#include "com/sun/star/uno/XInterface.hpp"
#include "osl/file.hxx"
#include "rtl/ref.hxx"
#include "rtl/strbuf.hxx"
#include "rtl/string.h"
#include "rtl/ustrbuf.hxx"
#include "rtl/ustring.h"
#include "rtl/ustring.hxx"
#include "sal/types.h"
#include "xmlreader/span.hxx"
......@@ -63,79 +60,79 @@ Type parseType(
switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) {
case ParseManager::NAMESPACE_OOR:
if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("any")))
equals("any"))
{
return TYPE_ANY;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("boolean-list")))
equals("boolean-list"))
{
return TYPE_BOOLEAN_LIST;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("short-list")))
equals("short-list"))
{
return TYPE_SHORT_LIST;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("int-list")))
equals("int-list"))
{
return TYPE_INT_LIST;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("long-list")))
equals("long-list"))
{
return TYPE_LONG_LIST;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("double-list")))
equals("double-list"))
{
return TYPE_DOUBLE_LIST;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("string-list")))
equals("string-list"))
{
return TYPE_STRING_LIST;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("hexBinary-list")))
equals("hexBinary-list"))
{
return TYPE_HEXBINARY_LIST;
}
break;
case ParseManager::NAMESPACE_XS:
if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("boolean")))
equals("boolean"))
{
return TYPE_BOOLEAN;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("short")))
equals("short"))
{
return TYPE_SHORT;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("int")))
equals("int"))
{
return TYPE_INT;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("long")))
equals("long"))
{
return TYPE_LONG;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("double")))
equals("double"))
{
return TYPE_DOUBLE;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("string")))
equals("string"))
{
return TYPE_STRING;
} else if (xmlreader::Span(
text.begin + i + 1, text.length - (i + 1)).
equals(RTL_CONSTASCII_STRINGPARAM("hexBinary")))
equals("hexBinary"))
{
return TYPE_HEXBINARY;
}
......@@ -145,22 +142,20 @@ Type parseType(
}
}
throw css::uno::RuntimeException(
(OUString("invalid type ") +
text.convertFromUtf8()),
"invalid type " + text.convertFromUtf8(),
css::uno::Reference< css::uno::XInterface >());
}
bool parseBoolean(xmlreader::Span const & text) {
assert(text.is());
if (text.equals(RTL_CONSTASCII_STRINGPARAM("true"))) {
if (text.equals("true")) {
return true;
}
if (text.equals(RTL_CONSTASCII_STRINGPARAM("false"))) {
if (text.equals("false")) {
return false;
}
throw css::uno::RuntimeException(
(OUString("invalid boolean ") +
text.convertFromUtf8()),
"invalid boolean " + text.convertFromUtf8(),
css::uno::Reference< css::uno::XInterface >());
}
......@@ -173,7 +168,7 @@ OUString parseTemplateReference(
return *defaultTemplateName;
}
throw css::uno::RuntimeException(
OUString("missing node-type attribute"),
"missing node-type attribute",
css::uno::Reference< css::uno::XInterface >());
}
return Data::fullTemplateName(component, nodeType);
......
......@@ -22,6 +22,8 @@
#include "sal/config.h"
#include <cstddef>
#include "rtl/strbuf.hxx"
#include "sal/types.h"
#include "xmlreader/detail/xmlreaderdllapi.hxx"
......@@ -33,6 +35,10 @@ class OOO_DLLPUBLIC_XMLREADER Pad {
public:
void add(char const * begin, sal_Int32 length);
template< std::size_t N > void add(char const (& literal)[N]) {
add(literal, N - 1);
}
void addEphemeral(char const * begin, sal_Int32 length);
void clear();
......
......@@ -22,12 +22,13 @@
#include "sal/config.h"
#include "rtl/string.hxx"
#include "rtl/stringutils.hxx"
#include "rtl/ustring.hxx"
#include <cstddef>
#include "sal/types.h"
#include "xmlreader/detail/xmlreaderdllapi.hxx"
namespace rtl { class OUString; }
namespace xmlreader {
struct OOO_DLLPUBLIC_XMLREADER Span {
......@@ -40,6 +41,10 @@ struct OOO_DLLPUBLIC_XMLREADER Span {
inline Span(char const * theBegin, sal_Int32 theLength):
begin(theBegin), length(theLength) {}
template< std::size_t N > explicit inline Span(char const (& literal)[N]):
begin(literal), length(N - 1)
{}
inline void clear() throw() { begin = 0; }
inline bool is() const { return begin != 0; }
......@@ -53,23 +58,13 @@ struct OOO_DLLPUBLIC_XMLREADER Span {
return equals(Span(textBegin, textLength));
}
inline bool equals(OString const & text) const {
return rtl_str_compare_WithLength(
begin, length, text.getStr(), text.getLength()) == 0;
}
/**
@overload
This function accepts an ASCII string literal as its argument.
*/
template< typename T > bool
equals( T& literal, typename rtl::internal::ConstCharArrayDetector< T, rtl::internal::Dummy >::Type = rtl::internal::Dummy() ) SAL_THROW(())
template< std::size_t N > inline bool equals(char const (& literal)[N])
const
{
assert( strlen( literal ) == rtl::internal::ConstCharArrayDetector< T >::size - 1 );
return rtl_str_compare_WithLength( begin, length, literal, rtl::internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
return equals(Span(literal, N - 1));
}
OUString convertFromUtf8() const;
rtl::OUString convertFromUtf8() const;
};
}
......
......@@ -87,19 +87,22 @@ SwLabelConfig::SwLabelConfig() :
// fill m_aLabels and m_aManufacturers with the predefined labels
res = reader.nextItem(
xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
assert(res == xmlreader::XmlReader::RESULT_BEGIN &&
name.equals(RTL_CONSTASCII_STRINGPARAM("manufacturers")));
assert(
res == xmlreader::XmlReader::RESULT_BEGIN
&& name.equals("manufacturers"));
res = reader.nextItem(
xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
while (res != xmlreader::XmlReader::RESULT_END)
{
// Opening manufacturer
assert(res == xmlreader::XmlReader::RESULT_BEGIN &&
name.equals(RTL_CONSTASCII_STRINGPARAM("manufacturer")));
assert(
res == xmlreader::XmlReader::RESULT_BEGIN
&& name.equals("manufacturer"));
// Get the name
reader.nextAttribute(&nsId, &name);
assert(nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
name.equals(RTL_CONSTASCII_STRINGPARAM("name")));
assert(
nsId == xmlreader::XmlReader::NAMESPACE_NONE
&& name.equals("name"));
sManufacturer = reader.getAttributeValue(false).convertFromUtf8();
for(;;) {
......@@ -108,14 +111,13 @@ SwLabelConfig::SwLabelConfig() :
xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
if (res == xmlreader::XmlReader::RESULT_END)
break;
assert(res == xmlreader::XmlReader::RESULT_BEGIN &&
name.equals(RTL_CONSTASCII_STRINGPARAM("label")));
assert(
res == xmlreader::XmlReader::RESULT_BEGIN
&& name.equals("label"));
// Get name value
sName = lcl_getValue(reader,
xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("name")));
sName = lcl_getValue(reader, xmlreader::Span("name"));
// Get measure value
sMeasure = lcl_getValue(reader,
xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("measure")));
sMeasure = lcl_getValue(reader, xmlreader::Span("measure"));
// Ending label mark
lcl_assertEndingItem(reader);
if ( m_aLabels.find( sManufacturer ) == m_aLabels.end() )
......
......@@ -21,7 +21,6 @@
#include <cassert>
#include "rtl/string.h"
#include "sal/types.h"
#include "xmlreader/pad.hxx"
#include "xmlreader/span.hxx"
......@@ -61,7 +60,7 @@ Span Pad::get() const {
if (span_.is()) {
return span_;
} else if (buffer_.getLength() == 0) {
return Span(RTL_CONSTASCII_STRINGPARAM(""));
return Span("");
} else {
return Span(buffer_.getStr(), buffer_.getLength());
}
......
......@@ -42,7 +42,7 @@ OUString Span::convertFromUtf8() const {
RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
{
throw css::uno::RuntimeException(
OUString("cannot convert from UTF-8"),
"cannot convert from UTF-8",
css::uno::Reference< css::uno::XInterface >());
}
return OUString(s, SAL_NO_ACQUIRE);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment