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