[Libreoffice-commits] core.git: i18npool/source sc/source

2021-04-05 Thread Mike Kaganski (via logerrit)
 i18npool/source/search/levdis.cxx  |   62 +
 i18npool/source/search/levdis.hxx  |4 --
 sc/source/filter/html/htmlpars.cxx |   28 +---
 3 files changed, 11 insertions(+), 83 deletions(-)

New commits:
commit 995b3186fa2126d1b299052a90a75cf32d5bfa26
Author: Mike Kaganski 
AuthorDate: Mon Apr 5 15:12:04 2021 +0300
Commit: Mike Kaganski 
CommitDate: Mon Apr 5 15:16:23 2021 +0200

Use std algorithms here

Change-Id: Ib7bb92cca1f52067f9030b6c6fdc088409ca10ef
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113601
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/i18npool/source/search/levdis.cxx 
b/i18npool/source/search/levdis.cxx
index 5842abd1eef5..dd9f8fbf587a 100644
--- a/i18npool/source/search/levdis.cxx
+++ b/i18npool/source/search/levdis.cxx
@@ -56,6 +56,7 @@
 */
 
 #include 
+#include 
 
 #include "levdis.hxx"
 
@@ -119,7 +120,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, 
sal_Int32 nStringLen )
 nP = 0; // a '?' could be any character.
 else
 // Minimum of replacement and deletion+insertion weighting
-nP = Min3( nRepP0, nRepP0, nDelR0 + nInsQ0 );
+nP = std::min({ nRepP0, nRepP0, nDelR0 + nInsQ0 });
 npDistance[0] = nInsQ0; // start with simple insert
 npDistance[1] = nInsQ0;
 npDistance[2] = nInsQ0;
@@ -150,7 +151,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, 
sal_Int32 nStringLen )
 }
 }
 }
-nSPMin = Min3( npDistance[0], npDistance[1], npDistance[2] );
+nSPMin = std::min({ npDistance[0], npDistance[1], npDistance[2] });
 }
 
 // calculate distance matrix
@@ -203,7 +204,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, 
sal_Int32 nStringLen )
 // WLD( X(i), Y(j) ) = min( WLD( X(i-1), Y(j-1) ) + p(i,j) ,
 //  WLD( X(i)  , Y(j-1) ) + q  ,
 //  WLD( X(i-1), Y(j)   ) + r  )
-npDistance[i] = Min3( d1 + nPij, d2 + nQ, npDistance[i-1] + nR );
+npDistance[i] = std::min({ d1 + nPij, d2 + nQ, npDistance[i-1] + 
nR });
 if ( npDistance[i] < nSPMin )
 nSPMin = npDistance[i];
 if ( bSplitCount )
@@ -263,63 +264,27 @@ void WLevDistance::CalcLPQR( int nX, int nY, int nZ, bool 
bRelaxed )
 if ( nX < 0 ) nX = 0;   // only positive values
 if ( nY < 0 ) nY = 0;
 if ( nZ < 0 ) nZ = 0;
-if (0 == Min3( nX, nY, nZ ))// at least one 0
+if (0 == std::min({ nX, nY, nZ })) // at least one 0
 {
 int nMid, nMax;
-nMax = Max3( nX, nY, nZ );  // either 0 for three 0s or Max
+nMax = std::max({ nX, nY, nZ }); // either 0 for three 0s or Max
 if ( 0 == (nMid = Mid3( nX, nY, nZ )) ) // even two 0
 nLimit = nMax;  // either 0 or the only one >0
 else// one is 0
-nLimit = LCM( nMid, nMax );
+nLimit = std::lcm( nMid, nMax );
 }
 else// all three of them are not 0
-nLimit = LCM( LCM( nX, nY ), nZ );
+nLimit = std::lcm(std::lcm(nX, nY), nZ);
 nRepP0 = ( nX ? nLimit / nX : nLimit + 1 );
 nInsQ0 = ( nY ? nLimit / nY : nLimit + 1 );
 nDelR0 = ( nZ ? nLimit / nZ : nLimit + 1 );
 bSplitCount = bRelaxed;
 }
 
-// greatest common divisor according to Euklid (chaindivision)
-// special case: 0 plus anything produces 1
-int WLevDistance::GCD( int a, int b )
-{
-if ( !a || !b )
-return 1;
-if ( a < 0 ) a = -a;
-if ( b < 0 ) b = -b;
-do
-{
-if ( a > b )
-a -= int(a / b) * b;
-else
-b -= int(b / a) * a;
-} while ( a && b );
-return( a ? a : b);
-}
-
-// least common multiple : a * b / GCD(a,b)
-int WLevDistance::LCM( int a, int b )
-{
-if ( a > b )// decrease overflow chance
-return( (a / GCD(a,b)) * b );
-else
-return( (b / GCD(a,b)) * a );
-}
-
-// Minimum of three values
-inline int WLevDistance::Min3( int x, int y, int z )
-{
-if ( x < y )
-return std::min(x, z);
-else
-return std::min(y, z);
-}
-
 // The value in the middle
 int WLevDistance::Mid3( int x, int y, int z )
 {
-int min = Min3(x,y,z);
+int min = std::min({ x, y, z });
 if ( x == min )
 return std::min(y, z);
 else if ( y == min )
@@ -328,15 +293,6 @@ int WLevDistance::Mid3( int x, int y, int z )
 return std::min(x, y);
 }
 
-// Maximum of three values
-int WLevDistance::Max3( int x, int y, int z )
-{
-if ( x > y )
-return std::max(x, z);
-else
-return std::max(y, z);
-}
-
 // initialize data from CTOR
 void WLevDistance::InitData( const sal_Unicode* cPattern )
 {
diff --git a/i18npool/source/search/levdis.hxx 
b/i18npool

[Libreoffice-commits] core.git: i18npool/source sc/source

2020-01-30 Thread Eike Rathke (via logerrit)
 i18npool/source/search/textsearch.cxx |2 +-
 sc/source/core/tool/interpr1.cxx  |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit f4f30276eab58e13f99d9a6446032e389caf8ae2
Author: Eike Rathke 
AuthorDate: Thu Jan 30 17:15:01 2020 +0100
Commit: Eike Rathke 
CommitDate: Thu Jan 30 17:22:51 2020 +0100

Update ICU RegexMatcher::setTimeLimit() documentation link to new location

Stumbled upon in a side step of grepping for icu4c.

Change-Id: I3f9cda5239e265258c7dc7a6a0689b3bc5f052ac

diff --git a/i18npool/source/search/textsearch.cxx 
b/i18npool/source/search/textsearch.cxx
index de0f74ad2cb9..964dc6c0b256 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -879,7 +879,7 @@ void TextSearch::RESrchPrepare( const 
css::util::SearchOptions2& rOptions)
 // Pathological patterns may result in exponential run time making the
 // application appear to be frozen. Limit that. Documentation for this
 // call says
-// 
https://ssl.icu-project.org/apiref/icu4c/classicu_1_1RegexMatcher.html#a6ebcfcab4fe6a38678c0291643a03a00
+// 
https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1RegexMatcher.html#a6ebcfcab4fe6a38678c0291643a03a00
 // "The units of the limit are steps of the match engine.
 // Correspondence with actual processor time will depend on the speed
 // of the processor and the details of the specific pattern, but will
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 89e7b39786cf..f52ac8916069 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -9424,7 +9424,7 @@ void ScInterpreter::ScRegex()
 return;
 }
 // Guard against pathological patterns, limit steps of engine, see
-// 
https://ssl.icu-project.org/apiref/icu4c/classicu_1_1RegexMatcher.html#a6ebcfcab4fe6a38678c0291643a03a00
+// 
https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1RegexMatcher.html#a6ebcfcab4fe6a38678c0291643a03a00
 aRegexMatcher.setTimeLimit( 23*1000, status);
 
 const icu::UnicodeString aIcuText( reinterpret_cast(aText.getStr()), aText.getLength());
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: i18npool/source sc/source

2017-04-06 Thread Jan-Marek Glogowski
 i18npool/source/collator/gencoll_rule.cxx |5 ++---
 sc/source/ui/view/viewfunc.cxx|5 +++--
 2 files changed, 5 insertions(+), 5 deletions(-)

New commits:
commit 26fb00ec6d8dec52a4ec4c0f194a9da6f310b7e3
Author: Jan-Marek Glogowski 
Date:   Thu Apr 6 16:59:34 2017 +0200

loplugin:useuniqueptr

Change-Id: I1499ea7316811892c014592ef2bb6e431543af1a

diff --git a/i18npool/source/collator/gencoll_rule.cxx 
b/i18npool/source/collator/gencoll_rule.cxx
index 7ca3e935e5f2..7d795b5af079 100644
--- a/i18npool/source/collator/gencoll_rule.cxx
+++ b/i18npool/source/collator/gencoll_rule.cxx
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -112,7 +113,7 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
 //UCollator *coll = ucol_openRules(Obuf.getStr(), Obuf.getLength(), 
UCOL_OFF,
 //UCOL_DEFAULT_STRENGTH, &parseError, &status);
 
-RuleBasedCollator *coll = new RuleBasedCollator(reinterpret_cast(Obuf.getStr()), status);
+auto coll = o3tl::make_unique(reinterpret_cast(Obuf.getStr()), status);
 
 if (U_SUCCESS(status)) {
 std::vector data;
@@ -131,8 +132,6 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
 printf("\nRule parsing error\n");
 }
 
-delete coll;
-
 return U_SUCCESS(status) ? 0 : 1;
 }   // End of main
 
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index ef742edc5478..7d4720bbbad7 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "viewfunc.hxx"
@@ -2663,9 +2664,9 @@ bool ScViewFunc::InsertName( const OUString& rName, const 
OUString& rSymbol,
 ScRangeName* pList = rDoc.GetRangeName();
 
 ScRangeData::Type nType = ScRangeData::Type::Name;
-std::unique_ptr pNewEntry(new ScRangeData(
+auto pNewEntry = o3tl::make_unique(
 &rDoc, rName, rSymbol, ScAddress( GetViewData().GetCurX(),
-GetViewData().GetCurY(), nTab), nType ));
+GetViewData().GetCurY(), nTab), nType );
 OUString aUpType = rType.toAsciiUpperCase();
 if ( aUpType.indexOf( 'P' ) != -1 )
 nType |= ScRangeData::Type::PrintArea;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: i18npool/source sc/source sw/source

2013-10-28 Thread Julien Nabet
 i18npool/source/nativenumber/nativenumbersupplier.cxx |8 
 sc/source/ui/optdlg/tpusrlst.cxx  |2 +-
 sw/source/ui/docvw/srcedtw.cxx|2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

New commits:
commit a3f0eab294df3a48d497c2b985ec9655f2da2357
Author: Julien Nabet 
Date:   Tue Oct 29 07:50:49 2013 +0100

cppcheck: Array index is used before limits check

Change-Id: I51f7408a81a10e2c586cb05b863f20b13bb7b263

diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx 
b/i18npool/source/nativenumber/nativenumbersupplier.cxx
index 382d58c..bf2ff11 100644
--- a/i18npool/source/nativenumber/nativenumbersupplier.cxx
+++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx
@@ -194,7 +194,7 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, 
sal_Int32 startPos, sal_
 srcStr[len++] = str[i];
 } else {
 if (len > 0) {
-if (isSeparator(str[i]) && i < nCount-1 && 
isNumber(str[i+1]))
+if (i < nCount-1 && isSeparator(str[i]) && 
isNumber(str[i+1]))
 continue; // skip comma inside number string
 sal_Bool notZero = sal_False;
 for (sal_Int32 begin = 0, end = len % 
number->multiplierExponent[0];
@@ -224,11 +224,11 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, 
sal_Int32 startPos, sal_
 len = 0;
 }
 if (i < nCount) {
-if ((doDecimal = (!doDecimal && isDecimal(str[i]) && i < 
nCount-1 && isNumber(str[i+1]))) != sal_False)
+if ((doDecimal = (!doDecimal && i < nCount-1 && 
isDecimal(str[i]) && isNumber(str[i+1]))) != sal_False)
 newStr[count] = (DecimalChar[number->number] ? 
DecimalChar[number->number] : str[i]);
-else if (isMinus(str[i]) && i < nCount-1 && 
isNumber(str[i+1]))
+else if (i < nCount-1 && isMinus(str[i]) && 
isNumber(str[i+1]))
 newStr[count] = (MinusChar[number->number] ? 
MinusChar[number->number] : str[i]);
-else if (isSeparator(str[i]) && i < nCount-1 && 
isNumber(str[i+1]))
+else if (i < nCount-1 && isSeparator(str[i]) && 
isNumber(str[i+1]))
 newStr[count] = (SeparatorChar[number->number] ? 
SeparatorChar[number->number] : str[i]);
 else
 newStr[count] = str[i];
diff --git a/sc/source/ui/optdlg/tpusrlst.cxx b/sc/source/ui/optdlg/tpusrlst.cxx
index c19e7bd..5fcb9bf 100644
--- a/sc/source/ui/optdlg/tpusrlst.cxx
+++ b/sc/source/ui/optdlg/tpusrlst.cxx
@@ -339,7 +339,7 @@ void ScTpUserLists::MakeListStr( OUString& rListStr )
 {
 rListStr += OUString(aStr[c]);
 
-while ( (aStr[c] == cDelimiter) && (c < nLen) )
+while ( (c < nLen) && (aStr[c] == cDelimiter) )
 c++;
 }
 }
diff --git a/sw/source/ui/docvw/srcedtw.cxx b/sw/source/ui/docvw/srcedtw.cxx
index 7d3f42b..46435db 100644
--- a/sw/source/ui/docvw/srcedtw.cxx
+++ b/sw/source/ui/docvw/srcedtw.cxx
@@ -82,7 +82,7 @@ static void lcl_Highlight(const OUString& rSource, 
SwTextPortions& aPortionList)
 while(nActPos < nStrLen)
 {
 svtools::ColorConfigEntry eFoundType = svtools::HTMLUNKNOWN;
-if(rSource[nActPos] == cOpenBracket && nActPos < nStrLen - 2 )
+if((nActPos < nStrLen - 2) && (rSource[nActPos] == cOpenBracket))
 {
 // insert 'empty' portion
 if(nPortEnd < nActPos - 1 )
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits