diff options
Diffstat (limited to 'bitbake/lib/bb/parse/parse_c/token.h')
-rw-r--r-- | bitbake/lib/bb/parse/parse_c/token.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/bitbake/lib/bb/parse/parse_c/token.h b/bitbake/lib/bb/parse/parse_c/token.h new file mode 100644 index 0000000000..2351fda6b5 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_c/token.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | Copyright (C) 2005 Holger Hans Peter Freyther | ||
3 | |||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
5 | of this software and associated documentation files (the "Software"), to deal | ||
6 | in the Software without restriction, including without limitation the rights | ||
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
8 | copies of the Software, and to permit persons to whom the Software is | ||
9 | furnished to do so, subject to the following conditions: | ||
10 | |||
11 | The above copyright notice and this permission notice shall be included in all | ||
12 | copies or substantial portions of the Software. | ||
13 | |||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
17 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
18 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
19 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | ||
20 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | */ | ||
23 | |||
24 | #ifndef TOKEN_H | ||
25 | #define TOKEN_H | ||
26 | |||
27 | #define PURE_METHOD | ||
28 | |||
29 | struct token_t { | ||
30 | const char* string()const PURE_METHOD; | ||
31 | |||
32 | static char* concatString(const char* l, const char* r); | ||
33 | void assignString(const char* str); | ||
34 | void copyString(const char* str); | ||
35 | |||
36 | void release_this(); | ||
37 | |||
38 | private: | ||
39 | char *m_string; | ||
40 | size_t m_stringLen; | ||
41 | }; | ||
42 | |||
43 | inline const char* token_t::string()const | ||
44 | { | ||
45 | return m_string; | ||
46 | } | ||
47 | |||
48 | /* | ||
49 | * append str to the current string | ||
50 | */ | ||
51 | inline char* token_t::concatString(const char* l, const char* r) | ||
52 | { | ||
53 | size_t cb = (l ? strlen (l) : 0) + strlen (r) + 1; | ||
54 | r_sz = new char[cb]; | ||
55 | *r_sz = 0; | ||
56 | if (l) strcat (r_sz, l); | ||
57 | strcat (r_sz, r); | ||
58 | |||
59 | return r_sz; | ||
60 | } | ||
61 | |||
62 | inline void token_t::assignString(const char* str) | ||
63 | { | ||
64 | m_string = str; | ||
65 | m_stringLen = str ? strlen(str) : 0; | ||
66 | } | ||
67 | |||
68 | inline void token_t::copyString(const char* str) | ||
69 | { | ||
70 | if( str ) { | ||
71 | m_stringLen = strlen(str); | ||
72 | m_string = new char[m_stringLen+1]; | ||
73 | strcpy(m_string, str) | ||
74 | } | ||
75 | } | ||
76 | |||
77 | inline void token_t::release_this() | ||
78 | { | ||
79 | delete m_string; | ||
80 | m_string = 0; | ||
81 | } | ||
82 | |||
83 | #endif | ||