From fdef606b4607dcc6c589227fd0fc5ab0fd4eebec Mon Sep 17 00:00:00 2001 From: quietly turning Date: Fri, 4 Sep 2020 15:41:33 -0400 Subject: [PATCH] expose RageUtil's BinaryToHex to Lua The hashing functions that CryptManger currently exposes to Lua return hash strings formatted in binary. Themes using those hash functions may want to compare hex strings. RageUtil already had a BinaryToHex utility; this commit exposes it as a global function, following along with other utility functions in RageUtil. --- src/RageUtil.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index 445f4a776d..71cdef73a9 100644 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -218,7 +218,7 @@ bool IsHexVal( const RString &s ) return false; for( size_t i=0; i < s.size(); ++i ) - if( !(s[i] >= '0' && s[i] <= '9') && + if( !(s[i] >= '0' && s[i] <= '9') && !(toupper(s[i]) >= 'A' && toupper(s[i]) <= 'F')) return false; @@ -339,7 +339,7 @@ RString PrettyPercent( float fNumerator, float fDenominator) return ssprintf("%0.2f%%",fNumerator/fDenominator*100); } -RString Commify( int iNum ) +RString Commify( int iNum ) { RString sNum = ssprintf("%d",iNum); return Commify( sNum ); @@ -494,7 +494,7 @@ RString vssprintf( const char *szFormat, va_list argList ) /* OK */ sStr.assign(buf, used); } - + delete [] buf; if (used != -1) { @@ -956,9 +956,9 @@ void splitpath( const RString &sPath, RString &sDir, RString &sFilename, RString vector asMatches; /* - * One level of escapes for the regex, one for C. Ew. + * One level of escapes for the regex, one for C. Ew. * This is really: - * ^(.*[\\/])?(.*)$ + * ^(.*[\\/])?(.*)$ */ static Regex sep("^(.*[\\\\/])?(.*)$"); bool bCheck = sep.Compare( sPath, asMatches ); @@ -1248,10 +1248,10 @@ float calc_stddev( const float *pStart, const float *pEnd, bool bSample ) bool CalcLeastSquares( const vector< pair > &vCoordinates, float &fSlope, float &fIntercept, float &fError ) { - if( vCoordinates.empty() ) + if( vCoordinates.empty() ) return false; float fSumXX = 0.0f, fSumXY = 0.0f, fSumX = 0.0f, fSumY = 0.0f; - for( unsigned i = 0; i < vCoordinates.size(); ++i ) + for( unsigned i = 0; i < vCoordinates.size(); ++i ) { fSumXX += vCoordinates[i].first * vCoordinates[i].first; fSumXY += vCoordinates[i].first * vCoordinates[i].second; @@ -1263,7 +1263,7 @@ bool CalcLeastSquares( const vector< pair > &vCoordinates, fIntercept = (fSumXX * fSumY - fSumX * fSumXY) / fDenominator; fError = 0.0f; - for( unsigned i = 0; i < vCoordinates.size(); ++i ) + for( unsigned i = 0; i < vCoordinates.size(); ++i ) { const float fOneError = fIntercept + fSlope * vCoordinates[i].first - vCoordinates[i].second; fError += fOneError * fOneError; @@ -1916,7 +1916,7 @@ wstring RStringToWstring( const RString &s ) ++start; continue; } - + wchar_t ch = L'\0'; if( !utf8_to_wchar( s.data(), s.size(), start, ch ) ) ch = INVALID_CHAR; @@ -2149,13 +2149,13 @@ RString Dirname( const RString &dir ) return dir.substr(0, pos+1); } -RString Capitalize( const RString &s ) +RString Capitalize( const RString &s ) { if( s.empty() ) return RString(); char *buf = const_cast(s.c_str()); - + UnicodeDoUpper( buf, s.size(), g_UpperCase ); return buf; @@ -2285,7 +2285,7 @@ void CollapsePath( RString &sPath, bool bRemoveLeadingDot ) sOut.append( sPath, iPos, iNext-iPos ); } - + sOut.swap( sPath ); } @@ -2436,6 +2436,7 @@ LuaFunction( URLEncode, URLEncode( SArg(1) ) ); LuaFunction( PrettyPercent, PrettyPercent( FArg(1), FArg(2) ) ); //LuaFunction( IsHexVal, IsHexVal( SArg(1) ) ); LuaFunction( lerp, lerp(FArg(1), FArg(2), FArg(3)) ); +LuaFunction( BinaryToHex, BinaryToHex( SArg(1) ) ); int LuaFunc_commify(lua_State* L); int LuaFunc_commify(lua_State* L)