From 71eca9ceca05885c5e1f6dec073b1dcdd7350c47 Mon Sep 17 00:00:00 2001 From: jpr Date: Mon, 1 Oct 2007 09:25:06 +0000 Subject: [PATCH] Add Util::ReplaceSpecChar method. Should be usefull to user that want create directory tree from values of Data Entries --- src/gdcmUtil.cxx | 32 +++++++++++++++++++++++++++----- src/gdcmUtil.h | 10 ++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 23106dc7..c0fd8ced 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:11 $ - Version: $Revision: 1.187 $ + Date: $Date: 2007/10/01 09:25:06 $ + Version: $Revision: 1.188 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -237,7 +237,6 @@ std::string Util::CreateCleanString(std::string const &s) str[i] = '.'; } } - if (str.size() > 0 ) { if (!isprint((unsigned char)s[str.size()-1]) ) @@ -248,9 +247,32 @@ std::string Util::CreateCleanString(std::string const &s) } } } - return str; } +/** + * \brief Replaces all special characters + * @param s string to modify + * @param rep replacement char + */ +void Util::ReplaceSpecChar(std::string &s, std::string &rep) +{ + unsigned int s_size = s.size(); + for(unsigned int i=0; i= '+' && s[i] <= '-') + || (s[i] >= 'a' && s[i] <= 'z') + || (s[i] >= '0' && s[i] <= '9') + || (s[i] >= 'A' && s[i] <= 'Z'))) + { + s.replace(i, 1, rep); + } + } + // deal with Dicom strings trailing '\0' + if(s[s_size-1] == rep.c_str()[0]) + s.erase(s_size-1, 1); +} + /** * \brief Weed out a string from the non-printable characters (in order @@ -1247,7 +1269,7 @@ void Util::hfpswap(double *a, double *b) ghost@aladdin.com */ -/* $Id: gdcmUtil.cxx,v 1.187 2007/05/23 14:18:11 jpr Exp $ */ +/* $Id: gdcmUtil.cxx,v 1.188 2007/10/01 09:25:06 jpr Exp $ */ /* Independent implementation of MD5 (RFC 1321). diff --git a/src/gdcmUtil.h b/src/gdcmUtil.h index 5a53b688..1ac0829f 100644 --- a/src/gdcmUtil.h +++ b/src/gdcmUtil.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.h,v $ Language: C++ - Date: $Date: 2007/08/22 16:14:05 $ - Version: $Revision: 1.69 $ + Date: $Date: 2007/10/01 09:25:06 $ + Version: $Revision: 1.70 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -47,6 +47,7 @@ public: 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 void ReplaceSpecChar(std::string &s, std::string &rep); static std::string NormalizePath(std::string const &name); static std::string GetPath(std::string const &fullName); static std::string GetName(std::string const &fullName); @@ -96,7 +97,8 @@ public: *a = *b; *b = tmp; } - void hfpswap(double *a, double *b); + void hfpswap(double *a, double *b); + static inline void sthifpswap(double *a, double *b) { double tmp; @@ -149,7 +151,7 @@ private: ghost@aladdin.com */ -/* $Id: gdcmUtil.h,v 1.69 2007/08/22 16:14:05 jpr Exp $ */ +/* $Id: gdcmUtil.h,v 1.70 2007/10/01 09:25:06 jpr Exp $ */ /* Independent implementation of MD5 (RFC 1321). This code implements the MD5 Algorithm defined in RFC 1321, whose -- 2.45.1