Changeset 205101 in webkit


Ignore:
Timestamp:
Aug 28, 2016 2:35:33 AM (8 years ago)
Author:
fred.wang@free.fr
Message:

Improve parsing of the menclose notation attribute value
https://bugs.webkit.org/show_bug.cgi?id=161045

Patch by Frederic Wang <fwang@igalia.com> on 2016-08-28
Reviewed by Darin Adler.

Source/WebCore:

We improve the way the list of menclose notations is parsed to avoid allocating a vector and
accept any whitespace as separators.

New test cases in mathml/presentation/menclose-notation-equivalence.html

  • mathml/MathMLMencloseElement.cpp: Include HTMLParserIdioms.h to use isHTMLSpace.

(WebCore::MathMLMencloseElement::addNotationFlags): Helper function to perform the relevant
addNotation calls from a notation name.
(WebCore::MathMLMencloseElement::parseNotationAttribute): Use only simple string operations
to determine the list of notations.

  • mathml/MathMLMencloseElement.h: Declare the new helper function.

LayoutTests:

We add some cases in menclose-notation-equivalence to verify that one can use any sequence of
whitespace to separate notation values. We try with 0, 1, 2 or 3 notation values.

  • mathml/presentation/menclose-notation-equivalence-expected.html:
  • mathml/presentation/menclose-notation-equivalence.html:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r205098 r205101  
     12016-08-28  Frederic Wang  <fwang@igalia.com>
     2
     3        Improve parsing of the menclose notation attribute value
     4        https://bugs.webkit.org/show_bug.cgi?id=161045
     5
     6        Reviewed by Darin Adler.
     7
     8        We add some cases in menclose-notation-equivalence to verify that one can use any sequence of
     9        whitespace to separate notation values. We try with 0, 1, 2 or 3 notation values.
     10
     11        * mathml/presentation/menclose-notation-equivalence-expected.html:
     12        * mathml/presentation/menclose-notation-equivalence.html:
     13
    1142016-08-28  Frederic Wang  <fwang@igalia.com>
    215
  • trunk/LayoutTests/mathml/presentation/menclose-notation-equivalence-expected.html

    r199980 r205101  
    2626    <math><mrow><menclose notation="left updiagonalstrike"><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
    2727
     28    <!-- menclose notations can be separated by any sequence of whitespace. -->
     29    <p>
     30      <math><mrow><menclose notation=""><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
     31      <math><mrow><menclose notation="top"><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
     32      <math><mrow><menclose notation="top circle"><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
     33      <math><mrow><menclose notation="top circle horizontalstrike"><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
     34    </p>
     35
    2836  </body>
    2937</html>
  • trunk/LayoutTests/mathml/presentation/menclose-notation-equivalence.html

    r199980 r205101  
    2626    <math dir="rtl"><mrow><menclose notation="left updiagonalstrike"><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
    2727
     28    <!-- menclose notations can be separated by any sequence of whitespace. -->
     29    <p>
     30      <math><mrow><menclose notation="&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;"><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
     31      <math><mrow><menclose notation="&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;top&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;"><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
     32      <math><mrow><menclose notation="&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;top&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;circle&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;"><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
     33      <math><mrow><menclose notation="&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;top&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;circle&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;horizontalstrike&#x20;&#x9;&#xA;&#xD;&#x20;&#x9;&#xA;&#xD;"><mspace width="100px" height="50px" mathbackground="red"/></menclose></mrow></math>
     34    </p>
     35
    2836  </body>
    2937</html>
  • trunk/Source/WebCore/ChangeLog

    r205100 r205101  
     12016-08-28  Frederic Wang  <fwang@igalia.com>
     2
     3        Improve parsing of the menclose notation attribute value
     4        https://bugs.webkit.org/show_bug.cgi?id=161045
     5
     6        Reviewed by Darin Adler.
     7
     8        We improve the way the list of menclose notations is parsed to avoid allocating a vector and
     9        accept any whitespace as separators.
     10
     11        New test cases in mathml/presentation/menclose-notation-equivalence.html
     12
     13        * mathml/MathMLMencloseElement.cpp: Include HTMLParserIdioms.h to use isHTMLSpace.
     14        (WebCore::MathMLMencloseElement::addNotationFlags): Helper function to perform the relevant
     15        addNotation calls from a notation name.
     16        (WebCore::MathMLMencloseElement::parseNotationAttribute): Use only simple string operations
     17        to determine the list of notations.
     18        * mathml/MathMLMencloseElement.h: Declare the new helper function.
     19
    1202016-08-28  Frederic Wang  <fwang@igalia.com>
    221
  • trunk/Source/WebCore/mathml/MathMLMencloseElement.cpp

    r204885 r205101  
    3030#if ENABLE(MATHML)
    3131
     32#include "HTMLParserIdioms.h"
    3233#include "MathMLNames.h"
    3334#include "RenderMathMLMenclose.h"
     
    5556}
    5657
     58void MathMLMencloseElement::addNotationFlags(StringView notation)
     59{
     60    ASSERT(m_notationFlags);
     61    if (notation == "longdiv") {
     62        addNotation(LongDiv);
     63    } else if (notation == "roundedbox") {
     64        addNotation(RoundedBox);
     65    } else if (notation == "circle") {
     66        addNotation(Circle);
     67    } else if (notation == "left") {
     68        addNotation(Left);
     69    } else if (notation == "right") {
     70        addNotation(Right);
     71    } else if (notation == "top") {
     72        addNotation(Top);
     73    } else if (notation == "bottom") {
     74        addNotation(Bottom);
     75    } else if (notation == "updiagonalstrike") {
     76        addNotation(UpDiagonalStrike);
     77    } else if (notation == "downdiagonalstrike") {
     78        addNotation(DownDiagonalStrike);
     79    } else if (notation == "verticalstrike") {
     80        addNotation(VerticalStrike);
     81    } else if (notation == "horizontalstrike") {
     82        addNotation(HorizontalStrike);
     83    } else if (notation == "updiagonalarrow") {
     84        addNotation(UpDiagonalArrow);
     85    } else if (notation == "phasorangle") {
     86        addNotation(PhasorAngle);
     87    } else if (notation == "box") {
     88        addNotation(Left);
     89        addNotation(Right);
     90        addNotation(Top);
     91        addNotation(Bottom);
     92    } else if (notation == "actuarial") {
     93        addNotation(Right);
     94        addNotation(Top);
     95    } else if (notation == "madruwb") {
     96        addNotation(Right);
     97        addNotation(Bottom);
     98    }
     99}
     100
    57101void MathMLMencloseElement::parseNotationAttribute()
    58102{
     
    62106        return;
    63107    }
    64     auto& value = attributeWithoutSynchronization(notationAttr);
    65     Vector<String> notationsList;
    66     String(value).split(' ', notationsList);
    67     for (auto& notation : notationsList) {
    68         if (notation == "longdiv") {
    69             addNotation(LongDiv);
    70         } else if (notation == "roundedbox") {
    71             addNotation(RoundedBox);
    72         } else if (notation == "circle") {
    73             addNotation(Circle);
    74         } else if (notation == "left") {
    75             addNotation(Left);
    76         } else if (notation == "right") {
    77             addNotation(Right);
    78         } else if (notation == "top") {
    79             addNotation(Top);
    80         } else if (notation == "bottom") {
    81             addNotation(Bottom);
    82         } else if (notation == "updiagonalstrike") {
    83             addNotation(UpDiagonalStrike);
    84         } else if (notation == "downdiagonalstrike") {
    85             addNotation(DownDiagonalStrike);
    86         } else if (notation == "verticalstrike") {
    87             addNotation(VerticalStrike);
    88         } else if (notation == "horizontalstrike") {
    89             addNotation(HorizontalStrike);
    90         } else if (notation == "updiagonalarrow") {
    91             addNotation(UpDiagonalArrow);
    92         } else if (notation == "phasorangle") {
    93             addNotation(PhasorAngle);
    94         } else if (notation == "box") {
    95             addNotation(Left);
    96             addNotation(Right);
    97             addNotation(Top);
    98             addNotation(Bottom);
    99         } else if (notation == "actuarial") {
    100             addNotation(Right);
    101             addNotation(Top);
    102         } else if (notation == "madruwb") {
    103             addNotation(Right);
    104             addNotation(Bottom);
     108    // We parse the list of whitespace-separated notation names.
     109    StringView value = attributeWithoutSynchronization(notationAttr).string();
     110    unsigned length = value.length();
     111    unsigned start = 0;
     112    while (start < length) {
     113        if (isHTMLSpace(value[start])) {
     114            start++;
     115            continue;
    105116        }
     117        unsigned end = start + 1;
     118        while (end < length && !isHTMLSpace(value[end]))
     119            end++;
     120        addNotationFlags(value.substring(start, end - start));
     121        start = end;
    106122    }
    107123}
  • trunk/Source/WebCore/mathml/MathMLMencloseElement.h

    r204885 r205101  
    6363    void clearNotations() { m_notationFlags = 0; }
    6464    void addNotation(MencloseNotationFlag notationFlag) { m_notationFlags.value() |= notationFlag; }
     65    void addNotationFlags(StringView notation);
    6566    Optional<uint16_t> m_notationFlags;
    6667};
Note: See TracChangeset for help on using the changeset viewer.