Kaydet (Commit) 0c571e23 authored tarafından Caolán McNamara's avatar Caolán McNamara

add and use a matchL

üst bb70a125
......@@ -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.
......
......@@ -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 )
{
......
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