Post by Robert on Nov 23, 2023 14:33:20 GMT -5
Here, the term "Display-Hex digits means" the characters '0' to '9', 'A' to 'F' and 'a' to 'f'.
Right now, there is no built-in feature to find Display-Hex digits, other than using a RegEx. To find one Display-Hex digit requires a Regex of
F R'[0-9a-fA-f]' or F R'[[:xdigit]]'
Finding longer spans would be more involved. There are a few possibly ways of adding direct support for this.
Method 1: Add new Picture code of P'*'
Currently, "*" is not a defined picture code, and is treated as ordinary data in a picture. Suppose "*" is used to define a Display-Hex character. Adding this would involve a few steps.
1.1 In \_Types.inc, 'TYPE PIC_type' would have to be modified. Currently 'mask' values are stored as 16-bit WORDs, but there are already 16 PicMap_xxx bit definitions. You'd need to change the WORD entries to LONG, because you would have to add a mask value something like this:
%PicMap_Hex_digit = &H00010000 ' P'*' hex digit 0-9 A-F a-f
1.2 _TabData.inc, the code would have to be added to recognize an "*" as a mask of %PicMap_Hex_digit, and so on.
Method 2: Add a new string type code of H.
This could actually be easier to do. Let's say we defined an H type like this:
H'len' -- find a string of exactly 'len' hex digits
or
H'min-max' -- find a string of between 'min' and 'max' hex digits
How would we go about finding the digits in question?
You could write the code out the hard way, like you did when D strings were added.
OR ... you could treat the H'xxx' string AS IF it were like a "macro". You would THEN convert that "macro" into the equivalent RegEx form, and then use that RegEx as if the user actually typed it in that way. All you have to do is to plug in the numeric values into a "model" RegEx to find the desired characters.
For instance, to find 2 hex digits, you'd say:
FIND H'2'
This would be converted into:
FIND R'[0-9a-fA-f]{2}'
To find between 2 and 4 hex digits, you could say:
FIND H'2-4'
This would be converted into:
FIND R'[0-9a-fA-f]{2,4}'
Now, this method doesn't define any mechanism to find only EVEN numbers of digits, which would be a common requirement. To do that, it would require additional syntax inside the H string, and some way to convert that into a valid RegEx.
Right now, I don't want to over-specify this idea or go into too much detail. But, should there be an interest, I believe it could be done. The most likely way would be to use the | or-sign to define alternate RegEx patterns. Then, the R'xxx' string would have to be built in the correct order of alternatives. I see that as kind of tedious but straight-forward coding. But at least it would be possible.
With P'*' there is no easy way to do this, except that since the * is directly typed in the picture, you just only define a picture with an even number of * codes.
R
Right now, there is no built-in feature to find Display-Hex digits, other than using a RegEx. To find one Display-Hex digit requires a Regex of
F R'[0-9a-fA-f]' or F R'[[:xdigit]]'
Finding longer spans would be more involved. There are a few possibly ways of adding direct support for this.
Method 1: Add new Picture code of P'*'
Currently, "*" is not a defined picture code, and is treated as ordinary data in a picture. Suppose "*" is used to define a Display-Hex character. Adding this would involve a few steps.
1.1 In \_Types.inc, 'TYPE PIC_type' would have to be modified. Currently 'mask' values are stored as 16-bit WORDs, but there are already 16 PicMap_xxx bit definitions. You'd need to change the WORD entries to LONG, because you would have to add a mask value something like this:
%PicMap_Hex_digit = &H00010000 ' P'*' hex digit 0-9 A-F a-f
1.2 _TabData.inc, the code would have to be added to recognize an "*" as a mask of %PicMap_Hex_digit, and so on.
Method 2: Add a new string type code of H.
This could actually be easier to do. Let's say we defined an H type like this:
H'len' -- find a string of exactly 'len' hex digits
or
H'min-max' -- find a string of between 'min' and 'max' hex digits
How would we go about finding the digits in question?
You could write the code out the hard way, like you did when D strings were added.
OR ... you could treat the H'xxx' string AS IF it were like a "macro". You would THEN convert that "macro" into the equivalent RegEx form, and then use that RegEx as if the user actually typed it in that way. All you have to do is to plug in the numeric values into a "model" RegEx to find the desired characters.
For instance, to find 2 hex digits, you'd say:
FIND H'2'
This would be converted into:
FIND R'[0-9a-fA-f]{2}'
To find between 2 and 4 hex digits, you could say:
FIND H'2-4'
This would be converted into:
FIND R'[0-9a-fA-f]{2,4}'
Now, this method doesn't define any mechanism to find only EVEN numbers of digits, which would be a common requirement. To do that, it would require additional syntax inside the H string, and some way to convert that into a valid RegEx.
Right now, I don't want to over-specify this idea or go into too much detail. But, should there be an interest, I believe it could be done. The most likely way would be to use the | or-sign to define alternate RegEx patterns. Then, the R'xxx' string would have to be built in the correct order of alternatives. I see that as kind of tedious but straight-forward coding. But at least it would be possible.
With P'*' there is no easy way to do this, except that since the * is directly typed in the picture, you just only define a picture with an even number of * codes.
R