Skip to content

Commit c56e437

Browse files
committed
llcppsymg:full inireader
1 parent 6aa386c commit c56e437

File tree

4 files changed

+170
-29
lines changed

4 files changed

+170
-29
lines changed

_xtool/llcppsymg/internal/symg/symg_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,21 @@ func TestGen(t *testing.T) {
421421
name: "inireader",
422422
path: "./testdata/inireader",
423423
dylibSymbols: []string{
424-
"ZN9INIReaderC1EPKc",
425-
"ZN9INIReaderC1EPKcl",
426-
"ZN9INIReaderD1Ev",
424+
"ZN9INIReaderC1EPKcm",
425+
"ZN9INIReaderC1ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
426+
"ZN9INIReaderC2EPKcm",
427+
"ZN9INIReaderC2ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
428+
"ZNK9INIReader10GetBooleanERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_b",
429+
"ZNK9INIReader10GetIntegerERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_l",
430+
"ZNK9INIReader10HasSectionERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
427431
"ZNK9INIReader10ParseErrorEv",
428-
"ZNK9INIReader3GetEPKcS1_S1_",
432+
"ZNK9INIReader11GetUnsignedERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_m",
433+
"ZNK9INIReader12GetInteger64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_x",
434+
"ZNK9INIReader13GetUnsigned64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_y",
435+
"ZNK9INIReader3GetERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
436+
"ZNK9INIReader7GetRealERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_d",
437+
"ZNK9INIReader8HasValueERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_",
438+
"ZNK9INIReader9GetStringERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
429439
},
430440
},
431441
{
Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,106 @@
1+
// Read an INI file into easy-to-access name/value pairs.
2+
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
// Copyright (C) 2009-2020, Ben Hoyt
6+
7+
// inih and INIReader are released under the New BSD license (see LICENSE.txt).
8+
// Go to the project home page for more info:
9+
//
10+
// https://github.com/benhoyt/inih
11+
12+
#ifndef INIREADER_H
13+
#define INIREADER_H
14+
15+
#include <cstdint>
16+
#include <map>
17+
#include <string>
18+
19+
// Visibility symbols, required for Windows DLLs
20+
#ifndef INI_API
21+
#if defined _WIN32 || defined __CYGWIN__
22+
#ifdef INI_SHARED_LIB
23+
#ifdef INI_SHARED_LIB_BUILDING
24+
#define INI_API __declspec(dllexport)
25+
#else
26+
#define INI_API __declspec(dllimport)
27+
#endif
28+
#else
29+
#define INI_API
30+
#endif
31+
#else
32+
#if defined(__GNUC__) && __GNUC__ >= 4
133
#define INI_API __attribute__((visibility("default")))
2-
class INIReader
3-
{
4-
public:
5-
__attribute__((visibility("default"))) explicit INIReader(const char *filename);
6-
INI_API explicit INIReader(const char *buffer, long buffer_size);
7-
~INIReader();
34+
#else
35+
#define INI_API
36+
#endif
37+
#endif
38+
#endif
39+
40+
// Read an INI file into easy-to-access name/value pairs. (Note that I've gone
41+
// for simplicity here rather than speed, but it should be pretty decent.)
42+
class INIReader {
43+
public:
44+
// Construct INIReader and parse given filename. See ini.h for more info
45+
// about the parsing.
46+
__attribute__((visibility("default"))) explicit INIReader(const std::string &filename);
47+
48+
// Construct INIReader and parse given buffer. See ini.h for more info
49+
// about the parsing.
50+
INI_API explicit INIReader(const char *buffer, size_t buffer_size);
51+
52+
// Return the result of ini_parse(), i.e., 0 on success, line number of
53+
// first error on parse error, or -1 on file open error.
854
INI_API int ParseError() const;
9-
INI_API const char *Get(const char *section, const char *name,
10-
const char *default_value) const;
1155

12-
private:
13-
static const char *MakeKey(const char *section, const char *name);
14-
};
56+
// Get a string value from INI file, returning default_value if not found.
57+
INI_API std::string Get(const std::string &section, const std::string &name,
58+
const std::string &default_value) const;
59+
60+
// Get a string value from INI file, returning default_value if not found,
61+
// empty, or contains only whitespace.
62+
INI_API std::string GetString(const std::string &section, const std::string &name,
63+
const std::string &default_value) const;
64+
65+
// Get an integer (long) value from INI file, returning default_value if
66+
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
67+
INI_API long GetInteger(const std::string &section, const std::string &name, long default_value) const;
68+
69+
// Get a 64-bit integer (int64_t) value from INI file, returning default_value if
70+
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
71+
INI_API int64_t GetInteger64(const std::string &section, const std::string &name, int64_t default_value) const;
72+
73+
// Get an unsigned integer (unsigned long) value from INI file, returning default_value if
74+
// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
75+
INI_API unsigned long GetUnsigned(const std::string &section, const std::string &name,
76+
unsigned long default_value) const;
77+
78+
// Get an unsigned 64-bit integer (uint64_t) value from INI file, returning default_value if
79+
// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
80+
INI_API uint64_t GetUnsigned64(const std::string &section, const std::string &name, uint64_t default_value) const;
81+
82+
// Get a real (floating point double) value from INI file, returning
83+
// default_value if not found or not a valid floating point value
84+
// according to strtod().
85+
INI_API double GetReal(const std::string &section, const std::string &name, double default_value) const;
86+
87+
// Get a boolean value from INI file, returning default_value if not found or if
88+
// not a valid true/false value. Valid true values are "true", "yes", "on", "1",
89+
// and valid false values are "false", "no", "off", "0" (not case sensitive).
90+
INI_API bool GetBoolean(const std::string &section, const std::string &name, bool default_value) const;
91+
92+
// Return true if the given section exists (section must contain at least
93+
// one name=value pair).
94+
INI_API bool HasSection(const std::string &section) const;
95+
96+
// Return true if a value exists with the given section and field names.
97+
INI_API bool HasValue(const std::string &section, const std::string &name) const;
98+
99+
private:
100+
int _error;
101+
std::map<std::string, std::string> _values;
102+
static std::string MakeKey(const std::string &section, const std::string &name);
103+
static int ValueHandler(void *user, const char *section, const char *name, const char *value);
104+
};
105+
106+
#endif // INIREADER_H
Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,67 @@
11
[
22
{
3-
"mangle": "_ZN9INIReaderC1EPKc",
4-
"c++": "INIReader::INIReader(const char *)",
3+
"mangle": "_ZN9INIReaderC1EPKcm",
4+
"c++": "INIReader::INIReader(const char *, size_t)",
5+
"go": "(*Reader).Init__1"
6+
},
7+
{
8+
"mangle": "_ZN9INIReaderC1ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
9+
"c++": "INIReader::INIReader(const std::string \u0026)",
510
"go": "(*Reader).Init"
611
},
712
{
8-
"mangle": "_ZN9INIReaderC1EPKcl",
9-
"c++": "INIReader::INIReader(const char *, long)",
10-
"go": "(*Reader).Init__1"
13+
"mangle": "_ZNK9INIReader10GetBooleanERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_b",
14+
"c++": "INIReader::GetBoolean(const std::string \u0026, const std::string \u0026, bool)",
15+
"go": "(*Reader).GetBoolean"
1116
},
1217
{
13-
"mangle": "_ZN9INIReaderD1Ev",
14-
"c++": "INIReader::~INIReader()",
15-
"go": "(*Reader).Dispose"
18+
"mangle": "_ZNK9INIReader10GetIntegerERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_l",
19+
"c++": "INIReader::GetInteger(const std::string \u0026, const std::string \u0026, long)",
20+
"go": "(*Reader).GetInteger"
21+
},
22+
{
23+
"mangle": "_ZNK9INIReader10HasSectionERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
24+
"c++": "INIReader::HasSection(const std::string \u0026)",
25+
"go": "(*Reader).HasSection"
1626
},
1727
{
1828
"mangle": "_ZNK9INIReader10ParseErrorEv",
1929
"c++": "INIReader::ParseError()",
2030
"go": "(*Reader).ModifyedParseError"
2131
},
2232
{
23-
"mangle": "_ZNK9INIReader3GetEPKcS1_S1_",
24-
"c++": "INIReader::Get(const char *, const char *, const char *)",
33+
"mangle": "_ZNK9INIReader11GetUnsignedERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_m",
34+
"c++": "INIReader::GetUnsigned(const std::string \u0026, const std::string \u0026, unsigned long)",
35+
"go": "(*Reader).GetUnsigned"
36+
},
37+
{
38+
"mangle": "_ZNK9INIReader12GetInteger64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_x",
39+
"c++": "INIReader::GetInteger64(const std::string \u0026, const std::string \u0026, int64_t)",
40+
"go": "(*Reader).GetInteger64"
41+
},
42+
{
43+
"mangle": "_ZNK9INIReader13GetUnsigned64ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_y",
44+
"c++": "INIReader::GetUnsigned64(const std::string \u0026, const std::string \u0026, uint64_t)",
45+
"go": "(*Reader).GetUnsigned64"
46+
},
47+
{
48+
"mangle": "_ZNK9INIReader3GetERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
49+
"c++": "INIReader::Get(const std::string \u0026, const std::string \u0026, const std::string \u0026)",
2550
"go": "(*Reader).Get"
51+
},
52+
{
53+
"mangle": "_ZNK9INIReader7GetRealERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_d",
54+
"c++": "INIReader::GetReal(const std::string \u0026, const std::string \u0026, double)",
55+
"go": "(*Reader).GetReal"
56+
},
57+
{
58+
"mangle": "_ZNK9INIReader8HasValueERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_",
59+
"c++": "INIReader::HasValue(const std::string \u0026, const std::string \u0026)",
60+
"go": "(*Reader).HasValue"
61+
},
62+
{
63+
"mangle": "_ZNK9INIReader9GetStringERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_S8_",
64+
"c++": "INIReader::GetString(const std::string \u0026, const std::string \u0026, const std::string \u0026)",
65+
"go": "(*Reader).GetString"
2666
}
27-
]
67+
]

_xtool/llcppsymg/internal/symg/testdata/inireader/llcppg.cfg

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
"trimPrefixes": ["INI"],
77
"cplusplus": true,
88
"symMap": {
9-
"_ZN9INIReaderC1EPKc":".Init",
10-
"_ZN9INIReaderC1EPKcl":".Init__1",
11-
"_ZN9INIReaderD1Ev":".Dispose",
9+
"_ZN9INIReaderC1ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE":".Init",
10+
"_ZN9INIReaderC1EPKcm":".Init__1",
1211
"_ZNK9INIReader10ParseErrorEv":".ModifyedParseError"
1312
}
1413
}

0 commit comments

Comments
 (0)