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 ///
40 /// commentsexpand allows expanding inside C and C++ style comments.
41 /// WARNING: It can currently be fooled by them showing up in strings!
42 ///
43 /// rawstringexpand allows expanding inside r"" and r'' style raw strings.
44 UT_API extern int UTVariableScan(UT_WorkBuffer &outstr, const char *instr,
45  UTVarCallback lookup, void *userdata,
46  bool tildeexpand = true,
47  bool commentsexpand = true,
48  bool rawstringexpand = true);
49 
50 /// UTExprVariableScan writes the output to a fixed length char * buffer
51 /// in outstr of size n. The number of variables that were expanded is returned.
52 /// @note If 0 is returned, outstr might still be different from instr
53 /// due to backslash escaping.
54 UT_API extern int UTExprVariableScan(UT_WorkBuffer &outstr, const char *instr,
55  UTVarCallback lookup,
56  UTVarCallback expreval,
57  void *userdata,
58  bool varexpand = true,
59  bool tildeexpand = true,
60  bool commentsexpand = true,
61  bool rawstringexpand = true);
62 
63 /// Convenience method for expanding environment variables from instr to outstr
64 static inline void
65 UTexpandVariables(UT_WorkBuffer &outstr, const char *instr)
66 {
67  UTVariableScan(outstr, instr ? instr : "", NULL, NULL);
68 }
69 
70 #endif
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, bool rawstringexpand=true)
#define UT_API
Definition: UT_API.h:14
const char *(* UTVarCallback)(const char *str, void *userdata)
Definition: UT_VarScan.h:20
UT_API int UTVariableScan(UT_WorkBuffer &outstr, const char *instr, UTVarCallback lookup, void *userdata, bool tildeexpand=true, bool commentsexpand=true, bool rawstringexpand=true)