MCPcopy Create free account
hub / github.com/LAStools/LAStools / SetWkt

Method SetWkt

src/wktparser.cpp:53–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53void WktParser::SetWkt(const std::string wktin) {
54 wktraw = wktin;
55 std::string work = wktin;
56 std::string token = "";
57 std::vector<std::string> vkey;
58 std::vector<std::string> vval;
59 bool inStr = false;
60 bool inEscape = false;
61
62 // add key to key vector
63 auto vkeyAdd = [&]() {
64 token = BOOST_PRE trim(token);
65 if (!token.empty()) {
66 vkey.push_back(token);
67 token = "";
68 }
69 };
70
71 // add value to value vector
72 auto vvalAdd = [&]() {
73 if (!token.empty()) {
74 vval.push_back(token);
75 token = "";
76 }
77 };
78
79 // parse wkt
80 for (char& c : work) {
81 if (inStr) {
82 // get string till trailing "
83 if (c == '\\') {
84 inEscape = true;
85 } else if (inEscape || c != '"') {
86 inEscape = false;
87 token += c;
88 } else {
89 // string close
90 inEscape = false;
91 inStr = false;
92 }
93 } else if (c == '[') {
94 // finalize last values and start a new key-value pair
95 if (!vkey.empty() && !vval.empty()) {
96 map.insert(std::pair<std::string, std::string>(VectorDelimited(vkey, "."), VectorDelimited(vval, "|")));
97 vval.clear();
98 }
99 // extend or start new key
100 BOOST_PRE to_lower(token);
101 // - detect wkt version
102 if (isWktUnknown) {
103 isWktUnknown = false;
104 if (StringInVector(token, Wkt1Tkn, false)) {
105 isWkt1 = true;
106 }
107 if (StringInVector(token, Wkt2Tkn, false)) {
108 if (isWkt1) {
109 // warn: invalid
110 LASMessage(LAS_WARNING, "WKT2/WKT1 mismatch");

Callers 2

runMethod · 0.80

Calls 6

trimFunction · 0.85
VectorDelimitedFunction · 0.85
StringInVectorFunction · 0.85
LASMessageFunction · 0.85
emptyMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected