[x3d-public] SFImage regex

Andreas Plesch andreasplesch at gmail.com
Thu Jun 7 11:11:51 PDT 2018


Since I got started with the regexes, let's look at SFImage as it is still
a TODO.

http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/fieldsDef.html#SFImageAndMFImage

appears to be the main (only?) source of the format description.

We need exactly three decimal non-negative integers followed by a zero or
more non-negative decimal or hexadecimal integers.

There is no mentioning of the separator, so let's look at some example
scenes:

http://www.web3d.org/x3d/content/examples/ConformanceNist/Appearance/PixelTexture/index.html

The NIST examples all use space as separator.
http://www.web3d.org/x3d/tooltips/X3dTooltips.html#PixelTexture examples
all use space.

http://www.web3d.org/specifications/X3dSchemaDocumentation4.0/x3d-4.0_SFImage.html
has a minimum length of 5, presumably as a result of three single digits
for wdth, height and components plus two separator characters.

So one question is: Are single commas legal to separate numbers in SFImage
from each other ?
http://www.web3d.org/specifications/X3dRegularExpressions.html says commas
are only allowed in MF fields, so let's say the answer is no.

What about leading zeroes ? The general guidance in
http://www.web3d.org/specifications/X3dRegularExpressions.html does not
allow leading zeroes.

There is a requirement to have width x height x component number of pixel
values but I am not sure if this requirement can be (easily) checked by a
regex.

Capital letters:
http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/fieldsDef.html#SFImageAndMFImage
only uses capital A-F in hexadecimal example values but let's say a-f is
also allowed since they are used in almost all examples.

Ok, let's give it a try:

[ \t]*(([0-9]|[1-9][0-9]+)([
]+|$)){3}(([0-9]|([1-9][0-9]+)|(0x([0-9]|[a-f]|[A-F])+))([ ]+|$))*

In words:

match any leading white space followed by
exactly three times the following
 - one of the following
   - either a single digit (including 0) or
   - a two or more digit number starting with a 1 to 9 digit
 - followed by either
  - one or more spaces
  - or the end of the string (accommodating the default '0 0 0' case)
then optionally followed zero or more times by
  - one of the following
    - either a single digit (including 0) or
    - a two or more digit number starting with a 1 to 9 digit
    - 0x followed by at least one of
       - a single digit or
       - a to f letter or
       - A to F letter
  - followed by either
    - one or more spaces
    - or the end of the string

The spaces are written as [ ] for clarity but could be just a space
character.

This allows 0 0 0 as it is the default value. It also allows 1 2 3 without
any pixel values.but we do not aim at checking the number of pixel values
anyways.

Any input, in particular examples of problem cases welcome. Since images
can be huge it may be necessary to optimize for performance and memory
which may require more regex expertise than I can bring myself to acquire.

-Andreas

-- 
Andreas Plesch
Waltham, MA 02453
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180607/185b7887/attachment.html>


More information about the x3d-public mailing list