]> Creatis software - gdcm.git/commitdiff
Add methods to check the 'printability' of a bin area
authorjpr <jpr>
Thu, 25 Aug 2005 14:55:47 +0000 (14:55 +0000)
committerjpr <jpr>
Thu, 25 Aug 2005 14:55:47 +0000 (14:55 +0000)
src/gdcmUtil.cxx
src/gdcmUtil.h

index bf200b0d212847dceaf3fdba5c7851194af7e85e..b9db1c163a03d4abef26bf7c724c6c1e7d632a3f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/08/22 16:17:54 $
-  Version:   $Revision: 1.159 $
+  Date:      $Date: 2005/08/25 14:55:47 $
+  Version:   $Revision: 1.160 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -179,6 +179,41 @@ int Util::CountSubstring (const std::string &str,
    return count;
 }
 
+/**
+ * \brief  Checks whether a 'string' is printable or not (in order
+ *         to avoid corrupting the terminal of invocation when printing)
+ * @param s string to check
+ */
+bool Util::IsCleanString(std::string const &s)
+{
+  std::cout<< std::endl << s << std::endl;
+   for(unsigned int i=0; i<s.size(); i++)
+   {
+      std::cout<< std::endl << i << " : " << (unsigned char)s[i] << std::endl;
+      if (!isprint((unsigned char)s[i]) )
+      {
+         return false;
+      }
+   }
+return true;   
+}
+
+/**
+ * \brief  Checks whether an 'area' is printable or not (in order
+ *         to avoid corrupting the terminal of invocation when printing)
+ * @param s string to check
+ */
+bool Util::IsCleanArea(uint8_t *s, int l)
+{
+   for( int i=0; i<l; i++)
+   {
+      if (!isprint((unsigned char)s[i]) )
+      {
+         return false;
+      }
+   }
+   return true;   
+}
 /**
  * \brief  Weed out a string from the non-printable characters (in order
  *         to avoid corrupting the terminal of invocation when printing)
@@ -210,6 +245,30 @@ std::string Util::CreateCleanString(std::string const &s)
    return str;
 }
 
+/**
+ * \brief  Weed out a string from the non-printable characters (in order
+ *         to avoid corrupting the terminal of invocation when printing)
+ * @param s string to remove non printable characters from
+ */
+std::string Util::CreateCleanString(uint8_t *s, int l)
+{
+   std::string str;
+
+   for( int i=0; i<l; i++)
+   {
+      if (!isprint((unsigned char)s[i]) )
+      {
+         str = str + '.';
+      }
+   else
+      {
+         str = str + (char )s[i];
+      }
+   }
+
+
+   return str;
+}
 /**
  * \brief   Add a SEPARATOR to the end of the name is necessary
  * @param   pathname file/directory name to normalize 
index c26a7d2c59953a328f80d12f0377a7be410bb9d9..592f8b025a90b777e45a644fc127b59e3ed746b1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.h,v $
   Language:  C++
-  Date:      $Date: 2005/08/22 16:17:54 $
-  Version:   $Revision: 1.61 $
+  Date:      $Date: 2005/08/25 14:55:47 $
+  Version:   $Revision: 1.62 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -44,6 +44,9 @@ public:
                                       const std::string &subStr);       
 
    static std::string CreateCleanString(std::string const &s);
+   static std::string CreateCleanString(uint8_t *s, int l);
+   static bool IsCleanString(std::string const &s);
+   static bool IsCleanArea(uint8_t *s, int l);
    static std::string NormalizePath(std::string const &name);
    static std::string GetPath(std::string const &fullName);
    static std::string GetName(std::string const &fullName);