]> Creatis software - gdcm.git/blobdiff - src/gdcmUtil.cxx
COMP: People really don't know what is the difference between cstring and char*
[gdcm.git] / src / gdcmUtil.cxx
index bf200b0d212847dceaf3fdba5c7851194af7e85e..224c9d5d84df101fb044e01bb41a54569d4bbf02 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/31 16:24:19 $
+  Version:   $Revision: 1.162 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -179,10 +179,46 @@ 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 area to check (uint8_t is just for prototyping. feel free to cast)
+ * @param l area length 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)
- * @param s string to remove non printable characters from
+ * @param s string to check (uint8_t is just for prototyping. feel free to cast)
  */
 std::string Util::CreateCleanString(std::string const &s)
 {
@@ -210,6 +246,31 @@ 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 area to process (uint8_t is just for prototyping. feel free to cast)
+ * @param l area length to check
+ */
+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