@@ -519,18 +519,9 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
519
519
case jpiNull :
520
520
appendStringInfoString (buf , "null" );
521
521
break ;
522
- case jpiKey :
523
- if (inKey )
524
- appendStringInfoChar (buf , '.' );
525
- escape_json (buf , jspGetString (v , NULL ));
526
- break ;
527
522
case jpiString :
528
523
escape_json (buf , jspGetString (v , NULL ));
529
524
break ;
530
- case jpiVariable :
531
- appendStringInfoChar (buf , '$' );
532
- escape_json (buf , jspGetString (v , NULL ));
533
- break ;
534
525
case jpiNumeric :
535
526
if (jspHasNext (v ))
536
527
appendStringInfoChar (buf , '(' );
@@ -576,58 +567,6 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
576
567
if (printBracketes )
577
568
appendStringInfoChar (buf , ')' );
578
569
break ;
579
- case jpiLikeRegex :
580
- if (printBracketes )
581
- appendStringInfoChar (buf , '(' );
582
-
583
- jspInitByBuffer (& elem , v -> base , v -> content .like_regex .expr );
584
- printJsonPathItem (buf , & elem , false,
585
- operationPriority (elem .type ) <=
586
- operationPriority (v -> type ));
587
-
588
- appendStringInfoString (buf , " like_regex " );
589
-
590
- escape_json (buf , v -> content .like_regex .pattern );
591
-
592
- if (v -> content .like_regex .flags )
593
- {
594
- appendStringInfoString (buf , " flag \"" );
595
-
596
- if (v -> content .like_regex .flags & JSP_REGEX_ICASE )
597
- appendStringInfoChar (buf , 'i' );
598
- if (v -> content .like_regex .flags & JSP_REGEX_DOTALL )
599
- appendStringInfoChar (buf , 's' );
600
- if (v -> content .like_regex .flags & JSP_REGEX_MLINE )
601
- appendStringInfoChar (buf , 'm' );
602
- if (v -> content .like_regex .flags & JSP_REGEX_WSPACE )
603
- appendStringInfoChar (buf , 'x' );
604
- if (v -> content .like_regex .flags & JSP_REGEX_QUOTE )
605
- appendStringInfoChar (buf , 'q' );
606
-
607
- appendStringInfoChar (buf , '"' );
608
- }
609
-
610
- if (printBracketes )
611
- appendStringInfoChar (buf , ')' );
612
- break ;
613
- case jpiPlus :
614
- case jpiMinus :
615
- if (printBracketes )
616
- appendStringInfoChar (buf , '(' );
617
- appendStringInfoChar (buf , v -> type == jpiPlus ? '+' : '-' );
618
- jspGetArg (v , & elem );
619
- printJsonPathItem (buf , & elem , false,
620
- operationPriority (elem .type ) <=
621
- operationPriority (v -> type ));
622
- if (printBracketes )
623
- appendStringInfoChar (buf , ')' );
624
- break ;
625
- case jpiFilter :
626
- appendStringInfoString (buf , "?(" );
627
- jspGetArg (v , & elem );
628
- printJsonPathItem (buf , & elem , false, false);
629
- appendStringInfoChar (buf , ')' );
630
- break ;
631
570
case jpiNot :
632
571
appendStringInfoString (buf , "!(" );
633
572
jspGetArg (v , & elem );
@@ -640,22 +579,17 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
640
579
printJsonPathItem (buf , & elem , false, false);
641
580
appendStringInfoString (buf , ") is unknown" );
642
581
break ;
643
- case jpiExists :
644
- appendStringInfoString (buf , "exists (" );
582
+ case jpiPlus :
583
+ case jpiMinus :
584
+ if (printBracketes )
585
+ appendStringInfoChar (buf , '(' );
586
+ appendStringInfoChar (buf , v -> type == jpiPlus ? '+' : '-' );
645
587
jspGetArg (v , & elem );
646
- printJsonPathItem (buf , & elem , false, false);
647
- appendStringInfoChar (buf , ')' );
648
- break ;
649
- case jpiCurrent :
650
- Assert (!inKey );
651
- appendStringInfoChar (buf , '@' );
652
- break ;
653
- case jpiRoot :
654
- Assert (!inKey );
655
- appendStringInfoChar (buf , '$' );
656
- break ;
657
- case jpiLast :
658
- appendStringInfoString (buf , "last" );
588
+ printJsonPathItem (buf , & elem , false,
589
+ operationPriority (elem .type ) <=
590
+ operationPriority (v -> type ));
591
+ if (printBracketes )
592
+ appendStringInfoChar (buf , ')' );
659
593
break ;
660
594
case jpiAnyArray :
661
595
appendStringInfoString (buf , "[*]" );
@@ -712,6 +646,35 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
712
646
v -> content .anybounds .first ,
713
647
v -> content .anybounds .last );
714
648
break ;
649
+ case jpiKey :
650
+ if (inKey )
651
+ appendStringInfoChar (buf , '.' );
652
+ escape_json (buf , jspGetString (v , NULL ));
653
+ break ;
654
+ case jpiCurrent :
655
+ Assert (!inKey );
656
+ appendStringInfoChar (buf , '@' );
657
+ break ;
658
+ case jpiRoot :
659
+ Assert (!inKey );
660
+ appendStringInfoChar (buf , '$' );
661
+ break ;
662
+ case jpiVariable :
663
+ appendStringInfoChar (buf , '$' );
664
+ escape_json (buf , jspGetString (v , NULL ));
665
+ break ;
666
+ case jpiFilter :
667
+ appendStringInfoString (buf , "?(" );
668
+ jspGetArg (v , & elem );
669
+ printJsonPathItem (buf , & elem , false, false);
670
+ appendStringInfoChar (buf , ')' );
671
+ break ;
672
+ case jpiExists :
673
+ appendStringInfoString (buf , "exists (" );
674
+ jspGetArg (v , & elem );
675
+ printJsonPathItem (buf , & elem , false, false);
676
+ appendStringInfoChar (buf , ')' );
677
+ break ;
715
678
case jpiType :
716
679
appendStringInfoString (buf , ".type()" );
717
680
break ;
@@ -742,6 +705,43 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
742
705
case jpiKeyValue :
743
706
appendStringInfoString (buf , ".keyvalue()" );
744
707
break ;
708
+ case jpiLast :
709
+ appendStringInfoString (buf , "last" );
710
+ break ;
711
+ case jpiLikeRegex :
712
+ if (printBracketes )
713
+ appendStringInfoChar (buf , '(' );
714
+
715
+ jspInitByBuffer (& elem , v -> base , v -> content .like_regex .expr );
716
+ printJsonPathItem (buf , & elem , false,
717
+ operationPriority (elem .type ) <=
718
+ operationPriority (v -> type ));
719
+
720
+ appendStringInfoString (buf , " like_regex " );
721
+
722
+ escape_json (buf , v -> content .like_regex .pattern );
723
+
724
+ if (v -> content .like_regex .flags )
725
+ {
726
+ appendStringInfoString (buf , " flag \"" );
727
+
728
+ if (v -> content .like_regex .flags & JSP_REGEX_ICASE )
729
+ appendStringInfoChar (buf , 'i' );
730
+ if (v -> content .like_regex .flags & JSP_REGEX_DOTALL )
731
+ appendStringInfoChar (buf , 's' );
732
+ if (v -> content .like_regex .flags & JSP_REGEX_MLINE )
733
+ appendStringInfoChar (buf , 'm' );
734
+ if (v -> content .like_regex .flags & JSP_REGEX_WSPACE )
735
+ appendStringInfoChar (buf , 'x' );
736
+ if (v -> content .like_regex .flags & JSP_REGEX_QUOTE )
737
+ appendStringInfoChar (buf , 'q' );
738
+
739
+ appendStringInfoChar (buf , '"' );
740
+ }
741
+
742
+ if (printBracketes )
743
+ appendStringInfoChar (buf , ')' );
744
+ break ;
745
745
default :
746
746
elog (ERROR , "unrecognized jsonpath item type: %d" , v -> type );
747
747
}
@@ -771,38 +771,38 @@ jspOperationName(JsonPathItemType type)
771
771
return "<=" ;
772
772
case jpiGreaterOrEqual :
773
773
return ">=" ;
774
- case jpiPlus :
775
774
case jpiAdd :
775
+ case jpiPlus :
776
776
return "+" ;
777
- case jpiMinus :
778
777
case jpiSub :
778
+ case jpiMinus :
779
779
return "-" ;
780
780
case jpiMul :
781
781
return "*" ;
782
782
case jpiDiv :
783
783
return "/" ;
784
784
case jpiMod :
785
785
return "%" ;
786
- case jpiStartsWith :
787
- return "starts with" ;
788
- case jpiLikeRegex :
789
- return "like_regex" ;
790
786
case jpiType :
791
787
return "type" ;
792
788
case jpiSize :
793
789
return "size" ;
794
- case jpiKeyValue :
795
- return "keyvalue" ;
796
- case jpiDouble :
797
- return "double" ;
798
790
case jpiAbs :
799
791
return "abs" ;
800
792
case jpiFloor :
801
793
return "floor" ;
802
794
case jpiCeiling :
803
795
return "ceiling" ;
796
+ case jpiDouble :
797
+ return "double" ;
804
798
case jpiDatetime :
805
799
return "datetime" ;
800
+ case jpiKeyValue :
801
+ return "keyvalue" ;
802
+ case jpiStartsWith :
803
+ return "starts with" ;
804
+ case jpiLikeRegex :
805
+ return "like_regex" ;
806
806
default :
807
807
elog (ERROR , "unrecognized jsonpath item type: %d" , type );
808
808
return NULL ;
@@ -900,8 +900,8 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
900
900
case jpiKeyValue :
901
901
case jpiLast :
902
902
break ;
903
- case jpiKey :
904
903
case jpiString :
904
+ case jpiKey :
905
905
case jpiVariable :
906
906
read_int32 (v -> content .value .datalen , base , pos );
907
907
/* FALLTHROUGH */
@@ -911,30 +911,24 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
911
911
break ;
912
912
case jpiAnd :
913
913
case jpiOr :
914
- case jpiAdd :
915
- case jpiSub :
916
- case jpiMul :
917
- case jpiDiv :
918
- case jpiMod :
919
914
case jpiEqual :
920
915
case jpiNotEqual :
921
916
case jpiLess :
922
917
case jpiGreater :
923
918
case jpiLessOrEqual :
924
919
case jpiGreaterOrEqual :
920
+ case jpiAdd :
921
+ case jpiSub :
922
+ case jpiMul :
923
+ case jpiDiv :
924
+ case jpiMod :
925
925
case jpiStartsWith :
926
926
read_int32 (v -> content .args .left , base , pos );
927
927
read_int32 (v -> content .args .right , base , pos );
928
928
break ;
929
- case jpiLikeRegex :
930
- read_int32 (v -> content .like_regex .flags , base , pos );
931
- read_int32 (v -> content .like_regex .expr , base , pos );
932
- read_int32 (v -> content .like_regex .patternlen , base , pos );
933
- v -> content .like_regex .pattern = base + pos ;
934
- break ;
935
929
case jpiNot :
936
- case jpiExists :
937
930
case jpiIsUnknown :
931
+ case jpiExists :
938
932
case jpiPlus :
939
933
case jpiMinus :
940
934
case jpiFilter :
@@ -950,6 +944,12 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
950
944
read_int32 (v -> content .anybounds .first , base , pos );
951
945
read_int32 (v -> content .anybounds .last , base , pos );
952
946
break ;
947
+ case jpiLikeRegex :
948
+ read_int32 (v -> content .like_regex .flags , base , pos );
949
+ read_int32 (v -> content .like_regex .expr , base , pos );
950
+ read_int32 (v -> content .like_regex .patternlen , base , pos );
951
+ v -> content .like_regex .pattern = base + pos ;
952
+ break ;
953
953
default :
954
954
elog (ERROR , "unrecognized jsonpath item type: %d" , v -> type );
955
955
}
@@ -958,12 +958,12 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
958
958
void
959
959
jspGetArg (JsonPathItem * v , JsonPathItem * a )
960
960
{
961
- Assert (v -> type == jpiFilter ||
962
- v -> type == jpiNot ||
961
+ Assert (v -> type == jpiNot ||
963
962
v -> type == jpiIsUnknown ||
964
- v -> type == jpiExists ||
965
963
v -> type == jpiPlus ||
966
964
v -> type == jpiMinus ||
965
+ v -> type == jpiFilter ||
966
+ v -> type == jpiExists ||
967
967
v -> type == jpiDatetime );
968
968
969
969
jspInitByBuffer (a , v -> base , v -> content .arg );
@@ -974,38 +974,37 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
974
974
{
975
975
if (jspHasNext (v ))
976
976
{
977
- Assert (v -> type == jpiString ||
977
+ Assert (v -> type == jpiNull ||
978
+ v -> type == jpiString ||
978
979
v -> type == jpiNumeric ||
979
980
v -> type == jpiBool ||
980
- v -> type == jpiNull ||
981
- v -> type == jpiKey ||
982
- v -> type == jpiAny ||
983
- v -> type == jpiAnyArray ||
984
- v -> type == jpiAnyKey ||
985
- v -> type == jpiIndexArray ||
986
- v -> type == jpiFilter ||
987
- v -> type == jpiCurrent ||
988
- v -> type == jpiExists ||
989
- v -> type == jpiRoot ||
990
- v -> type == jpiVariable ||
991
- v -> type == jpiLast ||
981
+ v -> type == jpiAnd ||
982
+ v -> type == jpiOr ||
983
+ v -> type == jpiNot ||
984
+ v -> type == jpiIsUnknown ||
985
+ v -> type == jpiEqual ||
986
+ v -> type == jpiNotEqual ||
987
+ v -> type == jpiLess ||
988
+ v -> type == jpiGreater ||
989
+ v -> type == jpiLessOrEqual ||
990
+ v -> type == jpiGreaterOrEqual ||
992
991
v -> type == jpiAdd ||
993
992
v -> type == jpiSub ||
994
993
v -> type == jpiMul ||
995
994
v -> type == jpiDiv ||
996
995
v -> type == jpiMod ||
997
996
v -> type == jpiPlus ||
998
997
v -> type == jpiMinus ||
999
- v -> type == jpiEqual ||
1000
- v -> type == jpiNotEqual ||
1001
- v -> type == jpiGreater ||
1002
- v -> type == jpiGreaterOrEqual ||
1003
- v -> type == jpiLess ||
1004
- v -> type == jpiLessOrEqual ||
1005
- v -> type == jpiAnd ||
1006
- v -> type == jpiOr ||
1007
- v -> type == jpiNot ||
1008
- v -> type == jpiIsUnknown ||
998
+ v -> type == jpiAnyArray ||
999
+ v -> type == jpiAnyKey ||
1000
+ v -> type == jpiIndexArray ||
1001
+ v -> type == jpiAny ||
1002
+ v -> type == jpiKey ||
1003
+ v -> type == jpiCurrent ||
1004
+ v -> type == jpiRoot ||
1005
+ v -> type == jpiVariable ||
1006
+ v -> type == jpiFilter ||
1007
+ v -> type == jpiExists ||
1009
1008
v -> type == jpiType ||
1010
1009
v -> type == jpiSize ||
1011
1010
v -> type == jpiAbs ||
@@ -1014,6 +1013,7 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
1014
1013
v -> type == jpiDouble ||
1015
1014
v -> type == jpiDatetime ||
1016
1015
v -> type == jpiKeyValue ||
1016
+ v -> type == jpiLast ||
1017
1017
v -> type == jpiStartsWith ||
1018
1018
v -> type == jpiLikeRegex );
1019
1019
0 commit comments