aboutsummaryrefslogtreecommitdiff
path: root/src/tokenstring.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/tokenstring.h')
-rw-r--r--src/tokenstring.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/tokenstring.h b/src/tokenstring.h
new file mode 100644
index 0000000..25f710b
--- /dev/null
+++ b/src/tokenstring.h
@@ -0,0 +1,120 @@
1/***************************************************************************
2 * Copyright (C) 2003 by Mike Buland *
3 * eichlan@Xagafinelle *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10#ifndef TOKENSTRING_H
11#define TOKENSTRING_H
12
13#include "linkedlist.h"
14
15/** A single tokenized command line. Contains all information necesarry to
16 * nicely access a stand-alone command line and to perform alias expansion
17 * inside of that command line.
18 * When expanding a token, the original command line is left intact, so any
19 * command usng a command line verbatum (getTokenString not getToken) will get
20 * the original, and not the expanded version.
21 * Since indexing into the original command line is also done by token, it
22 * means that using getTokenString( 0 ) will not always get you the first
23 * character of the command line, it will get you the first non-whitespace
24 * character.
25 * Furthermore, when expanding the expantion string is tokenized as well,
26 * but since the original string is unchanged, all tokens that expand any
27 * given index will all retain the same index into the original command line.
28 *@todo Update this to allow it to break on different types of token
29 * delimiters.
30 *@author Mike Buland
31 */
32class TokenString{
33public:
34 /** Automatically call parseLine when created.
35 *@param lpNewTokenString The command line to tokenize
36 *@author Mike Buland
37 */
38 TokenString( const char *lpNewTokenString=NULL );
39 ~TokenString();
40
41 /** Performs a tokenizing parse on the given command line, setting it as
42 * the internal command line for all future tokenizing (excluding
43 * expansion)
44 *@param lpNewTokenString The new command line to set to this object.
45 *@author Mike Buland
46 */
47 void parseLine( const char *lpNewTokenString );
48
49 /** Appends a token to the list of available tokens. This references the
50 * internal pointer to the command line, so no token string must be
51 * specified.
52 *@param nStart The first character of the token to insert.
53 *@param nEnd The last character of the token to insert.
54 *@author Mike Buland
55 */
56 void appendToken( int nStart, int nEnd );
57
58 /** Gets the number of tokens. This is particularly useful post-aliasing
59 * since the number of tokens may not match what is percieved from the
60 * original command line.
61 *@returns The number of available tokens.
62 *@author Mike Buland
63 */
64 int getNumTokens();
65
66 /** Gets a processed token specified by index.
67 *@param nIndex The index of the token to retrieve.
68 *@returns A pointer to the requested token. Please note that these tokens
69 * may not match the original command line.
70 *@author Mike Buland
71 */
72 char *getToken( int nIndex );
73
74 /** Gets the original command line based on tokens. Use this if you want
75 * to perform your own processing on parts of the command line, without
76 * resorting to tokens.
77 * The first character in the returned string will always be
78 * non-whitespace.
79 *@param nIndex The index of the token to start at, zero gets you the whole
80 * command line.
81 *@returns A pointer to the internal original command line string, starting
82 * at the position of the first non-whitespace character of the token
83 * specified.
84 *@author Mike Buland
85 */
86 char *getTokenString( int nIndex=0 );
87
88 /** Expands a token, replacing it with the string lpNewToken, but
89 * processing the new string for tokens before performing the replacement
90 *@param nIndex Which token should be replaced.
91 *@param lpNewToken The string to replace the token with.
92 *@author Mike Buland
93 */
94 void expandTokenTo( int nIndex, char *lpNewToken );
95
96 /** Inserts a token at any position in the command line. This does not
97 * effect the original command line.
98 *@param nStart The start of the token in the string lpNewToken. (inclusive)
99 *@param nEnd The end of the token in the string lpToken. (inclusive)
100 *@param lpOldOrig The pointer to the position in the orginal command
101 * line where this new token should point.
102 *@param lpNewToken The string containing the new token. May contain more
103 * than just one token.
104 *@param nIndex The position to insert the token to.
105 *@author Mike Buland
106 */
107 void insertToken( int nStart, int nEnd, char *lpOldOrig, const char *lpNewToken, int nIndex );
108
109private:
110 char *lpTokenString;
111 LinkedList lToken;
112
113 typedef struct Token
114 {
115 char *lpOrig; // This is just a pointer back to lpTokenString
116 char *lpToken; // This is really a whole token
117 } Token;
118};
119
120#endif