X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmUtil.cxx;h=ebb8191d56b9cba8ba022c84109a29df7af67a4b;hb=refs%2Ftags%2FVersion0.6.bp;hp=889ece2064d22206fc35856c25f818fdfc714f56;hpb=8479d585fdf6fde5e21127cfd1d68227179c5f3f;p=gdcm.git diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 889ece20..ebb8191d 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2004/10/28 23:10:25 $ - Version: $Revision: 1.58 $ + Date: $Date: 2004/11/05 20:23:14 $ + Version: $Revision: 1.60 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -168,7 +168,7 @@ std::string Util::GetPath(std::string const & fullName) } /** - * \ingroup Globals + * \ingroup Util * \brief Get the (last) name of a full path file name * @param fullName file/directory name to extract end name from */ @@ -189,6 +189,39 @@ std::string Util::GetName(std::string const & fullName) } } +/** + * \ingroup Util + * \brief Create a /DICOM/ string: + * It should a of even lenght (no odd length ever) + * It can contains as many \0 as you want. + * This function is similar to DicomString(const char*), + * except it doesn't take a lenght. + * It only pad with a null character if length is odd + */ +std::string Util::DicomString(const char* s) +{ + size_t l = strlen(s); + if( l%2 ) + { + l++; + } + std::string r(s, s+l); + assert( !(r.size() % 2) ); + return r; +} + +/** + * \ingroup Util + * \brief Create a /DICOM/ string: + * It should a of even length (no odd length ever) + * It can contains as many \0 as you want. + */ +std::string Util::DicomString(const char* s, size_t l) +{ + std::string r(s, s+l); + assert( !(r.size() % 2) ); + return r; +} template std::ostream& binary_write(std::ostream& os, const T& val) @@ -225,6 +258,11 @@ std::ostream& binary_write(std::ostream& os, const char* val) return os.write(val, strlen(val)); } +std::ostream& binary_write(std::ostream& os, std::string const & val) +{ + return os.write(val.c_str(), val.size()); +} + } // end namespace gdcm