summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-08-17 09:53:41 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-08-17 09:54:14 +0100
commit0c571e233f8824ab0ccd907e72dd8a81527f0998 (patch)
treea94236182b3f24c47000078751730370f69f28ca
parentbb70a1256200a593489005ce175d57fd246164ad (diff)
add and use a matchL
-rw-r--r--comphelper/inc/comphelper/string.hxx23
-rw-r--r--vcl/unx/generic/printer/jobdata.cxx50
-rw-r--r--vcl/unx/generic/printer/printerinfomanager.cxx119
3 files changed, 112 insertions, 80 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx
index c576a24ae6f5..3e74ca452aaa 100644
--- a/comphelper/inc/comphelper/string.hxx
+++ b/comphelper/inc/comphelper/string.hxx
@@ -162,6 +162,29 @@ COMPHELPER_DLLPUBLIC inline rtl::OUString getToken(const rtl::OUString &rIn,
return rIn.getToken(nToken, cTok, nIndex);
}
+/**
+ Match against a substring appearing in another string.
+
+ The result is true if and only if the second string appears as a substring
+ of the first string, at the given position.
+ This function can't be used for language specific comparison.
+
+ @param rStr The string that pMatch will be compared to.
+ @param pMatch The substring rStr is to be compared against
+ @param nMatchLen The length of pMatch
+ @param fromIndex The index to start the comparion from.
+ The index must be greater or equal than 0
+ and less or equal as the string length.
+ @return sal_True if pMatch match with the characters in the string
+ at the given position;
+ sal_False, otherwise.
+*/
+COMPHELPER_DLLPUBLIC inline sal_Bool matchL(const rtl::OString& rStr, const char *pMatch, sal_Int32 nMatchLen, sal_Int32 fromIndex = 0) SAL_THROW(())
+{
+ return rtl_str_shortenedCompare_WithLength( rStr.pData->buffer+fromIndex,
+ rStr.pData->length-fromIndex, pMatch, nMatchLen, nMatchLen ) == 0;
+}
+
/** Convert a sequence of strings to a single comma separated string.
Note that no escaping of commas or anything fancy is done.
diff --git a/vcl/unx/generic/printer/jobdata.cxx b/vcl/unx/generic/printer/jobdata.cxx
index 7f27d8551fd8..a0b6872896eb 100644
--- a/vcl/unx/generic/printer/jobdata.cxx
+++ b/vcl/unx/generic/printer/jobdata.cxx
@@ -36,6 +36,7 @@
#include <sal/alloca.h>
#include <rtl/strbuf.hxx>
+#include <comphelper/string.hxx>
using namespace psp;
@@ -187,7 +188,7 @@ bool JobData::getStreamBuffer( void*& pData, int& bytes )
bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobData )
{
SvMemoryStream aStream( pData, bytes, STREAM_READ );
- ByteString aLine;
+ rtl::OString aLine;
bool bVersion = false;
bool bPrinter = false;
bool bOrientation = false;
@@ -208,56 +209,59 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa
const char pslevelEquals[] = "pslevel=";
const char pdfdeviceEquals[] = "pdfdevice=";
+ using comphelper::string::matchL;
+
while( ! aStream.IsEof() )
{
aStream.ReadLine( aLine );
- if( aLine.CompareTo(RTL_CONSTASCII_STRINGPARAM("JobData")) == COMPARE_EQUAL )
+ if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM("JobData")))
bVersion = true;
- else if( aLine.CompareTo(RTL_CONSTASCII_STRINGPARAM(printerEquals)) == COMPARE_EQUAL )
+ else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(printerEquals)))
{
bPrinter = true;
- rJobData.m_aPrinterName = String( aLine.Copy(RTL_CONSTASCII_LENGTH(printerEquals)), RTL_TEXTENCODING_UTF8 );
+ rJobData.m_aPrinterName = rtl::OStringToOUString(aLine.copy(RTL_CONSTASCII_LENGTH(printerEquals)), RTL_TEXTENCODING_UTF8);
}
- else if( aLine.CompareTo(RTL_CONSTASCII_STRINGPARAM(orientatationEquals)) == COMPARE_EQUAL )
+ else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(orientatationEquals)))
{
bOrientation = true;
- rJobData.m_eOrientation = aLine.Copy(RTL_CONSTASCII_LENGTH(orientatationEquals)).EqualsIgnoreCaseAscii( "landscape" ) ? orientation::Landscape : orientation::Portrait;
+ rJobData.m_eOrientation = aLine.copy(RTL_CONSTASCII_LENGTH(orientatationEquals)).equalsIgnoreAsciiCase("landscape") ? orientation::Landscape : orientation::Portrait;
}
- else if( aLine.CompareTo(RTL_CONSTASCII_STRINGPARAM(copiesEquals)) == COMPARE_EQUAL )
+ else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(copiesEquals)))
{
bCopies = true;
- rJobData.m_nCopies = aLine.Copy(RTL_CONSTASCII_LENGTH(copiesEquals)).ToInt32();
+ rJobData.m_nCopies = aLine.copy(RTL_CONSTASCII_LENGTH(copiesEquals)).toInt32();
}
- else if( aLine.CompareTo(RTL_CONSTASCII_STRINGPARAM(margindajustmentEquals)) == COMPARE_EQUAL )
+ else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(margindajustmentEquals)))
{
bMargin = true;
- ByteString aValues( aLine.Copy(RTL_CONSTASCII_LENGTH(margindajustmentEquals)) );
- rJobData.m_nLeftMarginAdjust = aValues.GetToken( 0, ',' ).ToInt32();
- rJobData.m_nRightMarginAdjust = aValues.GetToken( 1, ',' ).ToInt32();
- rJobData.m_nTopMarginAdjust = aValues.GetToken( 2, ',' ).ToInt32();
- rJobData.m_nBottomMarginAdjust = aValues.GetToken( 3, ',' ).ToInt32();
+ rtl::OString aValues(aLine.copy(RTL_CONSTASCII_LENGTH(margindajustmentEquals)));
+ using comphelper::string::getToken;
+ rJobData.m_nLeftMarginAdjust = getToken(aValues, 0, ',').toInt32();
+ rJobData.m_nRightMarginAdjust = getToken(aValues, 1, ',').toInt32();
+ rJobData.m_nTopMarginAdjust = getToken(aValues, 2, ',').toInt32();
+ rJobData.m_nBottomMarginAdjust = getToken(aValues, 3, ',').toInt32();
}
- else if( aLine.CompareTo(RTL_CONSTASCII_STRINGPARAM(colordepthEquals)) == COMPARE_EQUAL )
+ else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(colordepthEquals)))
{
bColorDepth = true;
- rJobData.m_nColorDepth = aLine.Copy(RTL_CONSTASCII_LENGTH(colordepthEquals)).ToInt32();
+ rJobData.m_nColorDepth = aLine.copy(RTL_CONSTASCII_LENGTH(colordepthEquals)).toInt32();
}
- else if( aLine.CompareTo(RTL_CONSTASCII_STRINGPARAM(colordeviceEquals)) == COMPARE_EQUAL )
+ else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(colordeviceEquals)))
{
bColorDevice = true;
- rJobData.m_nColorDevice = aLine.Copy(RTL_CONSTASCII_LENGTH(colordeviceEquals)).ToInt32();
+ rJobData.m_nColorDevice = aLine.copy(RTL_CONSTASCII_LENGTH(colordeviceEquals)).toInt32();
}
- else if( aLine.CompareTo(RTL_CONSTASCII_STRINGPARAM(pslevelEquals)) == COMPARE_EQUAL )
+ else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(pslevelEquals)))
{
bPSLevel = true;
- rJobData.m_nPSLevel = aLine.Copy(RTL_CONSTASCII_LENGTH(pslevelEquals)).ToInt32();
+ rJobData.m_nPSLevel = aLine.copy(RTL_CONSTASCII_LENGTH(pslevelEquals)).toInt32();
}
- else if( aLine.CompareTo(RTL_CONSTASCII_STRINGPARAM(pdfdeviceEquals)) == COMPARE_EQUAL )
+ else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(pdfdeviceEquals)))
{
bPDFDevice = true;
- rJobData.m_nPDFDevice = aLine.Copy(RTL_CONSTASCII_LENGTH(pdfdeviceEquals)).ToInt32();
+ rJobData.m_nPDFDevice = aLine.copy(RTL_CONSTASCII_LENGTH(pdfdeviceEquals)).toInt32();
}
- else if( aLine.Equals( "PPDContexData" ) )
+ else if (aLine.equalsL(RTL_CONSTASCII_STRINGPARAM("PPDContexData")))
{
if( bPrinter )
{
diff --git a/vcl/unx/generic/printer/printerinfomanager.cxx b/vcl/unx/generic/printer/printerinfomanager.cxx
index 144821173962..d04ef42bfd80 100644
--- a/vcl/unx/generic/printer/printerinfomanager.cxx
+++ b/vcl/unx/generic/printer/printerinfomanager.cxx
@@ -45,7 +45,7 @@
#include "tools/config.hxx"
#include "i18npool/paper.hxx"
-
+#include <comphelper/string.hxx>
#include "rtl/strbuf.hxx"
#include <sal/macros.h>
@@ -273,52 +273,54 @@ void PrinterInfoManager::initialize()
#endif
aConfig.SetGroup( GLOBAL_DEFAULTS_GROUP );
- ByteString aValue( aConfig.ReadKey( "Copies" ) );
- if( aValue.Len() )
- m_aGlobalDefaults.m_nCopies = aValue.ToInt32();
+ rtl::OString aValue( aConfig.ReadKey( "Copies" ) );
+ if (!aValue.isEmpty())
+ m_aGlobalDefaults.m_nCopies = aValue.toInt32();
aValue = aConfig.ReadKey( "Orientation" );
- if( aValue.Len() )
- m_aGlobalDefaults.m_eOrientation = aValue.EqualsIgnoreCaseAscii( "Landscape" ) ? orientation::Landscape : orientation::Portrait;
+ if (!aValue.isEmpty())
+ m_aGlobalDefaults.m_eOrientation = aValue.equalsIgnoreAsciiCase("Landscape") ? orientation::Landscape : orientation::Portrait;
+
+ using comphelper::string::getToken;
aValue = aConfig.ReadKey( "MarginAdjust" );
- if( aValue.Len() )
+ if (!aValue.isEmpty())
{
- m_aGlobalDefaults.m_nLeftMarginAdjust = aValue.GetToken( 0, ',' ).ToInt32();
- m_aGlobalDefaults.m_nRightMarginAdjust = aValue.GetToken( 1, ',' ).ToInt32();
- m_aGlobalDefaults.m_nTopMarginAdjust = aValue.GetToken( 2, ',' ).ToInt32();
- m_aGlobalDefaults.m_nBottomMarginAdjust = aValue.GetToken( 3, ',' ).ToInt32();
+ m_aGlobalDefaults.m_nLeftMarginAdjust = getToken(aValue, 0, ',').toInt32();
+ m_aGlobalDefaults.m_nRightMarginAdjust = getToken(aValue, 1, ',').toInt32();
+ m_aGlobalDefaults.m_nTopMarginAdjust = getToken(aValue, 2, ',').toInt32();
+ m_aGlobalDefaults.m_nBottomMarginAdjust = getToken(aValue, 3, ',').toInt32();
}
aValue = aConfig.ReadKey( "ColorDepth", "24" );
- if( aValue.Len() )
- m_aGlobalDefaults.m_nColorDepth = aValue.ToInt32();
+ if (!aValue.isEmpty())
+ m_aGlobalDefaults.m_nColorDepth = aValue.toInt32();
aValue = aConfig.ReadKey( "ColorDevice" );
- if( aValue.Len() )
- m_aGlobalDefaults.m_nColorDevice = aValue.ToInt32();
+ if (!aValue.isEmpty())
+ m_aGlobalDefaults.m_nColorDevice = aValue.toInt32();
aValue = aConfig.ReadKey( "PSLevel" );
- if( aValue.Len() )
- m_aGlobalDefaults.m_nPSLevel = aValue.ToInt32();
+ if (!aValue.isEmpty())
+ m_aGlobalDefaults.m_nPSLevel = aValue.toInt32();
aValue = aConfig.ReadKey( "PDFDevice" );
- if( aValue.Len() )
- m_aGlobalDefaults.m_nPDFDevice = aValue.ToInt32();
+ if (!aValue.isEmpty())
+ m_aGlobalDefaults.m_nPDFDevice = aValue.toInt32();
aValue = aConfig.ReadKey( "PerformFontSubstitution" );
- if( aValue.Len() )
+ if (!aValue.isEmpty())
{
- if( ! aValue.Equals( "0" ) && ! aValue.EqualsIgnoreCaseAscii( "false" ) )
+ if (!aValue.equals("0") && !aValue.equalsIgnoreAsciiCase("false"))
m_aGlobalDefaults.m_bPerformFontSubstitution = true;
else
m_aGlobalDefaults.m_bPerformFontSubstitution = false;
}
aValue = aConfig.ReadKey( "DisableCUPS" );
- if( aValue.Len() )
+ if (!aValue.isEmpty())
{
- if( aValue.Equals( "1" ) || aValue.EqualsIgnoreCaseAscii( "true" ) )
+ if (aValue.equals("1") || aValue.equalsIgnoreAsciiCase("true"))
m_bDisableCUPS = true;
else
m_bDisableCUPS = false;
@@ -336,7 +338,7 @@ void PrinterInfoManager::initialize()
{
m_aGlobalDefaults.m_aContext.
setValue( pKey,
- aValue.Equals( "*nil" ) ? NULL : pKey->getValue( String( aValue, RTL_TEXTENCODING_ISO_8859_1 ) ),
+ aValue.equals("*nil") ? NULL : pKey->getValue(rtl::OStringToOUString(aValue, RTL_TEXTENCODING_ISO_8859_1)),
sal_True );
}
}
@@ -393,14 +395,14 @@ void PrinterInfoManager::initialize()
for( int nGroup = 0; nGroup < aConfig.GetGroupCount(); nGroup++ )
{
aConfig.SetGroup( aConfig.GetGroupName( nGroup ) );
- ByteString aValue = aConfig.ReadKey( "Printer" );
- if( aValue.Len() )
+ rtl::OString aValue = aConfig.ReadKey( "Printer" );
+ if (!aValue.isEmpty())
{
OUString aPrinterName;
- int nNamePos = aValue.Search( '/' );
+ sal_Int32 nNamePos = aValue.indexOf('/');
// check for valid value of "Printer"
- if( nNamePos == STRING_NOTFOUND )
+ if (nNamePos == -1)
continue;
Printer aPrinter;
@@ -412,9 +414,10 @@ void PrinterInfoManager::initialize()
aPrinter.m_aInfo.m_aFontSubstitutes.clear();
aPrinter.m_aInfo.m_aFontSubstitutions.clear();
- aPrinterName = String( aValue.Copy( nNamePos+1 ), RTL_TEXTENCODING_UTF8 );
- aPrinter.m_aInfo.m_aPrinterName = aPrinterName;
- aPrinter.m_aInfo.m_aDriverName = String( aValue.Copy( 0, nNamePos ), RTL_TEXTENCODING_UTF8 );
+ aPrinterName = rtl::OStringToOUString(aValue.copy(nNamePos+1),
+ RTL_TEXTENCODING_UTF8);
+ aPrinter.m_aInfo.m_aPrinterName = aPrinterName;
+ aPrinter.m_aInfo.m_aDriverName = rtl::OStringToOUString(aValue.copy(0, nNamePos), RTL_TEXTENCODING_UTF8);
// set parser, merge settings
// don't do this for CUPS printers as this is done
@@ -456,7 +459,7 @@ void PrinterInfoManager::initialize()
aValue = aConfig.ReadKey( "Command" );
// no printer without a command
- if( ! aValue.Len() )
+ if (aValue.isEmpty())
{
/* TODO:
* porters: please append your platform to the Solaris
@@ -468,61 +471,63 @@ void PrinterInfoManager::initialize()
aValue = "lpr";
#endif
}
- aPrinter.m_aInfo.m_aCommand = String( aValue, RTL_TEXTENCODING_UTF8 );
+ aPrinter.m_aInfo.m_aCommand = rtl::OStringToOUString(aValue, RTL_TEXTENCODING_UTF8);
}
aValue = aConfig.ReadKey( "QuickCommand" );
- aPrinter.m_aInfo.m_aQuickCommand = String( aValue, RTL_TEXTENCODING_UTF8 );
+ aPrinter.m_aInfo.m_aQuickCommand = rtl::OStringToOUString(aValue, RTL_TEXTENCODING_UTF8);
aValue = aConfig.ReadKey( "Features" );
- aPrinter.m_aInfo.m_aFeatures = String( aValue, RTL_TEXTENCODING_UTF8 );
+ aPrinter.m_aInfo.m_aFeatures = rtl::OStringToOUString(aValue, RTL_TEXTENCODING_UTF8);
// override the settings in m_aGlobalDefaults if keys exist
aValue = aConfig.ReadKey( "DefaultPrinter" );
- if( ! aValue.Equals( "0" ) && ! aValue.EqualsIgnoreCaseAscii( "false" ) )
+ if (!aValue.equals("0") && !aValue.equalsIgnoreAsciiCase("false"))
aDefaultPrinter = aPrinterName;
aValue = aConfig.ReadKey( "Location" );
- aPrinter.m_aInfo.m_aLocation = String( aValue, RTL_TEXTENCODING_UTF8 );
+ aPrinter.m_aInfo.m_aLocation = rtl::OStringToOUString(aValue, RTL_TEXTENCODING_UTF8);
aValue = aConfig.ReadKey( "Comment" );
- aPrinter.m_aInfo.m_aComment = String( aValue, RTL_TEXTENCODING_UTF8 );
+ aPrinter.m_aInfo.m_aComment = rtl::OStringToOUString(aValue, RTL_TEXTENCODING_UTF8);
aValue = aConfig.ReadKey( "Copies" );
- if( aValue.Len() )
- aPrinter.m_aInfo.m_nCopies = aValue.ToInt32();
+ if (!aValue.isEmpty())
+ aPrinter.m_aInfo.m_nCopies = aValue.toInt32();
aValue = aConfig.ReadKey( "Orientation" );
- if( aValue.Len() )
- aPrinter.m_aInfo.m_eOrientation = aValue.EqualsIgnoreCaseAscii( "Landscape" ) ? orientation::Landscape : orientation::Portrait;
+ if (!aValue.isEmpty())
+ aPrinter.m_aInfo.m_eOrientation = aValue.equalsIgnoreAsciiCase("Landscape") ? orientation::Landscape : orientation::Portrait;
+
+ using comphelper::string::getToken;
aValue = aConfig.ReadKey( "MarginAdjust" );
- if( aValue.Len() )
+ if (!aValue.isEmpty())
{
- aPrinter.m_aInfo.m_nLeftMarginAdjust = aValue.GetToken( 0, ',' ).ToInt32();
- aPrinter.m_aInfo.m_nRightMarginAdjust = aValue.GetToken( 1, ',' ).ToInt32();
- aPrinter.m_aInfo.m_nTopMarginAdjust = aValue.GetToken( 2, ',' ).ToInt32();
- aPrinter.m_aInfo.m_nBottomMarginAdjust = aValue.GetToken( 3, ',' ).ToInt32();
+ aPrinter.m_aInfo.m_nLeftMarginAdjust = getToken(aValue, 0, ',' ).toInt32();
+ aPrinter.m_aInfo.m_nRightMarginAdjust = getToken(aValue, 1, ',' ).toInt32();
+ aPrinter.m_aInfo.m_nTopMarginAdjust = getToken(aValue, 2, ',' ).toInt32();
+ aPrinter.m_aInfo.m_nBottomMarginAdjust = getToken(aValue, 3, ',' ).toInt32();
}
aValue = aConfig.ReadKey( "ColorDepth" );
- if( aValue.Len() )
- aPrinter.m_aInfo.m_nColorDepth = aValue.ToInt32();
+ if (!aValue.isEmpty())
+ aPrinter.m_aInfo.m_nColorDepth = aValue.toInt32();
aValue = aConfig.ReadKey( "ColorDevice" );
- if( aValue.Len() )
- aPrinter.m_aInfo.m_nColorDevice = aValue.ToInt32();
+ if (!aValue.isEmpty())
+ aPrinter.m_aInfo.m_nColorDevice = aValue.toInt32();
aValue = aConfig.ReadKey( "PSLevel" );
- if( aValue.Len() )
- aPrinter.m_aInfo.m_nPSLevel = aValue.ToInt32();
+ if (!aValue.isEmpty())
+ aPrinter.m_aInfo.m_nPSLevel = aValue.toInt32();
aValue = aConfig.ReadKey( "PDFDevice" );
- if( aValue.Len() )
- aPrinter.m_aInfo.m_nPDFDevice = aValue.ToInt32();
+ if (!aValue.isEmpty())
+ aPrinter.m_aInfo.m_nPDFDevice = aValue.toInt32();
aValue = aConfig.ReadKey( "PerformFontSubstitution" );
- if( ! aValue.Equals( "0" ) && ! aValue.EqualsIgnoreCaseAscii( "false" ) )
+ if (!aValue.equals("0") && !aValue.equalsIgnoreAsciiCase("false"))
aPrinter.m_aInfo.m_bPerformFontSubstitution = true;
else
aPrinter.m_aInfo.m_bPerformFontSubstitution = false;
@@ -541,7 +546,7 @@ void PrinterInfoManager::initialize()
{
aPrinter.m_aInfo.m_aContext.
setValue( pKey,
- aValue.Equals( "*nil" ) ? NULL : pKey->getValue( String( aValue, RTL_TEXTENCODING_ISO_8859_1 ) ),
+ aValue.equals("*nil") ? NULL : pKey->getValue(rtl::OStringToOUString(aValue, RTL_TEXTENCODING_ISO_8859_1)),
sal_True );
}
}