Nantes Université

Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 478f74d8 rédigé par qykth-git's avatar qykth-git Validation de GitHub
Parcourir les fichiers

Multi byte char support for non-ASCII path name (#65)

* Use "L" notation for wide character

* Remove unneeded cast

PrintMessage() now uses const pointer

* C++11 accepts std::string for std::wifstream

* C++11 accepts std::string for std::wifstream

* Use mbstowcs()/wcstombs() to convert character class

This fix works when file path includes non-ASCII characters.

* Revert "Use mbstowcs()/wcstombs() to convert character class"

This reverts commit 7fd150a1570b8d6de246da352688daaeadcda998.

mbstowcs()/wcstombs() is not so secure, and recommends mbstowcs_s()/wcstombs_s().
But these secure variants are not supported by some C libraries.
parent 271bf4f3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -88,7 +88,7 @@ bool parseArg( wchar_t* text, CModelData& modelData )
// every argument is at least two char long and first character is '/' or '-'
if( wcslen( text ) < 2 || ( text[ 0 ] != L'/' && text[ 0 ] != L'-' ) )
{
PrintMessage( InputDataError, (wchar_t*) UNKNOWN_OPTION_MSG, text );
PrintMessage( InputDataError, UNKNOWN_OPTION_MSG, text );
return( false );
}
......@@ -100,7 +100,7 @@ bool parseArg( wchar_t* text, CModelData& modelData )
wstring opt = L"'";
opt += currentArg;
opt += L"'";
PrintMessage( InputDataError, L"Option", (wchar_t*) opt.c_str(), L"was provided more than once" );
PrintMessage( InputDataError, L"Option", opt.c_str(), L"was provided more than once" );
return( false );
}
......@@ -274,7 +274,7 @@ bool parseArg( wchar_t* text, CModelData& modelData )
if( unknownOption )
{
PrintMessage( InputDataError, (wchar_t*) UNKNOWN_OPTION_MSG, text );
PrintMessage( InputDataError, UNKNOWN_OPTION_MSG, text );
return( false );
}
else
......
......@@ -89,7 +89,7 @@ ErrorCode GcdRunner::generateResults( IN CModelData& modelData, IN bool justNega
wstring msg = L"Internal error\n";
msg += L"As a workaround run the tool with parameter /r a few times and see if any of the iterations produces a result.\n";
msg += L"If the result is produced, it is guaranteed to be valid and it is safe to use.";
PrintMessage( GcdError, (wchar_t*) msg.data() );
PrintMessage( GcdError, msg.data() );
break;
}
#ifdef _DEBUG
......@@ -183,4 +183,4 @@ ErrorCode GcdRunner::Generate()
return( ErrorCode::ErrorCode_Success );
}
}
\ No newline at end of file
}
......@@ -249,7 +249,7 @@ void ConstraintsInterpreter::interpretTerm( IN CTerm* term, OUT CGcdExclusions&
if ( ! oneSatifies || allSatisfy )
{
wstring s = L"All or no values satisfy relation ";
s += (wchar_t*) (term->RawText).c_str();
s += (term->RawText).c_str();
_warnings.push_back( s );
}
......@@ -508,7 +508,7 @@ bool ConstraintsInterpreter::ConvertToExclusions( OUT CGcdExclusions& gcdExclusi
catch( CSyntaxError e )
{
wstring text = getConstraintTextForContext( _modelData.ConstraintPredicates, e.ErrAtPosition );
wchar_t* failureContext = (wchar_t*) text.c_str();
const wchar_t* failureContext = text.c_str();
// print message
switch( (SyntaxErrorType) e.Type )
......@@ -577,7 +577,7 @@ bool ConstraintsInterpreter::ConvertToExclusions( OUT CGcdExclusions& gcdExclusi
case ValidationWarnType::UnknownParameter:
{
wstring constraintText = _modelData.GetConstraintText( warning.ErrInConstraint );
wchar_t* failureContext = (wchar_t*) ( constraintText.c_str() );
const wchar_t* failureContext = constraintText.c_str();
PrintMessage( ConstraintsWarning, L"Constraint", failureContext, L"contains unknown parameter. Skipping..." );
break;
}
......@@ -592,7 +592,7 @@ bool ConstraintsInterpreter::ConvertToExclusions( OUT CGcdExclusions& gcdExclusi
catch( CErrValidation e )
{
wstring constraintText = _modelData.GetConstraintText( e.ErrInConstraint );
wchar_t* failureContext = (wchar_t*) ( constraintText.c_str() );
const wchar_t* failureContext = constraintText.c_str();
switch( e.Type )
{
......
......@@ -39,7 +39,7 @@ bool CGcdData::CheckEntireParameterExcluded()
wstring param = L"'" + found->Name + L"'";
PrintMessage( InputDataError, L"Too restrictive constraints. All values of parameter",
(wchar_t*) param.c_str(), L"got excluded." );
param.c_str(), L"got excluded." );
return( true );
}
}
......@@ -383,12 +383,12 @@ void CResult::PrintConstraintWarnings()
{
text += L"\n " + item;
}
PrintMessage( ConstraintsWarning, (wchar_t*) text.c_str() );
PrintMessage( ConstraintsWarning, text.c_str() );
}
for( auto & warn : SolverWarnings )
{
PrintMessage( ConstraintsWarning, (wchar_t*) warn.c_str() );
PrintMessage( ConstraintsWarning, warn.c_str() );
}
}
......
......@@ -220,7 +220,7 @@ bool CModelData::ValidateRowSeeds()
if( ( param.Name ).empty() || ( param.Name ).find( RESULT_DELIMITER ) != wstring::npos )
{
PrintMessage( RowSeedsWarning, L"Name of parameter",
(wchar_t*) param.Name.data(),
param.Name.data(),
L"is blank or contains a tab character. Seeding may not work properly." );
}
......@@ -231,7 +231,7 @@ bool CModelData::ValidateRowSeeds()
if( name.empty() || name.find( RESULT_DELIMITER ) != wstring::npos )
{
PrintMessage( RowSeedsWarning, L"Value",
(wchar_t*) value.GetPrimaryName().data(),
value.GetPrimaryName().data(),
L"or one of its names is blank or contains a tab character. Seeding may not work properly." );
}
}
......@@ -240,7 +240,7 @@ bool CModelData::ValidateRowSeeds()
if( !param.ValueNamesUnique( this->CaseSensitive ) )
{
PrintMessage( RowSeedsWarning, L"Values of the parameter",
(wchar_t*) param.Name.data(),
param.Name.data(),
L"are not unique. Seeding may not work properly." );
}
}
......
......@@ -106,7 +106,7 @@ bool readLineFromFile( wifstream& file, wstring& line )
file.get( c );
if( file.eof()
|| c == L'\n'
|| c == 0 ) return( true );
|| c == L'\0' ) return( true );
line += c;
}
return( true );
......@@ -127,7 +127,7 @@ bool CModelData::readParameter( wstring& line )
paramSep = line.find( ValuesDelim );
if( paramSep == wstring::npos )
{
PrintMessage( InputDataError, L"Parameter", (wchar_t*) line.c_str(), L"should have at least one value defined" );
PrintMessage( InputDataError, L"Parameter", line.c_str(), L"should have at least one value defined" );
return( false );
}
}
......@@ -286,7 +286,7 @@ bool CModelData::readParamSet( wstring& line )
wstring::iterator begin = findFirstNonWhitespace( next, line.end() );
if( begin == line.end() || *begin != SET_BEGIN )
{
PrintMessage( InputDataError, (wchar_t*) STD_MSG.data() );
PrintMessage( InputDataError, STD_MSG.data() );
return( false );
}
++begin;
......@@ -296,7 +296,7 @@ bool CModelData::readParamSet( wstring& line )
end = find( begin, line.end(), SET_END );
if ( end == line.end() )
{
PrintMessage( InputDataError, (wchar_t*) STD_MSG.data() );
PrintMessage( InputDataError, STD_MSG.data() );
return( false );
}
......@@ -306,7 +306,7 @@ bool CModelData::readParamSet( wstring& line )
setp = trim( setp );
if ( setp.empty() )
{
PrintMessage( InputDataError, (wchar_t*) STD_MSG.data() );
PrintMessage( InputDataError, STD_MSG.data() );
return( false );
}
......@@ -335,7 +335,7 @@ bool CModelData::readParamSet( wstring& line )
getUnmatchedParameterNames( setParams, unmatched );
if( !unmatched.empty() )
{
PrintMessage( InputDataWarning, L"Submodel defintion", (wchar_t*) trim( line ).data(), L"contains unknown parameter. Skipping..." );
PrintMessage( InputDataWarning, L"Submodel defintion", trim( line ).data(), L"contains unknown parameter. Skipping..." );
return( true ); // just a warning so don't exit
}
}
......@@ -345,7 +345,7 @@ bool CModelData::readParamSet( wstring& line )
wstrings::iterator newEnd = unique( setParams.begin(), setParams.end(), stringCaseInsensitiveEquals );
if( setParams.end() != newEnd )
{
PrintMessage( InputDataWarning, L"Submodel defintion", (wchar_t*) trim( line ).data(), L"contains duplicate parameters. Removing duplicates..." );
PrintMessage( InputDataWarning, L"Submodel defintion", trim( line ).data(), L"contains duplicate parameters. Removing duplicates..." );
setParams.erase( newEnd, setParams.end() );
}
......@@ -378,7 +378,7 @@ bool CModelData::readParamSet( wstring& line )
// anything other than @, quit
if ( at != line.end() && *at != SET_ORDER )
{
PrintMessage( InputDataError, (wchar_t*) STD_MSG.data() );
PrintMessage( InputDataError, STD_MSG.data() );
return( false );
}
......@@ -410,7 +410,7 @@ bool CModelData::readParamSet( wstring& line )
}
if ( !ret )
{
PrintMessage( InputDataError, (wchar_t*) STD_MSG.data() );
PrintMessage( InputDataError, STD_MSG.data() );
return( false );
}
......@@ -429,10 +429,10 @@ bool CModelData::readModel( const wstring& filePath )
{
// Some implementations of wifstream only allow ANSI strings as file names so converting before using
string ansiFilePath = wideCharToAnsi( filePath );
wifstream file( ansiFilePath.c_str() );
wifstream file( ansiFilePath );
if ( !file )
{
PrintMessage( InputDataError, L"Couldn't open file:", (wchar_t*)filePath.data() );
PrintMessage( InputDataError, L"Couldn't open file:", filePath.data() );
return( false );
}
......@@ -530,10 +530,10 @@ bool CModelData::ReadRowSeedFile( const wstring& filePath )
// Some implementations of wifstream only allow ANSI strings as file names so converting before using
string ansiFilePath = wideCharToAnsi( filePath );
wifstream file( ansiFilePath.c_str() );
wifstream file( ansiFilePath );
if ( !file )
{
PrintMessage( InputDataError, L"Couldn't open file:", (wchar_t*)filePath.data() );
PrintMessage( InputDataError, L"Couldn't open file:", filePath.data() );
return( false );
}
wstring line;
......@@ -574,7 +574,7 @@ bool CModelData::ReadRowSeedFile( const wstring& filePath )
if ( found == Parameters.end())
{
PrintMessage( RowSeedsWarning, L"Parameter",
(wchar_t*) param.data(),
param.data(),
L"not found in the model. Skipping..." );
}
parameters.push_back( found );
......@@ -619,7 +619,7 @@ bool CModelData::ReadRowSeedFile( const wstring& filePath )
if ( ! i_value->empty() )
{
PrintMessage( RowSeedsWarning, L"Value",
(wchar_t*) i_value->data(),
i_value->data(),
L"not found in the model. Skipping this value..." );
}
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter