-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// SMESH Driver : implementaion of driver for reading and writing
+// SMESH Driver : implementation of driver for reading and writing
// File : Mesh_Reader.cxx
// Module : SMESH
//
#include "SMESH_Comment.hxx"
+//#define _DEBUG_
#include <utilities.h>
using namespace std;
}
return SMESH_ComputeError::New( myStatus == DRS_OK ? int(COMPERR_OK) : int(myStatus), msg );
}
+
+//================================================================================
+/*!
+ * \brief Assure a string is UTF-8 valid by replacing invalid chars
+ */
+//================================================================================
+
+std::string Driver_Mesh::fixUTF8(const std::string & str )
+{
+ std::string fixed = str;
+ const unsigned char* s = reinterpret_cast<const unsigned char* >( fixed.data() );
+
+ for ( size_t i = 0; i < fixed.size(); ++i )
+ {
+ if ( s[i] < 128 )
+ continue; // latin
+
+ bool invalid = false;
+
+ // how many bytes follow?
+ int len = 0;
+ if (s[i] >> 5 == 0b110 ) len = 1; // WARNING: binary constants included in C++14
+ else if (s[i] >> 4 == 0b1110 ) len = 2;
+ else if (s[i] >> 3 == 0b11110) len = 3;
+ else
+ invalid = true;
+
+ // check the bytes
+ for ( int j = 0; j < len && !invalid; ++j )
+ invalid = ( s[i+j+1] >> 6 != 0b10 );
+
+ if ( invalid )
+ fixed[i] = '?';
+ else
+ i += len;
+ }
+ return fixed;
+}