Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:12

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4Tokenizer
0027 //
0028 // Class description:
0029 //
0030 // String tokenizer.
0031 // It derives from the implementation of the Rogue Wave RWTokenizer.
0032 // It intrinsically uses STL string.
0033 
0034 // Author: G.Cosmo, 11 October 2001
0035 // --------------------------------------------------------------------
0036 #ifndef G4Tokenizer_hh
0037 #define G4Tokenizer_hh 1
0038 
0039 #include "G4String.hh"
0040 
0041 class G4Tokenizer
0042 {
0043  public:
0044   G4Tokenizer(const G4String& stn)
0045     : string2tokenize(stn)
0046     , actual(0)
0047   {}
0048 
0049   G4String operator()(const char* str = " \t\n", std::size_t l = 0)
0050   {
0051     std::size_t i, j, tmp;
0052     G4bool hasws = false;
0053     if(l == 0)
0054       l = strlen(str);
0055 
0056     // Skip leading delimeters
0057     while(actual < string2tokenize.size())
0058     {
0059       for(i = 0; i < l; ++i)
0060       {
0061         if(string2tokenize[(G4int)actual] == str[i])
0062           hasws = true;
0063       }
0064       if(hasws)
0065       {
0066         ++actual;
0067         hasws = false;
0068       }
0069       else
0070         break;
0071     }
0072 
0073     for(j = actual; j < string2tokenize.size(); ++j)
0074     {
0075       for(i = 0; i < l; ++i)
0076         if(string2tokenize[(G4int)j] == str[i])
0077           break;
0078       if(i < l)
0079         break;
0080     }
0081     if(j != string2tokenize.size())
0082     {
0083       tmp    = actual;
0084       actual = j + 1;
0085       return string2tokenize.substr(tmp, j - tmp);
0086     }
0087     else
0088     {
0089       tmp    = actual;
0090       actual = j;
0091       return string2tokenize.substr(tmp, j - tmp);
0092     }
0093   }
0094 
0095  private:
0096   G4String string2tokenize;
0097   std::size_t actual;
0098 };
0099 
0100 #endif