Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Implemented the text constraint commands unsignedByte, unsignedShort, unsignedInt and unsignedLong, along the xsd counterparts.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | schema
Files: files | file ages | folders
SHA3-256: 051ae451a26f0667b651d79b433b86ca39ece31dc06a7efb852bc828b2002b57
User & Date: rolf 2019-11-30 00:07:11
Context
2019-11-30
00:50
Merged from trunk. check-in: 8c0cc53beb user: rolf tags: schema
00:22
wip Leaf check-in: 55d2228ae4 user: rolf tags: toschema
00:07
Implemented the text constraint commands unsignedByte, unsignedShort, unsignedInt and unsignedLong, along the xsd counterparts. check-in: 051ae451a2 user: rolf tags: schema
2019-11-29
16:42
Added text constraint command hexBinary (similar to the xsd type hexBinary). check-in: ea199fedb7 user: rolf tags: schema
Changes

Changes to doc/schema.xml.

774
775
776
777
778
779
780




























781
782
783
784
785
786
787
      <commanddef>
        <command><cmd>hexBinary</cmd></command>
        <desc>This text constraint match if text is a sequence of
        binary octets in hexadecimal encoding, where each binary octet
        is a two-character hexadecimal number. Lowercase and uppercase
        letters A through F are permitted.</desc>
      </commanddef>




























    </commandlist>
  </section>

  <section>
    <title>Local key constraints</title>

    <p>Document wide uniqueness and foreign key constraints are







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
      <commanddef>
        <command><cmd>hexBinary</cmd></command>
        <desc>This text constraint match if text is a sequence of
        binary octets in hexadecimal encoding, where each binary octet
        is a two-character hexadecimal number. Lowercase and uppercase
        letters A through F are permitted.</desc>
      </commanddef>
      <commanddef>
        <command><cmd>unsignedByte</cmd></command>
        <desc>This text constraint match if the text value is a
        xsd:unsignedByte. This is an integer between 0 and 255, both
        included, optionally preceded by a + sign and leading
        zeros.</desc>
      </commanddef>
      <commanddef>
        <command><cmd>unsignedShort</cmd></command>
        <desc>This text constraint match if the text value is a
        xsd:unsignedShort. This is an integer between 0 and 65535,
        both included, optionally preceded by a + sign and leading
        zeros.</desc>
      </commanddef>
      <commanddef>
        <command><cmd>unsignedInt</cmd></command>
        <desc>This text constraint match if the text value is a
        xsd:unsignedInt. This is an integer between 0 and 4294967295,
        both included, optionally preceded by a + sign and leading
        zeros.</desc>
      </commanddef>
      <commanddef>
        <command><cmd>unsignedLong</cmd></command>
        <desc>This text constraint match if the text value is a
        xsd:unsignedLong. This is an integer between 0 and
        18446744073709551615, both included, optionally preceded by a
        + sign and leading zeros.</desc>
      </commanddef>
    </commandlist>
  </section>

  <section>
    <title>Local key constraints</title>

    <p>Document wide uniqueness and foreign key constraints are

Changes to generic/schema.c.

6640
6641
6642
6643
6644
6645
6646




























































6647
6648
6649
6650
6651
6652
6653
....
6768
6769
6770
6771
6772
6773
6774








6775
6776
6777
6778
    CHECK_TI
    CHECK_TOPLEVEL
    checkNrArgs (1,1,"No arguments expected");
    ADD_CONSTRAINT (sdata, sc)
    sc->constraint = hexBinaryImpl;
    return TCL_OK;
}





























































void
tDOM_SchemaInit (
    Tcl_Interp *interp
    )
{
    Tcl_CreateObjCommand (interp, "tdom::schema", tDOM_SchemaObjCmd,
................................................................................
                          nameTCObjCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::ncname",
                          ncnameTCObjCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::qname",
                          qnameTCObjCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::hexBinary",
                          hexBinaryTCObjCmd, NULL, NULL);








}


#endif  /* #ifndef TDOM_NO_SCHEMA */







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>




6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
....
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
    CHECK_TI
    CHECK_TOPLEVEL
    checkNrArgs (1,1,"No arguments expected");
    ADD_CONSTRAINT (sdata, sc)
    sc->constraint = hexBinaryImpl;
    return TCL_OK;
}

static int
unsignedIntTypesImpl (
    Tcl_Interp *interp,
    void *constraintData,
    char *text
    )
{
    char *c;
    int count = 0;
    int nrDigits[] = {3, 5, 10, 20};
    char *max[] = {
        "255",
        "65535",
        "4294967295",
        "18446744073709551615"
    };
    
    if (*text == '+') text++;
    if (*text == 0) return 0;
    if (*text == '0') {
        text++;
        while (*text == '0') text++;
        if (*text == 0) return 1;
    }
    c = text;
    while (*text) {
        if (*text >= '0' && *text <= '9') {
            text++;
            count++;
        } else return 0;
    }
    if (count < nrDigits[(intptr_t) constraintData]) return 1;
    if (count == nrDigits[(intptr_t) constraintData]) {
        if (strcmp (max[(intptr_t) constraintData], c) >= 0) {
            return 1;
        }
    }
    return 0;
}

static int
unsignedIntTypesTCObjCmd (
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
    )
{
    SchemaData *sdata = GETASI;
    SchemaConstraint *sc;

    CHECK_TI
    CHECK_TOPLEVEL
    checkNrArgs (1,1,"No arguments expected");
    ADD_CONSTRAINT (sdata, sc)
    sc->constraint = unsignedIntTypesImpl;
    sc->constraintData = clientData;
    return TCL_OK;
}

void
tDOM_SchemaInit (
    Tcl_Interp *interp
    )
{
    Tcl_CreateObjCommand (interp, "tdom::schema", tDOM_SchemaObjCmd,
................................................................................
                          nameTCObjCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::ncname",
                          ncnameTCObjCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::qname",
                          qnameTCObjCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::hexBinary",
                          hexBinaryTCObjCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::unsignedByte",
                          unsignedIntTypesTCObjCmd, (ClientData) 0, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::unsignedShort",
                          unsignedIntTypesTCObjCmd, (ClientData) 1, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::unsignedInt",
                          unsignedIntTypesTCObjCmd, (ClientData) 2, NULL);
    Tcl_CreateObjCommand (interp,"tdom::schema::text::unsignedLong",
                          unsignedIntTypesTCObjCmd, (ClientData) 3, NULL);
}


#endif  /* #ifndef TDOM_NO_SCHEMA */

Changes to tests/schema.test.

4805
4806
4807
4808
4809
4810
4811












































































































































4812
4813
4814
4815
4816
4817
4818
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 0 0 1 0 1 0 0 0 1}













































































































































test schema-15.1 {constraint cmd tcl} {
    tdom::schema s
    s define {
        defelement a {
            tcl append ::schema-15.1
            element b
            tcl append ::schema-15.1







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 0 0 1 0 1 0 0 0 1}

test schema-14.37 {text: unsignedByte} {
    tdom::schema s
    s defelement doc {
        text {unsignedByte}
    }
    set result [list]
    foreach xml {
        <doc/>
        <doc>7</doc>
        <doc>+255</doc>
        <doc>-255</doc>
        <doc>-000255</doc>
        <doc>256</doc>
        <doc>65535</doc>
        <doc>000000000000000065535</doc>
        <doc>65536</doc>
        <doc>4294967295</doc>
        <doc>00000000000000004294967295</doc>
        <doc>4294967296</doc>
        <doc>18446744073709551615</doc>
        <doc>018446744073709551615</doc>
        <doc>18446744073709551616</doc>
        <doc>28446744073709551614</doc>
        <doc>3ABCDEF0</doc>
        {<doc> a0123b</doc>}
        {<doc>a0123b </doc>}
        <doc>a0123b</doc>
        <doc>1.2</doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}

test schema-14.38 {text: unsignedShort} {
    tdom::schema s
    s defelement doc {
        text {unsignedShort}
    }
    set result [list]
    foreach xml {
        <doc/>
        <doc>7</doc>
        <doc>+255</doc>
        <doc>-255</doc>
        <doc>-000255</doc>
        <doc>256</doc>
        <doc>65535</doc>
        <doc>000000000000000065535</doc>
        <doc>65536</doc>
        <doc>4294967295</doc>
        <doc>00000000000000004294967295</doc>
        <doc>4294967296</doc>
        <doc>18446744073709551615</doc>
        <doc>018446744073709551615</doc>
        <doc>18446744073709551616</doc>
        <doc>28446744073709551614</doc>
        <doc>3ABCDEF0</doc>
        {<doc> a0123b</doc>}
        {<doc>a0123b </doc>}
        <doc>a0123b</doc>
        <doc>1.2</doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0}

test schema-14.39 {text: unsignedInt} {
    tdom::schema s
    s defelement doc {
        text {unsignedInt}
    }
    set result [list]
    foreach xml {
        <doc/>
        <doc>7</doc>
        <doc>+255</doc>
        <doc>-255</doc>
        <doc>-000255</doc>
        <doc>256</doc>
        <doc>65535</doc>
        <doc>000000000000000065535</doc>
        <doc>65536</doc>
        <doc>4294967295</doc>
        <doc>00000000000000004294967295</doc>
        <doc>4294967296</doc>
        <doc>18446744073709551615</doc>
        <doc>018446744073709551615</doc>
        <doc>18446744073709551616</doc>
        <doc>28446744073709551614</doc>
        <doc>3ABCDEF0</doc>
        {<doc> a0123b</doc>}
        {<doc>a0123b </doc>}
        <doc>a0123b</doc>
        <doc>1.2</doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0}

test schema-14.40 {text: unsignedLong} {
    tdom::schema s
    s defelement doc {
        text {unsignedLong}
    }
    set result [list]
    foreach xml {
        <doc/>
        <doc>7</doc>
        <doc>+255</doc>
        <doc>-255</doc>
        <doc>-000255</doc>
        <doc>256</doc>
        <doc>65535</doc>
        <doc>000000000000000065535</doc>
        <doc>65536</doc>
        <doc>4294967295</doc>
        <doc>00000000000000004294967295</doc>
        <doc>4294967296</doc>
        <doc>18446744073709551615</doc>
        <doc>018446744073709551615</doc>
        <doc>18446744073709551616</doc>
        <doc>28446744073709551614</doc>
        <doc>3ABCDEF0</doc>
        {<doc> a0123b</doc>}
        {<doc>a0123b </doc>}
        <doc>a0123b</doc>
        <doc>1.2</doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 1 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0}

test schema-15.1 {constraint cmd tcl} {
    tdom::schema s
    s define {
        defelement a {
            tcl append ::schema-15.1
            element b
            tcl append ::schema-15.1