Skip to content

Commit 94e6c75

Browse files
author
Dmitry Lyssenko
committed
this is update for v1.74, see description at: https://github.com/ldn-softdev/jtc/blob/master/Release%20Notes.md
1 parent 3d621d4 commit 94e6c75

File tree

4 files changed

+234
-162
lines changed

4 files changed

+234
-162
lines changed

jtc.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using namespace std;
1515

1616

17-
#define VERSION "1.73"
17+
#define VERSION "1.74"
1818
#define CREATOR "Dmitry Lyssenko"
1919
#define EMAIL "[email protected]"
2020

@@ -192,7 +192,8 @@ class Jtc {
192192
Json::iterator dst; // -w walks (iterators) go here
193193
Json::iterator src; // -i/u/c walks (iterators) go here
194194
Json::map_jn ns; // NS from respective -i/u/c iters.
195-
string lbl{"\n"};
195+
string lbl{"\n"}; // facilitates -u for label update
196+
// init'ed with "\n" - invalid lbl
196197
};
197198

198199
struct Grouping {
@@ -236,7 +237,9 @@ class Jtc {
236237
is_tmp_per_walk_ = opt_[CHR(OPT_TMP)].hits() > 1 and
237238
opt_[CHR(OPT_SEQ)].hits() < 2 and
238239
opt_[CHR(OPT_TMP)].hits() == opt_[CHR(OPT_WLK)].hits();
239-
jinp_.tab(abs(opt_[CHR(OPT_IND)])) // prepare json_
240+
// ready jinp_
241+
jinp_.tab(opt_[CHR(OPT_IND)].hits() > 0 or not opt_[CHR(OPT_RAW)]?
242+
abs(opt_[CHR(OPT_IND)]): 1)
240243
.raw(opt_[CHR(OPT_RAW)])
241244
.quote_solidus(opt_[CHR(OPT_QUT)].hits() % 2 == 1);
242245

@@ -889,8 +892,10 @@ void Jtc::upsert_json(char op) {
889892

890893

891894
void Jtc::collect_itr_bindings(Json::iterator &it, Grouping unused) {
892-
// insert each/all -[iu] processed jsons
893-
if(processed_by_cli_(it)) return; // -ei ... \; w/o trailing -i<..>
895+
// facilitate insert each/all -[iu] processed jsons:
896+
// per each walked destination (-w, facilitated by &it), collect each respective source(s) (jits_)
897+
// Grouping arg is unused here, but is required by subscriber_'s definition
898+
if(processed_by_cli_(it)) return; // -ei ... \; w/o trailing -i<wlk>
894899

895900
merge_ns_(cr_.global_ns(), wns_[&it]); // syncup global ns
896901
if(jits_.walk_size() > 0) // walk_size > 0 means init'ed jits
@@ -899,7 +904,8 @@ void Jtc::collect_itr_bindings(Json::iterator &it, Grouping unused) {
899904
while(advance_to_next_src()) {
900905
DBG(1) DOUT() << "optarg idx [" << wcur_ << "] out of "
901906
<< (jitt_ == src_optarg? jsrc_.size(): wsrc_.size()) << " ("
902-
<< (jitt_ == src_optarg? "static":opt_.ordinal(wsrc_[wcur_]).c_str()) << ")" <<endl;
907+
<< (jitt_ == src_optarg? "static":opt_.ordinal(wsrc_[wcur_]).c_str())
908+
<< ")" << endl;
903909
psrc_.emplace_back(it, jits_); // collect iterator
904910
if(is_multi_walk_) break;
905911
}
@@ -909,6 +915,7 @@ void Jtc::collect_itr_bindings(Json::iterator &it, Grouping unused) {
909915

910916
void Jtc::update_by_iterator(Json::iterator &it, Grouping unused) {
911917
// update each/all -u processed jsons
918+
// Grouping arg is unused here, but is required by subscriber_'s definition
912919
if(lbl_update_ == false) // not faced label update yet
913920
lbl_update_ = not it.walks().empty() and it.walks().back().jsearch == Json::key_of_json;
914921
else // lbl update occurred, then
@@ -929,7 +936,7 @@ bool Jtc::advance_to_next_src(signed_size_t i) {
929936

930937
DBG(4) DOUT() << "walk src: " << i << ", walk/json: '"
931938
<< (jitt_ == src_optarg?
932-
jsrc_[idx()].to_string(Jnode::Raw):
939+
jsrc_[idx()].to_string(Jnode::Raw, 1):
933940
opt_.ordinal(wsrc_[idx()]).str()) << "'" << endl;
934941
size_t jc_size = jitt_ == src_optarg? jsrc_.size(): wsrc_.size(); // json source container size
935942
if(jits_.is_valid()) { // if true, walk_size must be > 0
@@ -998,7 +1005,7 @@ void Jtc::apply_src_walks(char op) {
9981005
pair.src: tmp.walk(), &pair.lbl);
9991006
}
10001007
}
1001-
else // ecli_ == true
1008+
else // ecli_ == true // case: -e -u/i ... \; -u/i<wlk>
10021009
if(execute_cli_(jexc_, pair.src, pair.ns) == true)
10031010
(this->*upsert[op == CHR(OPT_UPD)])(pair.dst, jexc_.walk(), &pair.lbl);
10041011

@@ -1172,7 +1179,7 @@ void Jtc::location_(Streamstr::const_iterator &jbegin) {
11721179

11731180

11741181
void Jtc::ready_params_(char option) {
1175-
// fill / prepare data: jsrc_ (if multiple jsons, no walks: -u<static> -u<static>),
1182+
// fill / prepare data: jsrc_ (if multiple jsons, no walks: -u<static1> -u<static2>),
11761183
// or jexc_ & wsrc_ (in case like: -eu -u... & -u<static> -u<walk> respectively)
11771184
if(ecli_) // -e detected
11781185
for(size_t i = cr_.opt_e_found(); cr_.opt_ui() and i <= opt_[cr_.opt_ui()].hits(); ++i)
@@ -1279,8 +1286,7 @@ void Jtc::compare_jsons_(const Jnode &j1, set<const Jnode*> &s1,
12791286

12801287
void Jtc::merge_jsons_(Json::iterator &it_dst, Json::iterator it_src, string *unused) {
12811288
// merge 2 jsons. convert to array non-array dst jsons (predicated by -m)
1282-
if(it_dst.walks().back().jsearch == Json::key_of_json and
1283-
it_dst.walks().back().stripped[0].empty()) // '<>k' facing
1289+
if(it_dst.reinterpret_label()) // '<>k' facing
12841290
{ cerr << "error: insert into label not applicable, use update" << endl; return; }
12851291

12861292
if(it_dst->is_object()) { // dst is object
@@ -1379,13 +1385,12 @@ void Jtc::merge_into_array_(Jnode &dst, const Jnode &src, MergeObj mode) {
13791385

13801386
void Jtc::update_jsons_(Json::iterator &it_dst, Json::iterator it_src, string *lbl) {
13811387
// update dst with src, merge jsons with overwrite if -m is given
1382-
if(it_dst.walks().back().jsearch == Json::key_of_json and
1383-
it_dst.walks().back().stripped[0].empty()) {
1388+
if(it_dst.reinterpret_label()) { // '<>k' facing
13841389
DBG(2) DOUT() << "label being updated" << endl; // facilitate '<>k' (empty lexeme)
13851390
if(merge_)
13861391
{ cerr << "error: merge not applicable in label update, ignoring" << endl; }
13871392
if(not it_src->is_string())
1388-
{ cerr << "error: only labels could be updated with valid JSON strings" << endl; return; }
1393+
{ cerr << "error: labels could be updated only with valid JSON strings" << endl; return; }
13891394
auto & parent = (*it_dst)[-1];
13901395
if(not parent.is_object())
13911396
{ cerr << "error: labels could be updated in objects only" << endl; return; }
@@ -1521,8 +1526,8 @@ bool Jtc::remove_others_(set<const Jnode*> &ws, Jnode &jn) {
15211526
Jtc::vec_jit Jtc::collect_walks_(const string &walk_path) {
15221527
// collect all walk iterations from given walk path (used by swap/purge)
15231528
vec_jit walk_itr;
1524-
if(not psrc_.empty()) { // psrc is filled when walked -[ui]
1525-
for(auto &pair: psrc_)
1529+
if(opt_[CHR(OPT_INS)].hits() > 0 or opt_[CHR(OPT_UPD)].hits() > 0 ) {
1530+
for(auto &pair: psrc_) // psrc is filled when walked -[ui]
15261531
walk_itr.push_back(move(jitt_ == src_input? // -[iu] by collect_itr_bindings
15271532
pair.src: pair.dst));
15281533
DBG(0) DOUT() << "source of iterations: '" << ENUMS(Jitsrc, jitt_)
@@ -1694,7 +1699,7 @@ void Jtc::process_offsets_(deque<deq_jit> &wpi, vector<vector<signed_size_t>> &f
16941699
if(actuals.empty()) // should never be the case
16951700
{ wpi.clear(); return; } // in case, avoiding endless loop
16961701
DBG(2) DOUT() << "output instance: " << actuals.front()
1697-
<< ", #lowest offsets/counter: {" << grouping << ", }" << endl;
1702+
<< ", #lowest offsets/counter: {" << grouping << ", " << lf_counter << "}" << endl;
16981703
(this->*subscriber_)(wpi[actuals.front()].front(), {grouping, lf_counter});
16991704
wpi[actuals.front()].pop_front();
17001705
}

0 commit comments

Comments
 (0)