]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/Common/StringFuncs.h
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / C / Common / StringFuncs.h
CommitLineData
97fa0ee9
YL
1/** @file\r
2String routines implementation\r
30fdf114 3\r
f7496d71 4Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
2e351cbe 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
30fdf114 6\r
30fdf114
LG
7**/\r
8\r
9#ifndef _EFI_STRING_FUNCS_H\r
10#define _EFI_STRING_FUNCS_H\r
11\r
12#include <stdio.h>\r
13#include <stdlib.h>\r
14#include <Common/UefiBaseTypes.h>\r
15\r
16//\r
17// Common data structures\r
18//\r
19typedef struct {\r
20 UINTN Count;\r
21 //\r
22 // Actually this array can be 0 or more items (based on Count)\r
23 //\r
24 CHAR8* Strings[1];\r
25} STRING_LIST;\r
26\r
27\r
28//\r
29// Functions declarations\r
30//\r
31\r
32CHAR8*\r
33CloneString (\r
34 IN CHAR8 *String\r
35 )\r
36;\r
37/**\r
38\r
39Routine Description:\r
40\r
41 Allocates a new string and copies 'String' to clone it\r
42\r
43Arguments:\r
44\r
45 String The string to clone\r
46\r
47Returns:\r
48\r
49 CHAR8* - NULL if there are not enough resources\r
50\r
51**/\r
52\r
53\r
54EFI_STATUS\r
55StripInfDscStringInPlace (\r
56 IN CHAR8 *String\r
57 )\r
58;\r
59/**\r
60\r
61Routine Description:\r
62\r
63 Remove all comments, leading and trailing whitespace from the string.\r
64\r
65Arguments:\r
66\r
fb0b35e0 67 String The string to 'strip'\r
30fdf114
LG
68\r
69Returns:\r
70\r
71 EFI_STATUS\r
72\r
73**/\r
74\r
75\r
76STRING_LIST*\r
77SplitStringByWhitespace (\r
78 IN CHAR8 *String\r
79 )\r
80;\r
81/**\r
82\r
83Routine Description:\r
84\r
85 Creates and returns a 'split' STRING_LIST by splitting the string\r
86 on whitespace boundaries.\r
87\r
88Arguments:\r
89\r
90 String The string to 'split'\r
91\r
92Returns:\r
93\r
94 EFI_STATUS\r
95\r
96**/\r
97\r
98\r
99STRING_LIST*\r
100NewStringList (\r
101 )\r
102;\r
103/**\r
104\r
105Routine Description:\r
106\r
107 Creates a new STRING_LIST with 0 strings.\r
108\r
109Returns:\r
110\r
111 STRING_LIST* - Null if there is not enough resources to create the object.\r
112\r
113**/\r
114\r
115\r
116EFI_STATUS\r
117AppendCopyOfStringToList (\r
118 IN OUT STRING_LIST **StringList,\r
119 IN CHAR8 *String\r
120 )\r
121;\r
122/**\r
123\r
124Routine Description:\r
125\r
126 Adds String to StringList. A new copy of String is made before it is\r
127 added to StringList.\r
128\r
129Returns:\r
130\r
131 EFI_STATUS\r
132\r
133**/\r
134\r
135\r
136EFI_STATUS\r
137RemoveLastStringFromList (\r
138 IN STRING_LIST *StringList\r
139 )\r
140;\r
141/**\r
142\r
143Routine Description:\r
144\r
145 Removes the last string from StringList and frees the memory associated\r
146 with it.\r
147\r
148Arguments:\r
149\r
150 StringList The string list to remove the string from\r
151\r
152Returns:\r
153\r
154 EFI_STATUS\r
155\r
156**/\r
157\r
158\r
159STRING_LIST*\r
160AllocateStringListStruct (\r
161 IN UINTN StringCount\r
162 )\r
163;\r
164/**\r
165\r
166Routine Description:\r
167\r
168 Allocates a STRING_LIST structure that can store StringCount strings.\r
169\r
170Arguments:\r
171\r
172 StringCount The number of strings that need to be stored\r
173\r
174Returns:\r
175\r
176 EFI_STATUS\r
177\r
178**/\r
179\r
180\r
181VOID\r
182FreeStringList (\r
183 IN STRING_LIST *StringList\r
184 )\r
185;\r
186/**\r
187\r
188Routine Description:\r
189\r
190 Frees all memory associated with StringList.\r
191\r
192Arguments:\r
193\r
194 StringList The string list to free\r
195\r
196Returns:\r
197\r
198 EFI_STATUS\r
199\r
200**/\r
201\r
202\r
203CHAR8*\r
204StringListToString (\r
205 IN STRING_LIST *StringList\r
206 )\r
207;\r
208/**\r
209\r
210Routine Description:\r
211\r
212 Generates a string that represents the STRING_LIST\r
213\r
214Arguments:\r
215\r
216 StringList The string list to convert to a string\r
217\r
218Returns:\r
219\r
220 CHAR8* - The string list represented with a single string. The returned\r
221 string must be freed by the caller.\r
222\r
223**/\r
224\r
225\r
226VOID\r
227PrintStringList (\r
228 IN STRING_LIST *StringList\r
229 )\r
230;\r
231/**\r
232\r
233Routine Description:\r
234\r
235 Prints out the string list\r
236\r
237Arguments:\r
238\r
239 StringList The string list to print\r
240\r
241**/\r
242\r
243\r
244#endif\r