HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_VarScan.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  *
7  * NAME: UT_VarScan.h (C++)
8  *
9  * COMMENTS:
10  *
11  */
12 
13 #ifndef __UT_VarScan_h__
14 #define __UT_VarScan_h__
15 
16 #include "UT_API.h"
17 
18 class UT_WorkBuffer;
19 
20 typedef const char *(*UTVarCallback)(const char *str, void *userdata);
21 
22 /// UTVariableScan copies the input string instr to the work
23 /// string outstr searching for variable references of the form
24 /// $name or ${name} in the input string. Each such variable
25 /// reference found in the input string is replaced by its value
26 /// which is obtained by passing the variable name to the func-
27 /// tion referenced by the given argument lookup. If the given
28 /// function fails by returning a null pointer then the variable
29 /// reference is replaced in the output string by a null string.
30 ///
31 /// If a null function pointer is passed as the lookup argument,
32 /// then UTVariableScan calls the function getenv to find the
33 /// value of each variable.
34 ///
35 /// UTVariableScan returns the integer number of variables which
36 /// have been expanded.
37 /// @note If 0 is returned, outstr might still be different from instr
38 /// due to backslash escaping.
39 UT_API extern int UTVariableScan(UT_WorkBuffer &outstr, const char *instr,
40  UTVarCallback lookup, void *userdata,
41  bool tildeexpand = true,
42  bool commentsexpand = true);
43 
44 /// UTExprVariableScan writes the output to a fixed length char * buffer
45 /// in outstr of size n. The number of variables that were expanded is returned.
46 /// @note If 0 is returned, outstr might still be different from instr
47 /// due to backslash escaping.
48 UT_API extern int UTExprVariableScan(UT_WorkBuffer &outstr, const char *instr,
49  UTVarCallback lookup,
50  UTVarCallback expreval,
51  void *userdata,
52  bool varexpand = true,
53  bool tildeexpand = true,
54  bool commentsexpand = true);
55 
56 /// Convenience method for expanding environment variables from instr to outstr
57 static inline void
58 UTexpandVariables(UT_WorkBuffer &outstr, const char *instr)
59 {
60  UTVariableScan(outstr, instr ? instr : "", NULL, NULL);
61 }
62 
63 #endif
#define UT_API
Definition: UT_API.h:13
UT_API int UTExprVariableScan(UT_WorkBuffer &outstr, const char *instr, UTVarCallback lookup, UTVarCallback expreval, void *userdata, bool varexpand=true, bool tildeexpand=true, bool commentsexpand=true)
UT_API int UTVariableScan(UT_WorkBuffer &outstr, const char *instr, UTVarCallback lookup, void *userdata, bool tildeexpand=true, bool commentsexpand=true)
const char *(* UTVarCallback)(const char *str, void *userdata)
Definition: UT_VarScan.h:20