Τετάρτη 9 Φεβρουαρίου 2022

Revision 2 Version 11

Some fixes in this revision:

1.Change a variable from long to currency, to prevent overflow from timetotime Win32  function which return a big number in Windows 10. This number supposed to count milliseconds from the start of Windows, but sometimes get a big value. So a K1 variable which was long type change to Currency and now has no problem. The problem was on sprites module in info.gsb, where the handling of refresh rate was bad, due to overflow (also good handling  on error exceptions, the M2000 environment continue to work, but show flickering in the head line or information line). Just changing the type to Currency eliminate this problem.

We can check if the number of internal counter is big by using Timecount read only variable. This variable if we didn't use Profiler (to adjust an offset, so we get Timecount from that offset), return the actual time from the starting of windows. My computer show 2282833990.198 milliseconds, about 634 hours or 26.4 days. That is not normal, but happen with Windows 10, 64bit, 21H2  (I don't have 11 to check it).

2. XML3 example in info show the use of automatic conversion (only at reading) for numeric character entities:

// New method NumericCharactersEntities
// use this to convert numeric entitites when you read ATTR OR TEXT
// BUT NOT USED WHEN WE WRITE BACK.
// See the É as É (201 or 0xC9)
pen 14 : Cls 5,0 :Print $(4),
declare databank xmldata
method databank, "NumericCharactersEntities", true
with databank, "xml" as doc$, "beautify" as beautify, "status" as status$
doc$={<?xml?>
<Students>
<Student Name="April" Gender="F" DateOfBirth="1989-01-02" />
<Student Name="Bob" Gender="M"  DateOfBirth="1990-03-04" />
<Student Name="Chad" Gender="M"  DateOfBirth="1991-05-06" />
<Student Name="Dave" Gender="M"  DateOfBirth="1992-07-08">
<Pet Type="dog" Name="Rover" />
</Student>
<Student DateOfBirth="1993-09-10" Gender="F" Name="Émily" />
</Students>
}
beautify=-4
Report 3, doc$
With Databank, "Attr" as Attr$()
Print status$=""
Method databank, "GetListByTag", "Student", -1 as Result
Print type$(Result), len(Result)
c=1
If len(Result)>0 then
Stack Result {
Read fieldsNo : With fieldsNo, "Attr" as fieldsno.tag$()
}
Stack Result {
Print c, " "+fieldsno.tag$("Name")
c++
if empty else LOOP  // Loop raise a flag for this block, which interpreter read at the end of block, and then cleat it
Read fieldsNo
}
end if
// If you change value, this value not saved with escaped numeric character edities
// only the xml special characters escaped:
// quot "
// amp &
// apos '
// lt <
// gt >
rem 1:
fieldsno.tag$("Name")=@conv$("Émily")
beautify=-4
Report 3, doc$
declare databank Nothing


Function Conv$(a$)
if len(a$)=0 then exit function
local b$, c$, k
for i=1 to len(a$)
c$=mid$(a$, i,1)
k=uint(chrcode(c$))
Rem 2:if k>127 then b$+="&#"+str$(k,"")+";" else b$+=c$ // this place decimal value
if k>127 then b$+="&#x"+hex$(k,2)+";" else b$+=c$ // this place hexadecimal value
next
=b$
End Function


3. JsonObject now has a DeleteKey method:

function KeyList (json) {
flush
with json, "index" as json.index, "count" as json.count ,"KeyToStringPos" as keyName$()
if json.count=0 then =(,): exit
for i=0 to json.count-1:data keyname$(i):next
=array([])
}
declare Json JsonObject
json$={
{
    "description":"A person",
    "type":"object",
    "properties":
        {
            "name":
                {
                    "type":"string"
                },
            "age":
                {
                    "type":"integer",
                    "maximum":125
                }
        }
}
}
method json, "parser", json$ as json
with json, "json" as json.format$(), "item" as json(), "item" as json$()
with json, "itempath" as json.path(), "itempath" as json.path$()


Report json.format$(4)
Print json$("description")
Print json$("type")
Print json.path$("properties.name.type")
Print json.path$("properties|age|type", "|") ' define different seperator
Print json.path("properties.age.maximum")
method json, "assignpath", "properties.age.maximum", 80
Report json.format$(4)
Print json.format$(0)


list1=Keylist(json.path("properties"))
Print format$("Found {0} properties:", len(list1))
nl$={
}+" - "
Print #-2, " - "+list1#sort()#str$(nl$)
// New in revision 2 version 11 deletekey
Report json.format$(0)
//Method json, "deletekey", "type"
Method json, "deletekey", "properties"
Report json.format$(0)




Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.