[Dcmlib] String comparison

Mathieu Malaterre mathieu.malaterre at kitware.com
Mon Nov 15 02:37:46 CET 2004


Hello,

   I have written a new function in gdcmUtil (*) -not merged in yet-, to take care of Dennis' request. I wanted to keep things as simple as possible, for efficiency mainly. Also this is now isolated in one function thus later we can change the behavior, declaring the DICOM not valid, when a string is not padded with null character (but space).

Let me know what you think. I'd like to commit this one on Monday.

Mathieu

/**
 * \ingroup Util
 * \brief Safely compare two Dicom String:
 *        - Both string should be of even lenght
 *        - We allow padding of even lenght string by either a null
 *          character of a space
 */
bool Util::DicomStringEqual(const std::string& s1, const char *s2)
{
  // s2 is the string from the DICOM reference: 'MONOCHROME1'
  std::string s1_even = s1; //Never change input parameter
  std::string s2_even = DicomString( s2 );
  if( s1_even[s1_even.size()-1] == ' ')
  {
    s1_even[s1_even.size()-1] = '\0'; //replace space character by null
  }
  return s1_even == s2_even;
}








More information about the Dcmlib mailing list