This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit e5b46badffe1ae31a5ebcc6faec940d6ec8c014f
Author: Josh Tynjala <[email protected]>
AuthorDate: Wed Apr 24 14:05:42 2024 -0700

    CSS.g: commas are optional in rgb() and rgba()
---
 .../org/apache/royale/compiler/internal/css/CSS.g  | 15 ++++++++--
 .../internal/css/CSSRgbColorPropertyValue.java     | 26 ++++++++++++++----
 .../internal/css/CSSRgbaColorPropertyValue.java    | 32 ++++++++++++++++------
 3 files changed, 57 insertions(+), 16 deletions(-)

diff --git 
a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g 
b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
index 60e96c3a9..2306e6732 100644
--- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
+++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
@@ -645,7 +645,13 @@ RGBA :     'rgba('         ( WS* NUMBER ( PERCENT | ) WS* 
) ','
                                ( WS* NUMBER ( PERCENT | ) WS* ) ',' 
                                ( WS* NUMBER ( PERCENT | ) WS* ) ',' 
                                ( WS* NUMBER ( PERCENT | ) WS* ) 
-               ')' ; 
+               ')'
+    |   'rgba('        ( WS* NUMBER ( PERCENT | ) WS* ) 
+                               ( WS* NUMBER ( PERCENT | ) WS* ) 
+                               ( WS* NUMBER ( PERCENT | ) WS* )
+                               ( WS* NUMBER ( PERCENT | ) WS* ) 
+               ')'
+    ; 
 
 /** 
  * Matches a rgb definition - rgb(100%,100%,100%)
@@ -653,7 +659,12 @@ RGBA :     'rgba('         ( WS* NUMBER ( PERCENT | ) WS* 
) ','
 RGB :  'rgb('  ( WS* NUMBER ( PERCENT | ) WS* ) ',' 
                                ( WS* NUMBER ( PERCENT | ) WS* ) ',' 
                                ( WS* NUMBER ( PERCENT | ) WS* ) 
-               ')' ; 
+               ')'
+    |  'rgb('  ( WS* NUMBER ( PERCENT | ) WS* )
+                               ( WS* NUMBER ( PERCENT | ) WS* )
+                               ( WS* NUMBER ( PERCENT | ) WS* ) 
+               ')'
+    ; 
 
 
 /** Arguments of a function call property value. */
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbColorPropertyValue.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbColorPropertyValue.java
index 7cc335e13..bdcf1b4d3 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbColorPropertyValue.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbColorPropertyValue.java
@@ -19,6 +19,8 @@
 
 package org.apache.royale.compiler.internal.css;
 
+import java.util.Arrays;
+import java.util.Iterator;
 import java.util.StringTokenizer;
 
 import org.antlr.runtime.Token;
@@ -58,13 +60,25 @@ public class CSSRgbColorPropertyValue extends 
CSSPropertyValue
     protected static int getIntValue(String rgb)
     {        
         rgb = rgb.substring(4, rgb.length() - 1);
-        
-        StringTokenizer st = new StringTokenizer(rgb, ",");
+
         StringBuffer sb = new StringBuffer();
-        while (st.hasMoreElements())
+        Iterator<Object> iterator = null;
+        if (rgb.indexOf(",") != -1)
+        { 
+            // separated by commas is considered a legacy mode
+            StringTokenizer st = new StringTokenizer(rgb, ",");
+            iterator = st.asIterator();
+        }
+        else
+        {
+            // separated by whitespace is allowed instead of commas
+            String[] elements = rgb.split("\\s+");
+            iterator = Arrays.<Object>stream(elements).iterator();
+        }
+        while (iterator.hasNext())
         {
-            int digit;    
-            String t = (String)st.nextElement();
+            int digit;
+            String t = (String) iterator.next();
             t = t.trim();
             if(t.contains("%")) {
                 t = t.replaceAll("%", "");
@@ -76,7 +90,7 @@ public class CSSRgbColorPropertyValue extends CSSPropertyValue
                 digit = Float.valueOf(t).intValue();
                 sb.append(Character.forDigit((digit >> 4) & 15, 16));
                 sb.append(Character.forDigit(digit & 15, 16));
-            }            
+            }
         }
         return Integer.parseInt( sb.toString(), 16 );
     }
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbaColorPropertyValue.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbaColorPropertyValue.java
index af74e7060..aa2034c7f 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbaColorPropertyValue.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRgbaColorPropertyValue.java
@@ -19,6 +19,8 @@
 
 package org.apache.royale.compiler.internal.css;
 
+import java.util.Arrays;
+import java.util.Iterator;
 import java.util.StringTokenizer;
 
 import org.antlr.runtime.Token;
@@ -59,21 +61,35 @@ public class CSSRgbaColorPropertyValue extends 
CSSPropertyValue
     {        
         rgb = rgb.substring(5, rgb.length() - 1);
         
-        StringTokenizer st = new StringTokenizer(rgb, ",");
         StringBuffer sb = new StringBuffer();
-        while (st.hasMoreElements())
+        Iterator<Object> iterator = null;
+        if (rgb.indexOf(",") != -1)
+        { 
+            // separated by commas is considered a legacy mode
+            StringTokenizer st = new StringTokenizer(rgb, ",");
+            iterator = st.asIterator();
+        }
+        else
+        {
+            // separated by whitespace is allowed instead of commas
+            String[] elements = rgb.split("\\s+");
+            iterator = Arrays.<Object>stream(elements).iterator();
+        }
+        while (iterator.hasNext())
         {
-            int digit;    
-            String t = (String)st.nextElement();
+            int digit;
+            String t = (String) iterator.next();
             t = t.trim();
-            if(t.contains("%")) {
+            if (t.contains("%"))
+            {
                 t = t.replaceAll("%", "");
                 digit = ( Float.valueOf(t).intValue() * 255) / 100;
                 sb.append(Character.forDigit((digit >> 4) & 15, 16));
                 sb.append(Character.forDigit(digit & 15, 16));
-                
-            } else {
-                if (st.hasMoreElements())
+            }
+            else
+            {
+                if (iterator.hasNext())
                 {
                     digit = Float.valueOf(t).intValue();
                     sb.append(Character.forDigit((digit >> 4) & 15, 16));

Reply via email to