]> Creatis software - gdcm.git/blobdiff - src/gdcmDocument.cxx
ADD : gdcmGlobal::CountSubstring method
[gdcm.git] / src / gdcmDocument.cxx
index 7acd21ae7b02260ec465f35d3e1dcc6f81b7928a..71312ce5ce2b6bab3c66efceca65e65559e5e349 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/31 14:24:47 $
-  Version:   $Revision: 1.69 $
+  Date:      $Date: 2004/09/07 13:57:04 $
+  Version:   $Revision: 1.71 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -588,8 +588,8 @@ gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
                                          uint16_t elem )
 {
    gdcmValEntry* valEntry = 0;
-
    gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem);
+   
    if (!currentEntry)
    {
       // The entry wasn't present and we simply create the required ValEntry:
@@ -721,9 +721,9 @@ bool gdcmDocument::ReplaceIfExistByNumber(std::string const & value,
  * \brief   Checks if a given Dicom Element exists within the H table
  * @param   group      Group number of the searched Dicom Element 
  * @param   element  Element number of the searched Dicom Element 
- * @return  number of occurences
+ * @return true is found
  */
-int gdcmDocument::CheckIfEntryExistByNumber(uint16_t group, uint16_t element )
+bool gdcmDocument::CheckIfEntryExistByNumber(uint16_t group, uint16_t element )
 {
    const std::string &key = gdcmDictEntry::TranslateToKey(group, element );
    return TagHT.count(key);
@@ -887,11 +887,13 @@ bool gdcmDocument::SetEntryByNumber(std::string const & content,
    gdcmVRKey vr = valEntry->GetVR();
    if( vr == "US" || vr == "SS" )
    {
-      valEntry->SetLength(2);
+      int c = CountSubstring(content, "\\"); // for multivaluated items
+      valEntry->SetLength((c+1)*2);
    }
    else if( vr == "UL" || vr == "SL" )
    {
-      valEntry->SetLength(4);
+      int c = CountSubstring(content, "\\"); // for multivaluated items
+      valEntry->SetLength((c+1)*4);
    }
    else
    {