Statistics
| Branch: | Revision:

root / src / common / fnamelisttokenizer.h @ e1750c09

History | View | Annotate | Download (2.25 KB)

1
//==========================================================================
2
//  FNAMELISTTOKENIZER.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//==========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16

    
17
#ifndef __FNAMELISTTOKENIZER_H
18
#define __FNAMELISTTOKENIZER_H
19

    
20
#include <string>
21
#include <vector>
22
#include "commondefs.h"
23
#include "commonutil.h"
24

    
25
NAMESPACE_BEGIN
26

    
27

    
28
/**
29
 * A string tokenizer class which honors quotation marks but not
30
 * backslashes. It is designed to split up filename lists returned by
31
 * cInifile::getAsFilenames().
32
 *
33
 * It considers the string as consisting of tokens separated by tab or space
34
 * characters. If a token contains space or tab ("C:\Program Files\X"),
35
 * it has to be surrounded with quotation marks. A token may NOT contain
36
 * quotation marks. (Rationale: filenames do not contain quotes but they
37
 * may well contain backslashes, so interpreting backslashes would not be
38
 * very practical.)
39
 */
40
class COMMON_API FilenamesListTokenizer
41
{
42
  private:
43
    char *str; // copy of full string (will be corrupted during tokenization)
44
    char *rest; // rest of string (to be tokenized)
45

    
46
  public:
47
    /**
48
     * Constructor. The class will make its own copy of the input string.
49
     */
50
    FilenamesListTokenizer(const char *str);
51

    
52
    /**
53
     * Destructor.
54
     */
55
    ~FilenamesListTokenizer();
56

    
57
    /**
58
     * Returns true if there're more tokens (i.e. the next nextToken()
59
     * call won't return NULL).
60
     */
61
    bool hasMoreTokens();
62

    
63
    /**
64
     * Returns the next token. The returned pointers will stay valid as long
65
     * as the tokenizer object exists. If there're no more tokens,
66
     * a NULL pointer will be returned.
67
     */
68
    const char *nextToken();
69

    
70
    /**
71
     * Utility function: tokenizes the full input string at once, and
72
     * returns the tokens in a string vector.
73
     */
74
    std::vector<std::string> asVector();
75
};
76

    
77
NAMESPACE_END
78

    
79

    
80
#endif
81