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